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 f5ddc83349a097277ae7c6d18dd9b821f56d2882..8b39530e84dd02f876c3fc4c567a94b66b3ca7b7 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 77a26fdf36034058c272711a4320b8ee664dda2f..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_INSERT 189 -#define TK_NULL 190 -#define TK_NK_QUESTION 191 -#define TK_NK_ARROW 192 -#define TK_ROWTS 193 -#define TK_TBNAME 194 -#define TK_QSTARTTS 195 -#define TK_QENDTS 196 -#define TK_WSTARTTS 197 -#define TK_WENDTS 198 -#define TK_WDURATION 199 -#define TK_CAST 200 -#define TK_NOW 201 -#define TK_TODAY 202 -#define TK_TIMEZONE 203 -#define TK_CLIENT_VERSION 204 -#define TK_SERVER_VERSION 205 -#define TK_SERVER_STATUS 206 -#define TK_CURRENT_USER 207 -#define TK_COUNT 208 -#define TK_LAST_ROW 209 -#define TK_BETWEEN 210 -#define TK_IS 211 -#define TK_NK_LT 212 -#define TK_NK_GT 213 -#define TK_NK_LE 214 -#define TK_NK_GE 215 -#define TK_NK_NE 216 -#define TK_MATCH 217 -#define TK_NMATCH 218 -#define TK_CONTAINS 219 -#define TK_JOIN 220 -#define TK_INNER 221 -#define TK_SELECT 222 -#define TK_DISTINCT 223 -#define TK_WHERE 224 -#define TK_PARTITION 225 -#define TK_BY 226 -#define TK_SESSION 227 -#define TK_STATE_WINDOW 228 -#define TK_SLIDING 229 -#define TK_FILL 230 -#define TK_VALUE 231 -#define TK_NONE 232 -#define TK_PREV 233 -#define TK_LINEAR 234 -#define TK_NEXT 235 -#define TK_HAVING 236 -#define TK_RANGE 237 -#define TK_EVERY 238 -#define TK_ORDER 239 -#define TK_SLIMIT 240 -#define TK_SOFFSET 241 -#define TK_LIMIT 242 -#define TK_OFFSET 243 -#define TK_ASC 244 -#define TK_NULLS 245 -#define TK_ID 246 -#define TK_NK_BITNOT 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/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 88ff0f3b98e6f5c99a79780810695293f6a8fca6..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, diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 39392b7a968242332ae0b8a1d7c2e887f2a624f4..6a865b4e2a01b6bab882caf1ea810786bc7aca44 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -128,10 +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 { @@ -460,7 +462,9 @@ typedef struct 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; 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/sync/sync.h b/include/libs/sync/sync.h index 5c539f0ef39af092a48c101638c90899881b73ca..8a6d6b7722807a004a3e46ec4ed24aa9b6875cbf 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -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/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 7a4bcd85b83ef8ff224395b562dda537657a5f57..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) 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/src/clientMain.c b/source/client/src/clientMain.c index 44b841206415f4862e6a1f9b12724b24109aefb8..e908046b1e3adfef72ceed24055d988e2fda9cb7 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -843,19 +843,25 @@ 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; } SSchedulerReq req = { @@ -869,14 +875,14 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { 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/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 880e2cb406cd4186581a21ff9e13140b6774b48e..a3df32a08c86c583deb4bd51ab31f52c588678aa 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -351,6 +351,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/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 cab6136cc506b660742bca047c0d5c157e279c4b..6320f4719d77bc849bede984b607cddd4d57133e 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" @@ -62,6 +61,12 @@ 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); + int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); int32_t vnodeValidateTableHash(SVnode *pVnode, char *tableFName); @@ -74,7 +79,6 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); -int32_t vnodeProcessCreateTSma(SVnode *pVnode, void *pCont, uint32_t contLen); // meta typedef struct SMeta SMeta; // todo: remove @@ -112,33 +116,31 @@ 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); + +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 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 f096fe7820eeb6a497a06389488eb1bc72ad32f9..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 { 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/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..ae9caa34441e39dbe32702c590c0d304105548ea 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 ASCENDING_TRAVERSE(o) (o == TSDB_ORDER_ASC) -#define QH_GET_NUM_OF_COLS(handle) ((size_t)(taosArrayGetSize((handle)->pResBlock->pDataBlock))) +typedef struct { + STbDataIter *iter; + int32_t index; + bool hasVal; +} SIterInfo; -#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; +typedef struct STableBlockScanInfo { + uint64_t uid; 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; + 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,2807 +57,2804 @@ 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); - - int64_t now = taosGetTimestamp(pCfg->precision); - return now - (tsTickPerMin[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick -} +static STimeWindow updateQueryTimeWindow(STsdb* pTsdb, STimeWindow* pWindow) { + STsdbKeepCfg* pCfg = &pTsdb->keepCfg; -static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableDataCond* pCond, int32_t tWinIdx) { - pTsdbReadHandle->window = pCond->twindows[tWinIdx]; + int64_t now = taosGetTimestamp(pCfg->precision); + int64_t earilyTs = now - (tsTickPerMin[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick - 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; } - STsdb* pTsdb = getTsdbByRetentions(pVnode, pReadHandle, pCond->twindows[0].skey, pVnode->config.tsdbCfg.retentions); + // make sure the output SSDataBlock size be less than 2MB. + const int32_t TWOMB = 2 * 1024 * 1024; + if ((*capacity) * rowLen > TWOMB) { + (*capacity) = TWOMB / rowLen; + } +} - 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; +// 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->suid = pCond->suid; - pReadHandle->outputCapacity = 4096; //((STsdb*)tsdb)->config.maxRowsPerFileBlock; - pReadHandle->loadExternalRow = pCond->loadExternalRows; - pReadHandle->currentLoadExternalRows = pCond->loadExternalRows; + pIter->index = ASCENDING_TRAVERSE(order) ? -1 : numOfFileset; + pIter->order = order; + pIter->pFileList = taosArrayDup(pFState->aDFileSet); + pIter->numOfFiles = numOfFileset; + + 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) { +static SSDataBlock* createResBlock(SQueryTableDataCond* pCond, int32_t capacity) { + SSDataBlock* pResBlock = createDataBlock(); + if (pResBlock == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - STsdbReadHandle* pTsdbReadHandle = tsdbQueryTablesImpl(pVnode, pCond, qId, taskId); - if (pTsdbReadHandle == NULL) { - 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; + // } - assert(pCond->order == TSDB_ORDER_ASC && pCond->twindows[0].skey <= pCond->twindows[0].ekey); - if (pTsdbReadHandle->cachelastrow) { - pTsdbReadHandle->type = TSDB_QUERY_TYPE_LAST; + STableBlockScanInfo* pScanInfo = p; + if (pScanInfo->pBlockList == NULL) { + pScanInfo->pBlockList = taosArrayInit(16, sizeof(SBlock)); + } + + 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); - if (rmem != NULL && rimem == NULL) { - pCheckInfo->chosen = CHECKINFO_CHOSEN_MEM; - return TD_ROW_KEY(rmem); + 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); + } + + 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; -} + SBlockOrderWrapper* pLeftBlock = &pSupporter->pDataBlockInfo[leftIndex][leftTableBlockIndex]; + SBlockOrderWrapper* pRightBlock = &pSupporter->pDataBlockInfo[rightIndex][rightTableBlockIndex]; -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; - } + return pLeftBlock->pBlock->aSubBlock[0].offset > pRightBlock->pBlock->aSubBlock[0].offset ? 1 : -1; +} - if (key < 0) { - key -= (daysPerFile * tsTickPerMin[precision]); - } +static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks) { + bool asc = ASCENDING_TRAVERSE(pReader->order); - 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; - } - - 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(); +static bool blockIteratorNext(SDataBlockIter* pBlockIter) { + bool asc = ASCENDING_TRAVERSE(pBlockIter->order); - 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(); - - 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; +static int32_t doMergeThreeLevelRows(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { + SRowMerger merge = {0}; + STSRow* pTSRow = NULL; - int32_t num = end - start + 1; - assert(num >= 0); - - 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 (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); - } - } + if (k.ts == key) { + tRowMerge(&merge, pRow); + doMergeRowsInBuf(&pBlockScanInfo->iter, key, pBlockScanInfo->delSkyline, &merge, pReader); + } - int32_t i = 0, j = 0, k = 0; - while (i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { - SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pResBlock->pDataBlock, i); + 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 colIdOfRow1; - if (j >= numOfColsOfRow1) { - colIdOfRow1 = INT32_MAX; - } else if (isRow1DataRow) { - colIdOfRow1 = pSchema1->columns[j].colId; - } else { - colIdOfRow1 = tdKvRowColIdAt(row1, j); - } + // [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 colIdOfRow2; - if (k >= numOfColsOfRow2) { - colIdOfRow2 = INT32_MAX; - } else if (isRow2DataRow) { - colIdOfRow2 = pSchema2->columns[k].colId; - } else { - colIdOfRow2 = tdKvRowColIdAt(row2, k); - } + // [7] k.ts == ik.ts < key + if (k.ts == ik.ts) { + ASSERT(key > ik.ts && key > k.ts); - 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); + 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); - ASSERT(rowKey != TSKEY_INITIAL_VAL); + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(&pBlockScanInfo->iter, key, pBlockScanInfo->delSkyline, &merge, pReader); - 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); + if (ik.ts == k.ts) { + tRowMerge(&merge, piRow); + doMergeRowsInBuf(&pBlockScanInfo->iiter, key, pBlockScanInfo->delSkyline, &merge, pReader); } - ++i; - - if (row == row1) { - ++j; - } else { - ++k; + 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 { - if (mergeOption == 1) { - colDataAppend(pColInfo, *curRow, NULL, true); + 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; } - ++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 -} + // [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); -static void getQualifiedRowsPos(STsdbReadHandle* pTsdbReadHandle, int32_t startPos, int32_t endPos, - int32_t numOfExisted, int32_t* start, int32_t* end) { - *start = -1; + doMergeRowsInFileBlocks(pBlockData, pBlockScanInfo, pReader, &merge); + tRowMergerGetRow(&merge, &pTSRow); + doAppendOneRow(pReader->pResBlock, pReader, pTSRow); + return TSDB_CODE_SUCCESS; + } - 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; - } + //[7] key = ik.ts > k.ts + if (key == ik.ts) { + doMergeMultiRows(piRow, uid, &pBlockScanInfo->iiter, pDelList, &pTSRow, pReader); - *start = startPos; - } else { - int32_t remain = (startPos - endPos) + 1; - if (remain + numOfExisted > pTsdbReadHandle->outputCapacity) { - *end = startPos + 1 - (pTsdbReadHandle->outputCapacity - numOfExisted); - } else { - *end = endPos; + 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; + } } - - *start = *end; - *end = startPos; } -} - -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; + ASSERT(0); } -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; +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 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); + int64_t ts = pBlockData->aTSKEY[pDumpInfo->rowIndex]; + if (ts > pReader->window.ekey || ts < pReader->window.skey) { + 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)); - - // 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); -} - -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; - - SQueryFilePos* cur = &pTsdbReadHandle->cur; - SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0]; - - 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; - } - } 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; - } - } - } - cur->mixBlock = true; + TSDBKEY k = {.ts = ts, .version = ver}; + if (hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, &k)) { + return false; } - return endPos; + return true; } -// 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; - } +static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWindow->ekey) || (ts < pWindow->skey); } - cur->win.ekey = key; - cur->lastKey = key + step; - cur->mixBlock = true; +static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + SBlockData* pBlockData = &pReader->status.fileBlockData; - 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); + SRowMerger merge = {0}; + STSRow* pTSRow = NULL; - if (rv1 != TD_ROW_SVER(row1)) { - rv1 = TD_ROW_SVER(row1); - } - if (row2 && rv2 != TD_ROW_SVER(row2)) { - rv2 = TD_ROW_SVER(row2); - } + int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex]; + TSDBROW* pRow = getValidRow(&pBlockScanInfo->iter, pBlockScanInfo->delSkyline, pReader); + TSDBROW* piRow = getValidRow(&pBlockScanInfo->iiter, pBlockScanInfo->delSkyline, pReader); - // 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; - } + if (pBlockScanInfo->iter.hasVal && pBlockScanInfo->iiter.hasVal) { + return doMergeThreeLevelRows(pReader, pBlockScanInfo); + } else { + // imem + file + if (pBlockScanInfo->iiter.hasVal) { + return doMergeBufAndFileRows(pReader, pBlockScanInfo, piRow, pTSRow, &pBlockScanInfo->iiter, 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}; + } - numOfRows = lastPos - firstPos + 1; - midPos = (numOfRows >> 1) + firstPos; + int32_t backward = (!ASCENDING_TRAVERSE(pReader->order)); - if (key < keyList[midPos]) { - lastPos = midPos - 1; - } else if (key > keyList[midPos]) { - firstPos = midPos + 1; + 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); + + 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; } + } + + return key; +} - SBlock* pBlock = pTableCheck->pCompInfo->blocks; - sup.numOfBlocksPerTable[numOfQualTables] = pTableCheck->numOfBlocks; +static int32_t moveToNextFile(STsdbReader* pReader, int32_t* numOfBlocks) { + SReaderStatus* pStatus = &pReader->status; - char* buf = taosMemoryMalloc(sizeof(STableBlockInfo) * pTableCheck->numOfBlocks); - if (buf == NULL) { - cleanBlockOrderSupporter(&sup, numOfQualTables); - return TSDB_CODE_TDB_OUT_OF_MEMORY; + 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; +} + +static int32_t doBuildDataBlock(STsdbReader* pReader) { + int32_t code = 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); + SReaderStatus* pStatus = &pReader->status; + SDataBlockIter* pBlockIter = &pStatus->blockIter; - tsdbDebug("%p create data blocks info struct completed for 1 table, %d blocks not sorted %s", pTsdbReadHandle, cnt, - pTsdbReadHandle->idStr); - return TSDB_CODE_SUCCESS; - } + SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(pBlockIter); + STableBlockScanInfo* pScanInfo = taosHashGet(pStatus->pTableMap, &pFBlock->uid, sizeof(pFBlock->uid)); - tsdbDebug("%p create data blocks info struct completed, %d blocks in %d tables %s", pTsdbReadHandle, cnt, - numOfQualTables, pTsdbReadHandle->idStr); + SBlock* pBlock = taosArrayGet(pScanInfo->pBlockList, pFBlock->tbBlockIdx); - assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pTableQueryInfo[j]->numOfBlocks may be 0 - sup.numOfTables = numOfQualTables; + 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; + } - 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; + // 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; - STableBlockInfo* pBlocksInfo = sup.pDataBlockInfo[pos]; - pTsdbReadHandle->pDataBlockInfo[numOfTotal++] = pBlocksInfo[index]; + while (1) { + if (pStatus->pTableIter == NULL) { + pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL); + if (pStatus->pTableIter == NULL) { + return TSDB_CODE_SUCCESS; + } + } - // 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; + STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter; + initMemDataIterator(pBlockScanInfo, pReader); + + 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; + } - for (int32_t i = 0; i < numOfTables; ++i) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + return rowIndex; +} - SBlock* pBlock = pCheckInfo->pCompInfo->blocks; +typedef enum { + CHECK_FILEBLOCK_CONT = 0x1, + CHECK_FILEBLOCK_QUIT = 0x2, +} CHECK_FILEBLOCK_STATE; - for (int32_t j = 0; j < pCheckInfo->numOfBlocks; ++j) { - pTableBlockInfo->totalSize += pBlock[j].len; +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; - int32_t numOfRows = pBlock[j].numOfRows; - pTableBlockInfo->totalRows += numOfRows; + *state = CHECK_FILEBLOCK_QUIT; + int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; - if (numOfRows > pTableBlockInfo->maxRows) { - pTableBlockInfo->maxRows = numOfRows; - } + int32_t nextIndex = -1; + SBlock* pNeighborBlock = getNeighborBlockOfSameTable(pFBlock, pScanInfo, &nextIndex, pReader->order); + if (pNeighborBlock == NULL) { // do nothing + return 0; + } - if (numOfRows < pTableBlockInfo->minRows) { - pTableBlockInfo->minRows = numOfRows; - } + bool overlap = overlapWithNeighborBlock(pBlock, pNeighborBlock, pReader->order); + if (overlap) { // load next block + SReaderStatus* pStatus = &pReader->status; + SDataBlockIter* pBlockIter = &pStatus->blockIter; - if (numOfRows < defaultRows) { - pTableBlockInfo->numOfSmallBlocks += 1; - } + // 1. find the next neighbor block in the scan block list + SFileDataBlockInfo fb = {.uid = pFBlock->uid, .tbBlockIdx = nextIndex}; + int32_t neighborIndex = findFileBlockInfoIndex(pBlockIter, &fb); - int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows); - pTableBlockInfo->blockRowsHisto[bucketIndex]++; - } + // 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; } - } - pTableBlockInfo->numOfTables = numOfTables; - return code; -} + // 4. check the data values + initBlockDumpInfo(pReader, pBlockIter); -static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exists) { - STsdbFS* pFileHandle = REPO_FS(pTsdbReadHandle->pTsdb); - SQueryFilePos* cur = &pTsdbReadHandle->cur; + pDumpInfo->rowIndex = + doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, key, pMerger, &pReader->verRange, step); - // 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 (pDumpInfo->rowIndex >= pBlock->nRow) { + *state = CHECK_FILEBLOCK_CONT; + } + } - tsdbRLockFS(pFileHandle); - tsdbFSIterInit(&pTsdbReadHandle->fileIter, pFileHandle, pTsdbReadHandle->order); - tsdbFSIterSeek(&pTsdbReadHandle->fileIter, fid); - tsdbUnLockFS(pFileHandle); + return TSDB_CODE_SUCCESS; +} - return getFirstFileDataBlock(pTsdbReadHandle, exists); - } else { - // check if current file block is all consumed - STableBlockInfo* pBlockInfo = &pTsdbReadHandle->pDataBlockInfo[cur->slot]; - STableCheckInfo* pCheckInfo = pBlockInfo->pTableCheckInfo; +int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader, + SRowMerger* pMerger) { + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - // 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); + bool asc = ASCENDING_TRAVERSE(pReader->order); + int64_t key = pBlockData->aTSKEY[pDumpInfo->rowIndex]; + int32_t step = asc ? 1 : -1; - if (code != TSDB_CODE_SUCCESS || *exists) { - return code; - } - } + pDumpInfo->rowIndex += step; + if (pDumpInfo->rowIndex <= pBlockData->nRow - 1) { + pDumpInfo->rowIndex = + doMergeRowsInFileBlockImpl(pBlockData, pDumpInfo->rowIndex, key, pMerger, &pReader->verRange, step); + } - // 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); + // 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; + + 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; + } } } -} -static bool doHasDataInBuffer(STsdbReadHandle* pTsdbReadHandle) { - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); + return TSDB_CODE_SUCCESS; +} - while (pTsdbReadHandle->activeIndex < numOfTables) { - if (hasMoreDataInCache(pTsdbReadHandle)) { - return true; - } +void updateSchema(TSDBROW* pRow, uint64_t uid, STsdbReader* pReader) { + int32_t sversion = TSDBROW_SVERSION(pRow); - pTsdbReadHandle->activeIndex += 1; + 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); } - - return false; } -// 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; +void doMergeMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo *pIter, SArray* pDelList, STSRow** pTSRow, STsdbReader* pReader) { + SRowMerger merge = {0}; - // starts from the buffer in case of descending timestamp order check data blocks - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); + TSDBKEY k = TSDBROW_KEY(pRow); + updateSchema(pRow, uid, pReader); - int32_t i = 0; - while (i < numOfTables) { - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(pIter, k.ts, pDelList, &merge, pReader); + tRowMergerGetRow(&merge, pTSRow); +} - // the first qualified table for interpolation query - // if ((pTsdbReadHandle->window.skey <= pCheckInfo->pTableObj->lastKey) && - // (pCheckInfo->pTableObj->lastKey != TSKEY_INITIAL_VAL)) { - // break; - // } +void doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* pBlockScanInfo, STsdbReader* pReader, + STSRow** pTSRow) { + SRowMerger merge = {0}; - i++; - } + TSDBKEY k = TSDBROW_KEY(pRow); + TSDBKEY ik = TSDBROW_KEY(piRow); - // there are no data in all the tables - if (i == numOfTables) { - return; - } + if (ASCENDING_TRAVERSE(pReader->order)) { // ascending order imem --> mem + updateSchema(piRow, pBlockScanInfo->uid, pReader); - STableCheckInfo info = *(STableCheckInfo*)taosArrayGet(pTsdbReadHandle->pTableCheckInfo, i); - taosArrayClear(pTsdbReadHandle->pTableCheckInfo); + tRowMergerInit(&merge, piRow, pReader->pSchema); + doMergeRowsInBuf(&pBlockScanInfo->iiter, ik.ts, pBlockScanInfo->delSkyline, &merge, pReader); - info.lastKey = pTsdbReadHandle->window.skey; - taosArrayPush(pTsdbReadHandle->pTableCheckInfo, &info); -} + tRowMerge(&merge, pRow); + doMergeRowsInBuf(&pBlockScanInfo->iter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); + } else { + updateSchema(pRow, pBlockScanInfo->uid, pReader); -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; + tRowMergerInit(&merge, pRow, pReader->pSchema); + doMergeRowsInBuf(&pBlockScanInfo->iter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); - int64_t st = taosGetTimestampUs(); - int16_t rv = -1; - STSchema* pSchema = NULL; - TSKEY lastRowKey = TSKEY_INITIAL_VAL; + tRowMerge(&merge, piRow); + doMergeRowsInBuf(&pBlockScanInfo->iiter, k.ts, pBlockScanInfo->delSkyline, &merge, pReader); + } - do { - STSRow* row = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, NULL, TD_VER_MAX); - if (row == NULL) { - break; - } + tRowMergerGetRow(&merge, pTSRow); +} - 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); +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; - break; + // 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; } + } - if (win->skey == INT64_MIN) { - win->skey = key; + if (pBlockScanInfo->iiter.hasVal) { + TSDBKEY k = TSDBROW_KEY(piRow); + if ((k.ts >= endKey && asc) || (k.ts <= endKey && !asc)) { + piRow = NULL; } + } - 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 (pBlockScanInfo->iter.hasVal && pBlockScanInfo->iiter.hasVal && pRow != NULL && piRow != NULL) { + TSDBKEY k = TSDBROW_KEY(pRow); + TSDBKEY ik = TSDBROW_KEY(piRow); - if (numOfRows >= maxRowsToRead) { - moveToNextRowInMem(pCheckInfo); - break; + 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); } - } while (moveToNextRowInMem(pCheckInfo)); + return TSDB_CODE_SUCCESS; + } - taosMemoryFreeClear(pSchema); // free the STSChema - assert(numOfRows <= maxRowsToRead); + if (pBlockScanInfo->iter.hasVal && pRow != NULL) { + doMergeMultiRows(pRow, pBlockScanInfo->uid, &pBlockScanInfo->iter, pDelList, pTSRow, pReader); + 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); + if (pBlockScanInfo->iiter.hasVal && piRow != NULL) { + doMergeMultiRows(piRow, pBlockScanInfo->uid, &pBlockScanInfo->iiter, pDelList, pTSRow, pReader); + return TSDB_CODE_SUCCESS; + } - return numOfRows; + return TSDB_CODE_SUCCESS; } -void* tsdbGetIdx(SMeta* pMeta) { - if (pMeta == NULL) { - return NULL; - } - return metaGetIdx(pMeta); -} -void* tsdbGetIvtIdx(SMeta* pMeta) { - if (pMeta == NULL) { - return NULL; +int32_t doAppendOneRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow) { + int32_t numOfRows = pBlock->info.rows; + int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock); + + SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; + STSchema* pSchema = pReader->pSchema; + + SColVal colVal = {0}; + int32_t i = 0, j = 0; + + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, i); + if (pColInfoData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { + colDataAppend(pColInfoData, numOfRows, (const char*)&pTSRow->ts, false); + i += 1; } - 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; + 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; } + } - STableKeyInfo info = {.lastKey = TSKEY_INITIAL_VAL, uid = id, .groupId = 0}; - taosArrayPush(list, &info); + // 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; } - metaCloseCtbCursor(pCur); + pBlock->info.rows += 1; return TSDB_CODE_SUCCESS; } -int32_t tsdbGetCtbIdList(SMeta* pMeta, int64_t suid, SArray* list) { - SMCtbCursor* pCur = metaOpenCtbCursor(pMeta, suid); +int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t endKey, int32_t capacity, + STsdbReader* pReader) { + SSDataBlock* pBlock = pReader->pResBlock; - while (1) { - tb_uid_t id = metaCtbCursorNext(pCur); - if (id == 0) { + do { + STSRow* pTSRow = NULL; + tsdbGetNextRowInMem(pBlockScanInfo, pReader, &pTSRow, endKey); + if (pTSRow == NULL) { break; } - taosArrayPush(list, &id); - } + doAppendOneRow(pBlock, pReader, pTSRow); + + // no data in buffer, return immediately + if (!(pBlockScanInfo->iter.hasVal || pBlockScanInfo->iiter.hasVal)) { + break; + } - metaCloseCtbCursor(pCur); + if (pBlock->info.rows >= capacity) { + break; + } + } while (1); + + ASSERT(pBlock->info.rows <= capacity); return TSDB_CODE_SUCCESS; } +// todo refactor, use arraylist instead +int32_t tsdbSetTableId(STsdbReader* pReader, int64_t uid) { + ASSERT(pReader != NULL); + taosHashClear(pReader->status.pTableMap); + + STableBlockScanInfo info = {.lastKey = 0, .uid = uid}; + taosHashPut(pReader->status.pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info)); + return TDB_CODE_SUCCESS; +} + /** * @brief Get all suids since suid * @@ -2928,852 +2882,587 @@ int32_t tsdbGetStbIdList(SMeta* pMeta, int64_t suid, SArray* list) { return TSDB_CODE_SUCCESS; } -static void destroyHelper(void* param) { - if (param == NULL) { - return; - } +// 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)); - // } +// // tQueryInfo* pInfo = (tQueryInfo*)param; +// // if (pInfo->optr != TSDB_RELATION_IN) { +// // taosMemoryFreeClear(pInfo->q); +// // } else { +// // taosHashCleanup((SHashObj *)(pInfo->q)); +// // } - taosMemoryFree(param); -} +// taosMemoryFree(param); +// } -#define TSDB_PREV_ROW 0x1 -#define TSDB_NEXT_ROW 0x2 +// #define TSDB_PREV_ROW 0x1 +// #define TSDB_NEXT_ROW 0x2 -static bool loadBlockOfActiveTable(STsdbReadHandle* pTsdbReadHandle) { - if (pTsdbReadHandle->checkFiles) { - // check if the query range overlaps with the file data block - bool exists = true; +// static bool loadBlockOfActiveTable(STsdbReader* pTsdbReadHandle) { +// if (pTsdbReadHandle->checkFiles) { +// // check if the query range overlaps with the file data block +// bool exists = true; - int32_t code = getDataBlocksInFiles(pTsdbReadHandle, &exists); - if (code != TSDB_CODE_SUCCESS) { - pTsdbReadHandle->checkFiles = false; - return false; - } +// int32_t code = buildBlockFromFiles(pTsdbReadHandle, &exists); +// if (code != TSDB_CODE_SUCCESS) { +// pTsdbReadHandle->checkFiles = false; +// return false; +// } - 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); - } +// 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->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. - return exists; - } +// pTsdbReadHandle->currentLoadExternalRows = false; // clear the flag, since the exact matched row is found. +// return exists; +// } - pTsdbReadHandle->checkFiles = false; - } +// pTsdbReadHandle->checkFiles = false; +// } - if (hasMoreDataInCache(pTsdbReadHandle)) { - pTsdbReadHandle->currentLoadExternalRows = false; - return true; - } +// 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; - // 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); + +// // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); +// // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); +// pTsdbReadHandle->currentLoadExternalRows = false; + +// return result; +// } - bool result = tsdbGetExternalRow(pTsdbReadHandle); +// return false; +// } + +// static bool loadDataBlockFromTableSeq(STsdbReader* pTsdbReadHandle) { +// size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); +// assert(numOfTables > 0); - // pTsdbReadHandle->prev = doFreeColumnInfoData(pTsdbReadHandle->prev); - // pTsdbReadHandle->next = doFreeColumnInfoData(pTsdbReadHandle->next); - pTsdbReadHandle->currentLoadExternalRows = false; +// 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 result; - } +// size_t cols = taosArrayGetSize(pColumnInfoData); +// for (int32_t i = 0; i < cols; ++i) { +// SColumnInfoData* pColInfo = taosArrayGet(pColumnInfoData, i); +// colDataDestroy(pColInfo); +// } - return false; -} +// taosArrayDestroy(pColumnInfoData); +// return NULL; +// } -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); +// 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); - SQueryFilePos* cur = &pTsdbReadHandle->cur; +// taosMemoryFreeClear(p->pCompInfo); +// } - 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; +// taosArrayDestroy(pTableCheckInfo); +// return NULL; +// } - 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); +// ====================================== 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; + } - // update the last key value - pCheckInfo->lastKey = key + step; + int32_t numOfTables = taosArrayGetSize(pTableList); + pReader->status.pTableMap = createDataBlockScanInfo(pReader, pTableList->pData, numOfTables); + if (pReader->status.pTableMap == NULL) { + tsdbReaderClose(pReader); + *ppReader = NULL; - cur->rows = 1; // only one row - cur->lastKey = key + step; - cur->mixBlock = true; - cur->win.skey = key; - cur->win.ekey = key; + code = TSDB_CODE_TDB_OUT_OF_MEMORY; + goto _err; + } - return true; + SDataBlockIter* pBlockIter = &pReader->status.blockIter; + + STsdbFSState* pFState = pReader->pTsdb->fs->cState; + initFilesetIterator(&pReader->status.fileIter, pFState, pReader->order, pReader->idStr); + resetDataBlockIterator(&pReader->status.blockIter, pReader->order); + + // 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; + } } - return false; + tsdbDebug("%p total numOfTable:%d in this query %s", pReader, numOfTables, pReader->idStr); + return code; + +_err: + tsdbError("failed to create data reader, code: %s %s", tstrerror(code), pReader->idStr); + return code; } -// 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; -//} +void tsdbReaderClose(STsdbReader* pReader) { + if (pReader == NULL) { + return; + } -static bool loadDataBlockFromTableSeq(STsdbReadHandle* pTsdbReadHandle) { - size_t numOfTables = taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo); - assert(numOfTables > 0); + blockDataDestroy(pReader->pResBlock); - int64_t stime = taosGetTimestampUs(); + taosMemoryFreeClear(pReader->suppInfo.pstatis); + taosMemoryFreeClear(pReader->suppInfo.plist); + taosMemoryFree(pReader->suppInfo.slotIds); - while (pTsdbReadHandle->activeIndex < numOfTables) { - if (loadBlockOfActiveTable(pTsdbReadHandle)) { - return true; - } + 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); +// } - STableCheckInfo* pCheckInfo = taosArrayGet(pTsdbReadHandle->pTableCheckInfo, pTsdbReadHandle->activeIndex); - pCheckInfo->numOfBlocks = 0; +// tsdbDestroyReadH(&pReader->rhelper); - pTsdbReadHandle->activeIndex += 1; - pTsdbReadHandle->locateStart = false; - pTsdbReadHandle->checkFiles = true; - pTsdbReadHandle->cur.rows = 0; - pTsdbReadHandle->currentLoadExternalRows = pTsdbReadHandle->loadExternalRow; +// tdFreeDataCols(pReader->pDataCols); +// pReader->pDataCols = NULL; +// +// pReader->prev = doFreeColumnInfoData(pReader->prev); +// pReader->next = doFreeColumnInfoData(pReader->next); +#endif - terrno = TSDB_CODE_SUCCESS; + SIOCostSummary* pCost = &pReader->cost; - int64_t elapsedTime = taosGetTimestampUs() - stime; - pTsdbReadHandle->cost.checkForNextTime += elapsedTime; - } + 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); - return false; + taosMemoryFree(pReader->idStr); + taosMemoryFree(pReader->pSchema); + taosMemoryFreeClear(pReader); } -// handle data in cache situation -// bool tsdbNextDataBlock(tsdbReaderT pHandle, uint64_t uid) -bool tsdbNextDataBlock(tsdbReaderT pHandle) { - STsdbReadHandle* pTsdbReadHandle = (STsdbReadHandle*)pHandle; - - 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); - } - - if (emptyQueryTimewindow(pTsdbReadHandle)) { - tsdbDebug("%p query window not overlaps with the data set, no result returned, %s", pTsdbReadHandle, - pTsdbReadHandle->idStr); +bool tsdbNextDataBlock(STsdbReader* pReader) { + if (isEmptyQueryTimeWindow(&pReader->window)) { return false; } - int64_t stime = taosGetTimestampUs(); - int64_t elapsedTime = stime; - - // 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); - } - } + // cleanup the data that belongs to the previous data block + SSDataBlock* pBlock = pReader->pResBlock; + blockDataCleanup(pBlock); - 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; + int64_t stime = taosGetTimestampUs(); + int64_t elapsedTime = stime; + SReaderStatus* pStatus = &pReader->status; - int32_t code = getDataBlocksInFiles(pTsdbReadHandle, &exists); + if (pReader->type == BLOCK_LOAD_OFFSET_ORDER) { + if (pStatus->loadFromFile) { + int32_t code = buildBlockFromFiles(pReader); if (code != TSDB_CODE_SUCCESS) { - pTsdbReadHandle->activeIndex = 0; - pTsdbReadHandle->checkFiles = false; - 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 124efaa3c77ba395d144bc31a6e8501bbccceab2..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,6 +80,7 @@ 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->blockCount = 0; 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 dc87be8bbbadbda6143cfb44f59d4e76b57f5d6f..ed9206c04ee88f233b9ca8bdb23461f829735e3a 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -25,8 +25,8 @@ 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 vnodeProcessWriteReq(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 vnodePreProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg) { int32_t code = 0; @@ -93,11 +93,44 @@ int32_t vnodePreProcessWriteMsg(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 vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp) { @@ -146,7 +179,7 @@ int32_t vnodeProcessWriteMsg(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 (vnodeProcessWriteReq(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 vnodeProcessWriteMsg(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 vnodeProcessWriteMsg(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); @@ -292,22 +328,6 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { } } -int32_t vnodeProcessWriteReq(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 @@ -328,7 +348,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; @@ -868,3 +888,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 621c6ef6e039d6b09d2fb7be320458d4134e56f5..ab0ad6875e772ee5ab7288396b4cd9707eca4efe 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -242,17 +242,14 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { } #if 1 - 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), "vnode process syncmsg, msgType:%d, syncNode:%s", pMsg->msgType, syncNodeStr); - syncRpcMsgLog2(logBuf, pMsg); - } - taosMemoryFree(syncNodeStr); + 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) { @@ -305,7 +302,8 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg->msgType); code = -1; } - } else { + + } else if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_WAL_FIRST) { // use wal first strategy if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); @@ -411,43 +409,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), - "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), "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), "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 88f2fedd2873d1302cbd3cc7a059c6de30d1fba6..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 @@ -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 { @@ -682,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 { @@ -755,7 +768,7 @@ 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); @@ -768,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/executil.c b/source/libs/executor/src/executil.c index fcdc4c840e6c0c9351d46bb2cb6e3d5b589d8a4d..2d2f9bab38f3531c2acccac3ebaef2ed8ae62af8 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -63,7 +63,8 @@ size_t getResultRowSize(SqlFunctionCtx* pCtx, int32_t numOfOutput) { rowSize += pCtx[i].resDataInfo.interBufSize; } - rowSize += (numOfOutput * sizeof(bool)); // expand rowSize to mark if col is null for top/bottom result(saveTupleData) + rowSize += + (numOfOutput * sizeof(bool)); // expand rowSize to mark if col is null for top/bottom result(saveTupleData) return rowSize; } @@ -114,7 +115,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SHashObj* pHashmap, int p->pos = *(SResultRowPosition*)pData; memcpy(p->key, (char*)key + sizeof(uint64_t), keyLen - sizeof(uint64_t)); #ifdef BUF_PAGE_DEBUG - qDebug("page_groupRes, groupId:%"PRIu64",pageId:%d,offset:%d\n", p->groupId, p->pos.pageId, p->pos.offset); + qDebug("page_groupRes, groupId:%" PRIu64 ",pageId:%d,offset:%d\n", p->groupId, p->pos.pageId, p->pos.offset); #endif taosArrayPush(pGroupResInfo->pRows, &p); } @@ -288,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; @@ -301,14 +305,11 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo SNode* pTagIndexCond = (SNode*)pListInfo->pTagIndexCond; if (pScanNode->tableType == TSDB_SUPER_TABLE) { if (pTagIndexCond) { - SIndexMetaArg metaArg = { - .metaEx = metaHandle, .idx = tsdbGetIdx(metaHandle), .ivtIdx = tsdbGetIvtIdx(metaHandle), .suid = tableUid}; - SArray* res = taosArrayInit(8, sizeof(uint64_t)); // code = doFilterTag(pTagIndexCond, &metaArg, res); code = TSDB_CODE_INDEX_REBUILDING; 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); @@ -324,7 +325,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) { @@ -333,13 +334,13 @@ int32_t getTableList(void* metaHandle, SScanPhysiNode* pScanNode, STableListInfo return code; } - if(pTagCond){ + if (pTagCond) { int32_t i = 0; while (i < taosArrayGetSize(pListInfo->pTableList)) { STableKeyInfo* info = taosArrayGet(pListInfo->pTableList, i); - bool isOk = isTableOk(info, pTagCond, metaHandle); - if(terrno) return terrno; - if(!isOk){ + bool isOk = isTableOk(info, pTagCond, metaHandle); + if (terrno) return terrno; + if (!isOk) { taosArrayRemove(pListInfo->pTableList, i); continue; } @@ -350,8 +351,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); @@ -742,8 +746,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)); @@ -759,25 +761,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; @@ -798,10 +782,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 ed78e4173a8f7e660855630e1585dfece466cd60..7f84b4c1743e49c8cd6c42d452c970bc5ecb49a7 100644 --- a/source/libs/executor/src/executorMain.c +++ b/source/libs/executor/src/executorMain.c @@ -143,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 17ff0cc4306d562b51433db30c2fd1534645a4cf..7db7ae0c55a4dc9b06b0db0ff68e379116bdd511 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; @@ -3889,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; @@ -3991,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); @@ -4193,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; @@ -4252,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; @@ -4294,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); } @@ -4504,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; } @@ -4523,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; @@ -4586,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"); @@ -4744,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 515efb86f3bd28969822156309ecf2059f890594..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) { @@ -2158,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; } @@ -2177,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); @@ -2234,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) { @@ -2275,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; @@ -2321,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); @@ -2399,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 @@ -2443,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; } @@ -2529,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); } @@ -2637,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 aa02aa4faa04408d0f1ed42f1c1e796ac6f289bd..1e7e7e57c3d1c9333afaef5969bca49a2ec20ee6 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -2211,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 7c40f373a7ed579fb444b1f88e7e534bed7567d4..f94522f0d8bde5df192d6481f2c2a9ae4cc57291 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -5937,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/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index 22c13a3934f3a0cd1c745bd0e746ff8f5b5233b7..6c0717e8450e5b5e3a5f5f07bcc29545035d7eb0 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -394,10 +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 cd77361b51bf04deb4680b8928e93907952fdaab..2a94ee43e3f13340cf06919fd111ce44274fdad5 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2214,6 +2214,8 @@ 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"; @@ -2224,6 +2226,12 @@ 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); } @@ -2247,6 +2255,12 @@ 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); } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index cdc26547f7d39819913b4292daea9d57cc8a12fa..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: @@ -545,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); diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 5c2dcadd4a8f1e00efb210caa00168f402a6e585..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); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 7d919874d52670ced72a97448b85e9389d07cf27..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 { } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index a1a9532acebc1cf93d2ffc4cae9b88e8ed4ef977..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); @@ -1670,5 +1681,10 @@ SNode* createInsertStmt(SAstCreateContext* pCxt, SNode* pTable, SNodeList* pCols 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 8a1b072105d65a6e0e196d8ff99a1057e87fea10..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) { @@ -487,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: 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 1f4294279b83ade0780d37a0f8d74b05c74a6dc0..0975fe7309189512503285930f7475c432c3e48c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2839,17 +2839,87 @@ 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 = translateExprList(pCxt, pInsert->pCols); + code = translateInsertCols(pCxt, pInsert); } if (TSDB_CODE_SUCCESS == code) { - code = resetTranslateNamespace(pCxt); + code = translateInsertQuery(pCxt, pInsert); } if (TSDB_CODE_SUCCESS == code) { - code = translateQuery(pCxt, pInsert->pQuery); + code = translateInsertProject(pCxt, pInsert); } return code; } @@ -6129,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)) { @@ -6177,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; } diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 84ce6acf6deac71956067e96c347ca17b43c2879..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 658 -#define YYNRULE 484 -#define YYNTOKEN 252 -#define YY_MAX_SHIFT 657 -#define YY_MIN_SHIFTREDUCE 959 -#define YY_MAX_SHIFTREDUCE 1442 -#define YY_ERROR_ACTION 1443 -#define YY_ACCEPT_ACTION 1444 -#define YY_NO_ACTION 1445 -#define YY_MIN_REDUCE 1446 -#define YY_MAX_REDUCE 1929 +#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,654 +216,658 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2354) +#define YY_ACTTAB_COUNT (2363) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 378, 1907, 427, 509, 428, 1481, 435, 341, 428, 1481, - /* 10 */ 1625, 1627, 40, 38, 1906, 140, 1444, 71, 1904, 79, - /* 20 */ 336, 1447, 1244, 1511, 1583, 41, 39, 37, 36, 35, - /* 30 */ 117, 992, 522, 1319, 1764, 1242, 62, 31, 258, 1575, - /* 40 */ 1573, 1907, 103, 164, 1907, 102, 101, 100, 99, 98, - /* 50 */ 97, 96, 95, 94, 159, 546, 1314, 159, 1904, 14, - /* 60 */ 1580, 1904, 1782, 549, 549, 1250, 1782, 142, 1269, 1458, - /* 70 */ 574, 996, 997, 323, 539, 1734, 348, 573, 40, 38, - /* 80 */ 1382, 140, 1, 122, 479, 478, 336, 1632, 1244, 477, - /* 90 */ 1582, 551, 118, 474, 324, 444, 473, 472, 471, 1319, - /* 100 */ 1764, 1242, 1795, 1630, 654, 1469, 89, 1765, 576, 1767, - /* 110 */ 1768, 572, 538, 567, 61, 61, 1841, 1907, 1321, 1322, - /* 120 */ 303, 1837, 1314, 120, 624, 14, 44, 339, 1782, 143, - /* 130 */ 159, 1250, 1907, 1537, 1904, 140, 574, 548, 155, 1849, - /* 140 */ 1850, 1734, 1854, 573, 1582, 161, 1734, 103, 2, 1904, - /* 150 */ 102, 101, 100, 99, 98, 97, 96, 95, 94, 426, - /* 160 */ 219, 220, 430, 1245, 372, 1243, 1141, 1142, 1795, 346, - /* 170 */ 654, 1508, 91, 1765, 576, 1767, 1768, 572, 1269, 567, - /* 180 */ 434, 510, 1841, 430, 1321, 1322, 1840, 1837, 1446, 322, - /* 190 */ 1248, 1249, 1677, 1297, 1298, 1300, 1301, 1302, 1303, 1304, - /* 200 */ 569, 565, 1312, 1313, 1315, 1316, 1317, 1318, 1320, 1323, - /* 210 */ 1907, 535, 112, 111, 110, 109, 108, 107, 106, 105, - /* 220 */ 104, 302, 162, 159, 512, 213, 1676, 1904, 297, 1245, - /* 230 */ 71, 1243, 631, 630, 629, 344, 549, 628, 627, 626, - /* 240 */ 123, 621, 620, 619, 618, 617, 616, 615, 614, 133, - /* 250 */ 610, 61, 1576, 75, 162, 162, 1248, 1249, 61, 1297, - /* 260 */ 1298, 1300, 1301, 1302, 1303, 1304, 569, 565, 1312, 1313, - /* 270 */ 1315, 1316, 1317, 1318, 1320, 1323, 40, 38, 555, 342, - /* 280 */ 479, 478, 384, 1403, 336, 477, 1244, 140, 118, 474, - /* 290 */ 541, 536, 473, 472, 471, 495, 1582, 1319, 43, 1242, - /* 300 */ 1099, 598, 597, 596, 1103, 595, 1105, 1106, 594, 1108, - /* 310 */ 591, 1268, 1114, 588, 1116, 1117, 585, 582, 1907, 300, - /* 320 */ 1314, 1751, 484, 14, 532, 1401, 1402, 1404, 1405, 1250, - /* 330 */ 1468, 160, 1748, 40, 38, 1904, 1907, 494, 377, 522, - /* 340 */ 376, 336, 86, 1244, 1764, 1632, 2, 206, 1061, 159, - /* 350 */ 113, 205, 340, 1904, 1319, 119, 1242, 465, 1744, 1750, - /* 360 */ 325, 1630, 540, 1572, 1467, 487, 1244, 1580, 654, 481, - /* 370 */ 567, 1734, 1782, 522, 204, 1907, 1558, 1314, 1063, 1242, - /* 380 */ 550, 1267, 1321, 1322, 165, 1734, 1250, 573, 1905, 34, - /* 390 */ 33, 162, 1904, 41, 39, 37, 36, 35, 162, 56, - /* 400 */ 522, 1580, 55, 8, 1571, 1734, 73, 302, 432, 1250, - /* 410 */ 512, 382, 1795, 369, 1266, 1748, 90, 1765, 576, 1767, - /* 420 */ 1768, 572, 522, 567, 153, 654, 1841, 1245, 1580, 1243, - /* 430 */ 329, 1837, 154, 383, 444, 371, 367, 1619, 162, 1321, - /* 440 */ 1322, 1744, 1750, 218, 158, 1626, 1627, 1009, 654, 1008, - /* 450 */ 1580, 609, 1867, 567, 1248, 1249, 1680, 1297, 1298, 1300, - /* 460 */ 1301, 1302, 1303, 1304, 569, 565, 1312, 1313, 1315, 1316, - /* 470 */ 1317, 1318, 1320, 1323, 34, 33, 556, 1010, 41, 39, - /* 480 */ 37, 36, 35, 1009, 1245, 1008, 1243, 34, 33, 1556, - /* 490 */ 27, 41, 39, 37, 36, 35, 34, 33, 463, 1670, - /* 500 */ 41, 39, 37, 36, 35, 1224, 1225, 1245, 563, 1243, - /* 510 */ 172, 1248, 1249, 1010, 1297, 1298, 1300, 1301, 1302, 1303, - /* 520 */ 1304, 569, 565, 1312, 1313, 1315, 1316, 1317, 1318, 1320, - /* 530 */ 1323, 40, 38, 1324, 1248, 1249, 1439, 476, 475, 336, - /* 540 */ 417, 1244, 1764, 162, 1569, 522, 192, 609, 522, 1413, - /* 550 */ 1856, 1386, 1319, 522, 1242, 313, 387, 1268, 1270, 402, - /* 560 */ 146, 510, 1393, 546, 113, 461, 457, 453, 449, 191, - /* 570 */ 1782, 470, 1678, 1580, 1853, 1314, 1580, 1343, 574, 522, - /* 580 */ 1675, 1580, 297, 1734, 1250, 573, 174, 173, 40, 38, - /* 590 */ 403, 122, 625, 623, 72, 42, 336, 189, 1244, 551, - /* 600 */ 1348, 9, 522, 314, 469, 312, 311, 1580, 467, 1319, - /* 610 */ 1795, 1242, 469, 443, 89, 1765, 576, 1767, 1768, 572, - /* 620 */ 613, 567, 1552, 654, 1841, 1438, 468, 170, 303, 1837, - /* 630 */ 1580, 120, 1314, 522, 468, 1192, 493, 1321, 1322, 1333, - /* 640 */ 1907, 1250, 28, 1379, 1577, 1466, 156, 1849, 1850, 491, - /* 650 */ 1854, 489, 69, 159, 1752, 68, 1250, 1904, 9, 188, - /* 660 */ 181, 1580, 186, 11, 10, 1748, 440, 34, 33, 996, - /* 670 */ 997, 41, 39, 37, 36, 35, 546, 7, 607, 522, - /* 680 */ 654, 1329, 1245, 59, 1243, 179, 1734, 1268, 250, 601, - /* 690 */ 1709, 1744, 1750, 605, 1321, 1322, 1623, 131, 130, 604, - /* 700 */ 603, 602, 23, 567, 122, 1465, 1464, 1580, 1856, 1248, - /* 710 */ 1249, 1268, 1297, 1298, 1300, 1301, 1302, 1303, 1304, 569, - /* 720 */ 565, 1312, 1313, 1315, 1316, 1317, 1318, 1320, 1323, 34, - /* 730 */ 33, 1299, 1852, 41, 39, 37, 36, 35, 1033, 1245, - /* 740 */ 1856, 1243, 29, 1271, 120, 1355, 1734, 1734, 34, 33, - /* 750 */ 1463, 612, 41, 39, 37, 36, 35, 1462, 1461, 157, - /* 760 */ 1849, 1850, 606, 1854, 1851, 1623, 1248, 1249, 1034, 1297, - /* 770 */ 1298, 1300, 1301, 1302, 1303, 1304, 569, 565, 1312, 1313, - /* 780 */ 1315, 1316, 1317, 1318, 1320, 1323, 40, 38, 299, 1498, - /* 790 */ 1266, 1734, 657, 1565, 336, 1764, 1244, 410, 1734, 1734, - /* 800 */ 422, 37, 36, 35, 1282, 522, 265, 1319, 1460, 1242, - /* 810 */ 270, 480, 1457, 1610, 1861, 1375, 503, 395, 1557, 423, - /* 820 */ 151, 397, 212, 1782, 522, 647, 643, 639, 635, 263, - /* 830 */ 1314, 574, 522, 1580, 1456, 507, 1734, 502, 573, 1250, - /* 840 */ 34, 33, 1632, 520, 41, 39, 37, 36, 35, 1734, - /* 850 */ 74, 388, 1580, 1734, 87, 522, 2, 228, 1631, 1375, - /* 860 */ 1580, 1299, 1378, 1795, 45, 4, 521, 91, 1765, 576, - /* 870 */ 1767, 1768, 572, 230, 567, 1734, 1721, 1841, 654, 1455, - /* 880 */ 558, 562, 1837, 1580, 1454, 1299, 1453, 1452, 1451, 1450, - /* 890 */ 519, 421, 1321, 1322, 416, 415, 414, 413, 412, 409, - /* 900 */ 408, 407, 406, 405, 401, 400, 399, 398, 392, 391, - /* 910 */ 390, 389, 607, 386, 385, 1449, 1538, 52, 506, 553, - /* 920 */ 1734, 141, 215, 357, 1253, 1734, 276, 1734, 1734, 1734, - /* 930 */ 1734, 131, 130, 604, 603, 602, 1555, 1245, 522, 1243, - /* 940 */ 274, 58, 1487, 1216, 57, 208, 34, 33, 1252, 259, - /* 950 */ 41, 39, 37, 36, 35, 1567, 1734, 1563, 546, 197, - /* 960 */ 175, 209, 195, 217, 1248, 1249, 1580, 1297, 1298, 1300, - /* 970 */ 1301, 1302, 1303, 1304, 569, 565, 1312, 1313, 1315, 1316, - /* 980 */ 1317, 1318, 1320, 1323, 1493, 61, 122, 34, 33, 522, - /* 990 */ 649, 41, 39, 37, 36, 35, 199, 304, 201, 198, - /* 1000 */ 343, 200, 1491, 221, 34, 33, 482, 551, 41, 39, - /* 1010 */ 37, 36, 35, 203, 568, 125, 202, 1580, 11, 10, - /* 1020 */ 1754, 1282, 85, 88, 485, 600, 120, 1459, 128, 1341, - /* 1030 */ 607, 129, 82, 50, 253, 234, 1764, 496, 304, 1441, - /* 1040 */ 1442, 248, 1849, 545, 42, 544, 42, 533, 1907, 131, - /* 1050 */ 130, 604, 603, 602, 1256, 515, 1756, 42, 66, 65, - /* 1060 */ 381, 161, 580, 169, 1782, 1904, 462, 128, 227, 375, - /* 1070 */ 1341, 1092, 571, 1400, 242, 237, 1783, 1734, 1255, 573, - /* 1080 */ 559, 345, 298, 1342, 1349, 365, 1305, 363, 359, 355, - /* 1090 */ 166, 350, 347, 129, 114, 1764, 1482, 269, 1620, 128, - /* 1100 */ 547, 1871, 1120, 247, 1795, 252, 1347, 1124, 291, 1765, - /* 1110 */ 576, 1767, 1768, 572, 570, 567, 564, 1813, 255, 257, - /* 1120 */ 80, 5, 3, 1782, 1342, 162, 53, 349, 1266, 352, - /* 1130 */ 356, 550, 309, 1131, 1129, 1061, 1734, 1764, 573, 132, - /* 1140 */ 310, 1208, 266, 404, 1672, 171, 139, 1347, 30, 334, - /* 1150 */ 1336, 1337, 1338, 1339, 1340, 1344, 1345, 1346, 411, 418, - /* 1160 */ 419, 420, 424, 1795, 1272, 1782, 425, 90, 1765, 576, - /* 1170 */ 1767, 1768, 572, 574, 567, 433, 1275, 1841, 1734, 436, - /* 1180 */ 573, 329, 1837, 154, 178, 437, 180, 1274, 438, 30, - /* 1190 */ 334, 1336, 1337, 1338, 1339, 1340, 1344, 1345, 1346, 1276, - /* 1200 */ 1764, 439, 183, 1868, 441, 1795, 185, 1273, 442, 91, - /* 1210 */ 1765, 576, 1767, 1768, 572, 187, 567, 70, 445, 1841, - /* 1220 */ 190, 464, 301, 93, 1838, 1714, 1764, 466, 1782, 1570, - /* 1230 */ 194, 207, 1566, 267, 196, 134, 574, 135, 497, 1568, - /* 1240 */ 1564, 1734, 136, 573, 137, 498, 210, 214, 319, 504, - /* 1250 */ 508, 530, 516, 1271, 1782, 534, 501, 268, 511, 225, - /* 1260 */ 78, 1882, 574, 1713, 1682, 513, 321, 1734, 1795, 573, - /* 1270 */ 126, 526, 90, 1765, 576, 1767, 1768, 572, 6, 567, - /* 1280 */ 127, 517, 1841, 1881, 223, 1863, 329, 1837, 1920, 1581, - /* 1290 */ 543, 241, 148, 518, 1795, 528, 529, 1875, 90, 1765, - /* 1300 */ 576, 1767, 1768, 572, 232, 567, 328, 537, 1841, 1872, - /* 1310 */ 527, 236, 329, 1837, 1920, 1764, 327, 326, 525, 524, - /* 1320 */ 1375, 121, 1270, 1898, 560, 557, 1258, 246, 19, 330, - /* 1330 */ 578, 1624, 1857, 271, 1553, 243, 546, 1319, 651, 1251, - /* 1340 */ 262, 650, 51, 1782, 653, 284, 147, 1728, 244, 275, - /* 1350 */ 63, 574, 273, 294, 293, 1727, 1734, 1726, 573, 64, - /* 1360 */ 1314, 245, 1725, 1822, 122, 351, 1722, 353, 354, 1250, - /* 1370 */ 1236, 1237, 167, 1720, 358, 360, 361, 1903, 554, 362, - /* 1380 */ 251, 1764, 561, 1795, 254, 551, 256, 90, 1765, 576, - /* 1390 */ 1767, 1768, 572, 1719, 567, 1923, 364, 1841, 1718, 366, - /* 1400 */ 1717, 329, 1837, 1920, 120, 368, 1716, 370, 531, 1782, - /* 1410 */ 1699, 168, 1860, 373, 374, 1211, 1210, 574, 1693, 248, - /* 1420 */ 1849, 545, 1734, 544, 573, 379, 1907, 1692, 380, 1691, - /* 1430 */ 1690, 1180, 1665, 1664, 1663, 67, 1662, 1661, 551, 159, - /* 1440 */ 1660, 1659, 1658, 1904, 393, 1764, 394, 1657, 396, 1795, - /* 1450 */ 1656, 1655, 1654, 283, 1765, 576, 1767, 1768, 572, 1653, - /* 1460 */ 567, 1652, 1651, 1650, 1649, 1648, 1647, 1259, 1646, 1254, - /* 1470 */ 1645, 1644, 1643, 1782, 1642, 1641, 1640, 124, 1639, 1907, - /* 1480 */ 1638, 574, 1637, 1636, 1635, 1634, 1734, 1633, 573, 1182, - /* 1490 */ 1510, 1478, 161, 115, 1262, 176, 1904, 1764, 152, 1477, - /* 1500 */ 999, 1707, 551, 429, 431, 565, 1312, 1313, 1315, 1316, - /* 1510 */ 1317, 1318, 998, 1795, 1701, 1689, 116, 283, 1765, 576, - /* 1520 */ 1767, 1768, 572, 184, 567, 1782, 1688, 1674, 177, 1559, - /* 1530 */ 1509, 182, 1507, 574, 1505, 446, 447, 1503, 1734, 1027, - /* 1540 */ 573, 448, 450, 1907, 451, 452, 454, 456, 1501, 1490, - /* 1550 */ 1764, 455, 458, 1489, 1474, 460, 159, 459, 1561, 1135, - /* 1560 */ 1904, 1134, 193, 1560, 1764, 1795, 1060, 1499, 1059, 144, - /* 1570 */ 1765, 576, 1767, 1768, 572, 1058, 567, 1057, 1782, 622, - /* 1580 */ 1054, 624, 1053, 320, 49, 1052, 574, 315, 1494, 1492, - /* 1590 */ 316, 1734, 1782, 573, 317, 483, 1473, 523, 1472, 486, - /* 1600 */ 574, 488, 1471, 492, 490, 1734, 92, 573, 1706, 1218, - /* 1610 */ 54, 1700, 138, 552, 1921, 499, 1764, 1687, 1795, 500, - /* 1620 */ 1685, 1686, 292, 1765, 576, 1767, 1768, 572, 211, 567, - /* 1630 */ 1684, 1683, 1795, 15, 1228, 216, 292, 1765, 576, 1767, - /* 1640 */ 1768, 572, 1681, 567, 1782, 1673, 318, 82, 224, 229, - /* 1650 */ 42, 226, 574, 222, 16, 505, 1260, 1734, 76, 573, - /* 1660 */ 514, 77, 24, 10, 240, 1415, 231, 235, 1764, 48, - /* 1670 */ 233, 239, 26, 1397, 1399, 1392, 145, 238, 1754, 25, - /* 1680 */ 1764, 81, 249, 1372, 1795, 1427, 47, 1371, 287, 1765, - /* 1690 */ 576, 1767, 1768, 572, 1764, 567, 1782, 1753, 149, 1432, - /* 1700 */ 18, 1426, 1421, 331, 574, 1431, 1430, 332, 1782, 1734, - /* 1710 */ 20, 573, 1334, 333, 1290, 1798, 574, 575, 1309, 566, - /* 1720 */ 17, 1734, 1782, 573, 1307, 150, 542, 1306, 32, 12, - /* 1730 */ 571, 21, 163, 46, 579, 1734, 1795, 573, 22, 338, - /* 1740 */ 144, 1765, 576, 1767, 1768, 572, 13, 567, 1795, 583, - /* 1750 */ 1764, 577, 292, 1765, 576, 1767, 1768, 572, 1121, 567, - /* 1760 */ 581, 586, 1795, 1118, 1764, 584, 291, 1765, 576, 1767, - /* 1770 */ 1768, 572, 1115, 567, 1764, 1814, 587, 589, 1782, 1109, - /* 1780 */ 590, 592, 593, 335, 1107, 1922, 574, 599, 1113, 1098, - /* 1790 */ 1112, 1734, 1782, 573, 1111, 83, 1110, 337, 84, 1130, - /* 1800 */ 574, 60, 1782, 260, 1126, 1734, 608, 573, 1025, 1049, - /* 1810 */ 574, 611, 261, 1047, 1067, 1734, 1764, 573, 1795, 1046, - /* 1820 */ 1045, 1044, 292, 1765, 576, 1767, 1768, 572, 1764, 567, - /* 1830 */ 1043, 1042, 1795, 1041, 1040, 1064, 292, 1765, 576, 1767, - /* 1840 */ 1768, 572, 1795, 567, 1782, 1062, 277, 1765, 576, 1767, - /* 1850 */ 1768, 572, 574, 567, 1037, 1036, 1782, 1734, 1035, 573, - /* 1860 */ 1032, 1031, 1030, 1506, 574, 632, 1504, 634, 633, 1734, - /* 1870 */ 1764, 573, 636, 638, 1502, 640, 1500, 642, 637, 641, - /* 1880 */ 1764, 644, 645, 646, 1795, 1488, 648, 989, 278, 1765, - /* 1890 */ 576, 1767, 1768, 572, 1764, 567, 1795, 1470, 1782, 264, - /* 1900 */ 279, 1765, 576, 1767, 1768, 572, 574, 567, 1782, 652, - /* 1910 */ 655, 1734, 1246, 573, 272, 1445, 574, 1445, 656, 1445, - /* 1920 */ 1445, 1734, 1782, 573, 1445, 1445, 1445, 1445, 1445, 1445, - /* 1930 */ 574, 1445, 1445, 1445, 1445, 1734, 1764, 573, 1795, 1445, - /* 1940 */ 1445, 1445, 286, 1765, 576, 1767, 1768, 572, 1795, 567, - /* 1950 */ 1764, 1445, 288, 1765, 576, 1767, 1768, 572, 1445, 567, - /* 1960 */ 1764, 1445, 1795, 1445, 1782, 1445, 280, 1765, 576, 1767, - /* 1970 */ 1768, 572, 574, 567, 1445, 1445, 1445, 1734, 1782, 573, - /* 1980 */ 1445, 1445, 1445, 1445, 1445, 1445, 574, 1445, 1782, 1445, - /* 1990 */ 1445, 1734, 1445, 573, 1445, 1445, 574, 1445, 1445, 1445, - /* 2000 */ 1445, 1734, 1445, 573, 1795, 1445, 1445, 1445, 289, 1765, - /* 2010 */ 576, 1767, 1768, 572, 1445, 567, 1445, 1445, 1795, 1445, - /* 2020 */ 1764, 1445, 281, 1765, 576, 1767, 1768, 572, 1795, 567, - /* 2030 */ 1764, 1445, 290, 1765, 576, 1767, 1768, 572, 1445, 567, - /* 2040 */ 1445, 1445, 1764, 1445, 1445, 1445, 1445, 1445, 1782, 1445, - /* 2050 */ 1445, 1445, 1445, 1445, 1445, 1445, 574, 1445, 1782, 1445, - /* 2060 */ 1445, 1734, 1445, 573, 1445, 1445, 574, 1445, 1445, 1445, - /* 2070 */ 1782, 1734, 1445, 573, 1445, 1445, 1445, 1445, 574, 1445, - /* 2080 */ 1445, 1445, 1445, 1734, 1764, 573, 1445, 1445, 1795, 1445, - /* 2090 */ 1445, 1445, 282, 1765, 576, 1767, 1768, 572, 1795, 567, - /* 2100 */ 1764, 1445, 295, 1765, 576, 1767, 1768, 572, 1445, 567, - /* 2110 */ 1795, 1445, 1782, 1445, 296, 1765, 576, 1767, 1768, 572, - /* 2120 */ 574, 567, 1445, 1445, 1445, 1734, 1764, 573, 1782, 1445, - /* 2130 */ 1445, 1445, 1445, 1445, 1445, 1445, 574, 1445, 1445, 1445, - /* 2140 */ 1445, 1734, 1445, 573, 1445, 1445, 1445, 1445, 1445, 1445, - /* 2150 */ 1764, 1445, 1795, 1445, 1782, 1445, 1776, 1765, 576, 1767, - /* 2160 */ 1768, 572, 574, 567, 1445, 1445, 1445, 1734, 1795, 573, - /* 2170 */ 1445, 1445, 1775, 1765, 576, 1767, 1768, 572, 1782, 567, - /* 2180 */ 1445, 1445, 1445, 1445, 1445, 1445, 574, 1445, 1445, 1445, - /* 2190 */ 1445, 1734, 1764, 573, 1795, 1445, 1445, 1445, 1774, 1765, - /* 2200 */ 576, 1767, 1768, 572, 1764, 567, 1445, 1445, 1445, 1445, - /* 2210 */ 1445, 1445, 1445, 1445, 1445, 1445, 1764, 1445, 1795, 1445, - /* 2220 */ 1782, 1445, 307, 1765, 576, 1767, 1768, 572, 574, 567, - /* 2230 */ 1445, 1445, 1782, 1734, 1445, 573, 1445, 1445, 1445, 1445, - /* 2240 */ 574, 1445, 1445, 1445, 1782, 1734, 1445, 573, 1445, 1445, - /* 2250 */ 1445, 1445, 574, 1445, 1445, 1445, 1445, 1734, 1445, 573, - /* 2260 */ 1795, 1445, 1445, 1445, 306, 1765, 576, 1767, 1768, 572, - /* 2270 */ 1445, 567, 1795, 1445, 1764, 1445, 308, 1765, 576, 1767, - /* 2280 */ 1768, 572, 1445, 567, 1795, 1445, 1445, 1445, 305, 1765, - /* 2290 */ 576, 1767, 1768, 572, 1445, 567, 1445, 1445, 1445, 1445, - /* 2300 */ 1445, 1445, 1782, 1445, 1445, 1445, 1445, 1445, 1445, 1445, - /* 2310 */ 574, 1445, 1445, 1445, 1445, 1734, 1445, 573, 1445, 1445, - /* 2320 */ 1445, 1445, 1445, 1445, 1445, 1445, 1445, 1445, 1445, 1445, - /* 2330 */ 1445, 1445, 1445, 1445, 1445, 1445, 1445, 1445, 1445, 1445, - /* 2340 */ 1445, 1445, 1795, 1445, 1445, 1445, 285, 1765, 576, 1767, - /* 2350 */ 1768, 572, 1445, 567, + /* 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 */ 312, 353, 259, 312, 261, 262, 259, 294, 261, 262, - /* 10 */ 297, 298, 12, 13, 366, 283, 252, 267, 370, 265, - /* 20 */ 20, 0, 22, 0, 292, 12, 13, 14, 15, 16, - /* 30 */ 280, 4, 263, 33, 255, 35, 4, 338, 339, 289, - /* 40 */ 286, 353, 21, 274, 353, 24, 25, 26, 27, 28, - /* 50 */ 29, 30, 31, 32, 366, 263, 56, 366, 370, 59, - /* 60 */ 291, 370, 283, 20, 20, 65, 283, 254, 20, 256, - /* 70 */ 291, 44, 45, 275, 291, 296, 312, 298, 12, 13, - /* 80 */ 14, 283, 82, 291, 61, 62, 20, 283, 22, 66, - /* 90 */ 292, 312, 69, 70, 290, 58, 73, 74, 75, 33, - /* 100 */ 255, 35, 323, 299, 104, 255, 327, 328, 329, 330, - /* 110 */ 331, 332, 329, 334, 82, 82, 337, 353, 118, 119, - /* 120 */ 341, 342, 56, 331, 43, 59, 82, 275, 283, 268, - /* 130 */ 366, 65, 353, 272, 370, 283, 291, 345, 346, 347, - /* 140 */ 348, 296, 350, 298, 292, 366, 296, 21, 82, 370, - /* 150 */ 24, 25, 26, 27, 28, 29, 30, 31, 32, 260, - /* 160 */ 113, 114, 263, 163, 83, 165, 118, 119, 323, 312, - /* 170 */ 104, 0, 327, 328, 329, 330, 331, 332, 20, 334, - /* 180 */ 260, 298, 337, 263, 118, 119, 341, 342, 0, 306, - /* 190 */ 190, 191, 309, 193, 194, 195, 196, 197, 198, 199, + /* 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 */ 353, 148, 24, 25, 26, 27, 28, 29, 30, 31, - /* 220 */ 32, 174, 222, 366, 177, 56, 308, 370, 310, 163, - /* 230 */ 267, 165, 61, 62, 63, 64, 20, 66, 67, 68, - /* 240 */ 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, - /* 250 */ 79, 82, 289, 84, 222, 222, 190, 191, 82, 193, - /* 260 */ 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, - /* 270 */ 204, 205, 206, 207, 208, 209, 12, 13, 43, 275, - /* 280 */ 61, 62, 263, 190, 20, 66, 22, 283, 69, 70, - /* 290 */ 227, 228, 73, 74, 75, 312, 292, 33, 82, 35, - /* 300 */ 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, - /* 310 */ 105, 20, 107, 108, 109, 110, 111, 112, 353, 300, - /* 320 */ 56, 285, 4, 59, 231, 232, 233, 234, 235, 65, - /* 330 */ 255, 366, 296, 12, 13, 370, 353, 19, 162, 263, - /* 340 */ 164, 20, 265, 22, 255, 283, 82, 114, 35, 366, - /* 350 */ 274, 33, 290, 370, 33, 278, 35, 281, 322, 323, - /* 360 */ 324, 299, 20, 286, 255, 47, 22, 291, 104, 51, - /* 370 */ 334, 296, 283, 263, 56, 353, 0, 56, 65, 35, - /* 380 */ 291, 20, 118, 119, 274, 296, 65, 298, 366, 8, - /* 390 */ 9, 222, 370, 12, 13, 14, 15, 16, 222, 81, - /* 400 */ 263, 291, 84, 82, 285, 296, 173, 174, 14, 65, - /* 410 */ 177, 274, 323, 158, 20, 296, 327, 328, 329, 330, - /* 420 */ 331, 332, 263, 334, 282, 104, 337, 163, 291, 165, - /* 430 */ 341, 342, 343, 274, 58, 180, 181, 295, 222, 118, - /* 440 */ 119, 322, 323, 113, 355, 297, 298, 20, 104, 22, - /* 450 */ 291, 58, 363, 334, 190, 191, 0, 193, 194, 195, - /* 460 */ 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, - /* 470 */ 206, 207, 208, 209, 8, 9, 241, 50, 12, 13, - /* 480 */ 14, 15, 16, 20, 163, 22, 165, 8, 9, 0, - /* 490 */ 2, 12, 13, 14, 15, 16, 8, 9, 35, 291, - /* 500 */ 12, 13, 14, 15, 16, 175, 176, 163, 59, 165, - /* 510 */ 302, 190, 191, 50, 193, 194, 195, 196, 197, 198, - /* 520 */ 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, - /* 530 */ 209, 12, 13, 14, 190, 191, 155, 269, 270, 20, - /* 540 */ 76, 22, 255, 222, 284, 263, 33, 58, 263, 83, - /* 550 */ 325, 14, 33, 263, 35, 37, 274, 20, 20, 274, - /* 560 */ 47, 298, 83, 263, 274, 52, 53, 54, 55, 56, - /* 570 */ 283, 281, 309, 291, 349, 56, 291, 145, 291, 263, - /* 580 */ 308, 291, 310, 296, 65, 298, 122, 123, 12, 13, - /* 590 */ 274, 291, 269, 270, 81, 43, 20, 84, 22, 312, - /* 600 */ 168, 82, 263, 85, 94, 87, 88, 291, 90, 33, - /* 610 */ 323, 35, 94, 274, 327, 328, 329, 330, 331, 332, - /* 620 */ 271, 334, 273, 104, 337, 244, 116, 56, 341, 342, - /* 630 */ 291, 331, 56, 263, 116, 83, 21, 118, 119, 190, - /* 640 */ 353, 65, 210, 4, 274, 255, 346, 347, 348, 34, - /* 650 */ 350, 36, 81, 366, 285, 84, 65, 370, 82, 146, - /* 660 */ 147, 291, 149, 1, 2, 296, 153, 8, 9, 44, - /* 670 */ 45, 12, 13, 14, 15, 16, 263, 39, 94, 263, - /* 680 */ 104, 14, 163, 3, 165, 172, 296, 20, 150, 93, - /* 690 */ 274, 322, 323, 293, 118, 119, 296, 113, 114, 115, - /* 700 */ 116, 117, 43, 334, 291, 255, 255, 291, 325, 190, - /* 710 */ 191, 20, 193, 194, 195, 196, 197, 198, 199, 200, - /* 720 */ 201, 202, 203, 204, 205, 206, 207, 208, 209, 8, - /* 730 */ 9, 194, 349, 12, 13, 14, 15, 16, 35, 163, - /* 740 */ 325, 165, 2, 20, 331, 83, 296, 296, 8, 9, - /* 750 */ 255, 65, 12, 13, 14, 15, 16, 255, 255, 346, - /* 760 */ 347, 348, 293, 350, 349, 296, 190, 191, 65, 193, - /* 770 */ 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, - /* 780 */ 204, 205, 206, 207, 208, 209, 12, 13, 18, 0, - /* 790 */ 20, 296, 19, 284, 20, 255, 22, 27, 296, 296, - /* 800 */ 30, 14, 15, 16, 83, 263, 33, 33, 255, 35, - /* 810 */ 276, 22, 255, 279, 220, 221, 274, 47, 0, 49, - /* 820 */ 47, 51, 56, 283, 263, 52, 53, 54, 55, 56, - /* 830 */ 56, 291, 263, 291, 255, 274, 296, 316, 298, 65, - /* 840 */ 8, 9, 283, 274, 12, 13, 14, 15, 16, 296, - /* 850 */ 84, 81, 291, 296, 81, 263, 82, 84, 299, 221, - /* 860 */ 291, 194, 223, 323, 42, 43, 274, 327, 328, 329, - /* 870 */ 330, 331, 332, 150, 334, 296, 0, 337, 104, 255, - /* 880 */ 43, 341, 342, 291, 255, 194, 255, 255, 255, 255, - /* 890 */ 117, 121, 118, 119, 124, 125, 126, 127, 128, 129, - /* 900 */ 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - /* 910 */ 140, 141, 94, 143, 144, 255, 272, 150, 151, 239, - /* 920 */ 296, 18, 149, 47, 35, 296, 23, 296, 296, 296, - /* 930 */ 296, 113, 114, 115, 116, 117, 0, 163, 263, 165, - /* 940 */ 37, 38, 0, 170, 41, 172, 8, 9, 35, 274, - /* 950 */ 12, 13, 14, 15, 16, 284, 296, 284, 263, 86, - /* 960 */ 57, 284, 89, 43, 190, 191, 291, 193, 194, 195, - /* 970 */ 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, - /* 980 */ 206, 207, 208, 209, 0, 82, 291, 8, 9, 263, - /* 990 */ 48, 12, 13, 14, 15, 16, 86, 59, 86, 89, - /* 1000 */ 274, 89, 0, 83, 8, 9, 22, 312, 12, 13, - /* 1010 */ 14, 15, 16, 86, 284, 43, 89, 291, 1, 2, - /* 1020 */ 46, 83, 82, 120, 22, 284, 331, 256, 43, 91, - /* 1030 */ 94, 43, 92, 43, 373, 43, 255, 319, 59, 118, - /* 1040 */ 119, 346, 347, 348, 43, 350, 43, 364, 353, 113, - /* 1050 */ 114, 115, 116, 117, 165, 83, 82, 43, 155, 156, - /* 1060 */ 157, 366, 43, 160, 283, 370, 264, 43, 83, 166, - /* 1070 */ 91, 83, 291, 83, 360, 83, 283, 296, 165, 298, - /* 1080 */ 243, 264, 179, 145, 83, 182, 83, 184, 185, 186, - /* 1090 */ 187, 188, 189, 43, 43, 255, 262, 83, 295, 43, - /* 1100 */ 351, 326, 83, 344, 323, 367, 168, 83, 327, 328, - /* 1110 */ 329, 330, 331, 332, 333, 334, 335, 336, 367, 367, - /* 1120 */ 82, 224, 354, 283, 145, 222, 287, 321, 20, 263, - /* 1130 */ 47, 291, 320, 83, 83, 35, 296, 255, 298, 83, - /* 1140 */ 269, 161, 314, 263, 263, 42, 150, 168, 210, 211, - /* 1150 */ 212, 213, 214, 215, 216, 217, 218, 219, 303, 301, - /* 1160 */ 145, 301, 263, 323, 20, 283, 257, 327, 328, 329, - /* 1170 */ 330, 331, 332, 291, 334, 257, 20, 337, 296, 318, - /* 1180 */ 298, 341, 342, 343, 267, 298, 267, 20, 311, 210, - /* 1190 */ 211, 212, 213, 214, 215, 216, 217, 218, 219, 20, - /* 1200 */ 255, 313, 267, 363, 311, 323, 267, 20, 304, 327, - /* 1210 */ 328, 329, 330, 331, 332, 267, 334, 267, 263, 337, - /* 1220 */ 267, 257, 257, 263, 342, 296, 255, 283, 283, 283, - /* 1230 */ 283, 265, 283, 318, 283, 283, 291, 283, 171, 283, - /* 1240 */ 283, 296, 283, 298, 283, 317, 265, 265, 311, 263, - /* 1250 */ 263, 229, 147, 20, 283, 230, 298, 279, 296, 265, - /* 1260 */ 265, 359, 291, 296, 296, 296, 296, 296, 323, 298, - /* 1270 */ 307, 296, 327, 328, 329, 330, 331, 332, 236, 334, - /* 1280 */ 307, 305, 337, 359, 291, 362, 341, 342, 343, 291, - /* 1290 */ 154, 361, 359, 304, 323, 296, 296, 352, 327, 328, - /* 1300 */ 329, 330, 331, 332, 307, 334, 296, 296, 337, 326, - /* 1310 */ 238, 307, 341, 342, 343, 255, 12, 13, 237, 225, - /* 1320 */ 221, 291, 20, 352, 242, 240, 22, 321, 82, 245, - /* 1330 */ 287, 296, 325, 263, 273, 358, 263, 33, 258, 35, - /* 1340 */ 265, 36, 315, 283, 257, 277, 310, 0, 357, 253, - /* 1350 */ 173, 291, 266, 277, 277, 0, 296, 0, 298, 42, - /* 1360 */ 56, 356, 0, 340, 291, 73, 0, 35, 183, 65, - /* 1370 */ 35, 35, 35, 0, 183, 35, 35, 369, 369, 183, - /* 1380 */ 368, 255, 369, 323, 368, 312, 368, 327, 328, 329, - /* 1390 */ 330, 331, 332, 0, 334, 374, 183, 337, 0, 35, - /* 1400 */ 0, 341, 342, 343, 331, 22, 0, 35, 104, 283, - /* 1410 */ 0, 82, 352, 168, 167, 165, 163, 291, 0, 346, - /* 1420 */ 347, 348, 296, 350, 298, 159, 353, 0, 158, 0, - /* 1430 */ 0, 46, 0, 0, 0, 142, 0, 0, 312, 366, - /* 1440 */ 0, 0, 0, 370, 137, 255, 35, 0, 137, 323, - /* 1450 */ 0, 0, 0, 327, 328, 329, 330, 331, 332, 0, - /* 1460 */ 334, 0, 0, 0, 0, 0, 0, 163, 0, 165, - /* 1470 */ 0, 0, 0, 283, 0, 0, 0, 42, 0, 353, - /* 1480 */ 0, 291, 0, 0, 0, 0, 296, 0, 298, 22, - /* 1490 */ 0, 0, 366, 39, 190, 42, 370, 255, 43, 0, - /* 1500 */ 14, 0, 312, 46, 46, 201, 202, 203, 204, 205, - /* 1510 */ 206, 207, 14, 323, 0, 0, 39, 327, 328, 329, - /* 1520 */ 330, 331, 332, 154, 334, 283, 0, 0, 40, 0, - /* 1530 */ 0, 39, 0, 291, 0, 35, 47, 0, 296, 60, - /* 1540 */ 298, 39, 35, 353, 47, 39, 35, 39, 0, 0, - /* 1550 */ 255, 47, 35, 0, 0, 39, 366, 47, 0, 35, - /* 1560 */ 370, 22, 89, 0, 255, 323, 35, 0, 35, 327, - /* 1570 */ 328, 329, 330, 331, 332, 35, 334, 35, 283, 43, - /* 1580 */ 35, 43, 35, 288, 91, 35, 291, 22, 0, 0, - /* 1590 */ 22, 296, 283, 298, 22, 49, 0, 288, 0, 35, - /* 1600 */ 291, 35, 0, 22, 35, 296, 20, 298, 0, 35, - /* 1610 */ 150, 0, 169, 371, 372, 22, 255, 0, 323, 150, - /* 1620 */ 0, 0, 327, 328, 329, 330, 331, 332, 147, 334, - /* 1630 */ 0, 0, 323, 82, 178, 83, 327, 328, 329, 330, - /* 1640 */ 331, 332, 0, 334, 283, 0, 150, 92, 39, 46, - /* 1650 */ 43, 146, 291, 82, 226, 152, 22, 296, 82, 298, - /* 1660 */ 148, 82, 82, 2, 46, 83, 82, 82, 255, 43, - /* 1670 */ 83, 43, 43, 83, 83, 83, 82, 82, 46, 82, - /* 1680 */ 255, 82, 46, 83, 323, 35, 43, 83, 327, 328, - /* 1690 */ 329, 330, 331, 332, 255, 334, 283, 46, 46, 83, - /* 1700 */ 43, 35, 83, 35, 291, 35, 35, 35, 283, 296, - /* 1710 */ 43, 298, 190, 288, 22, 82, 291, 192, 83, 82, - /* 1720 */ 226, 296, 283, 298, 83, 46, 365, 83, 82, 82, - /* 1730 */ 291, 82, 46, 220, 35, 296, 323, 298, 82, 35, - /* 1740 */ 327, 328, 329, 330, 331, 332, 226, 334, 323, 35, - /* 1750 */ 255, 93, 327, 328, 329, 330, 331, 332, 83, 334, - /* 1760 */ 82, 35, 323, 83, 255, 82, 327, 328, 329, 330, - /* 1770 */ 331, 332, 83, 334, 255, 336, 82, 35, 283, 83, - /* 1780 */ 82, 35, 82, 288, 83, 372, 291, 94, 106, 22, - /* 1790 */ 106, 296, 283, 298, 106, 82, 106, 288, 82, 35, - /* 1800 */ 291, 82, 283, 43, 22, 296, 59, 298, 60, 35, - /* 1810 */ 291, 80, 43, 35, 65, 296, 255, 298, 323, 35, - /* 1820 */ 35, 35, 327, 328, 329, 330, 331, 332, 255, 334, - /* 1830 */ 35, 22, 323, 35, 35, 65, 327, 328, 329, 330, - /* 1840 */ 331, 332, 323, 334, 283, 35, 327, 328, 329, 330, - /* 1850 */ 331, 332, 291, 334, 35, 35, 283, 296, 35, 298, - /* 1860 */ 35, 35, 35, 0, 291, 35, 0, 39, 47, 296, - /* 1870 */ 255, 298, 35, 39, 0, 35, 0, 39, 47, 47, - /* 1880 */ 255, 35, 47, 39, 323, 0, 35, 35, 327, 328, - /* 1890 */ 329, 330, 331, 332, 255, 334, 323, 0, 283, 22, - /* 1900 */ 327, 328, 329, 330, 331, 332, 291, 334, 283, 21, - /* 1910 */ 21, 296, 22, 298, 22, 375, 291, 375, 20, 375, - /* 1920 */ 375, 296, 283, 298, 375, 375, 375, 375, 375, 375, - /* 1930 */ 291, 375, 375, 375, 375, 296, 255, 298, 323, 375, - /* 1940 */ 375, 375, 327, 328, 329, 330, 331, 332, 323, 334, - /* 1950 */ 255, 375, 327, 328, 329, 330, 331, 332, 375, 334, - /* 1960 */ 255, 375, 323, 375, 283, 375, 327, 328, 329, 330, - /* 1970 */ 331, 332, 291, 334, 375, 375, 375, 296, 283, 298, - /* 1980 */ 375, 375, 375, 375, 375, 375, 291, 375, 283, 375, - /* 1990 */ 375, 296, 375, 298, 375, 375, 291, 375, 375, 375, - /* 2000 */ 375, 296, 375, 298, 323, 375, 375, 375, 327, 328, - /* 2010 */ 329, 330, 331, 332, 375, 334, 375, 375, 323, 375, - /* 2020 */ 255, 375, 327, 328, 329, 330, 331, 332, 323, 334, - /* 2030 */ 255, 375, 327, 328, 329, 330, 331, 332, 375, 334, - /* 2040 */ 375, 375, 255, 375, 375, 375, 375, 375, 283, 375, - /* 2050 */ 375, 375, 375, 375, 375, 375, 291, 375, 283, 375, - /* 2060 */ 375, 296, 375, 298, 375, 375, 291, 375, 375, 375, - /* 2070 */ 283, 296, 375, 298, 375, 375, 375, 375, 291, 375, - /* 2080 */ 375, 375, 375, 296, 255, 298, 375, 375, 323, 375, - /* 2090 */ 375, 375, 327, 328, 329, 330, 331, 332, 323, 334, - /* 2100 */ 255, 375, 327, 328, 329, 330, 331, 332, 375, 334, - /* 2110 */ 323, 375, 283, 375, 327, 328, 329, 330, 331, 332, - /* 2120 */ 291, 334, 375, 375, 375, 296, 255, 298, 283, 375, - /* 2130 */ 375, 375, 375, 375, 375, 375, 291, 375, 375, 375, - /* 2140 */ 375, 296, 375, 298, 375, 375, 375, 375, 375, 375, - /* 2150 */ 255, 375, 323, 375, 283, 375, 327, 328, 329, 330, - /* 2160 */ 331, 332, 291, 334, 375, 375, 375, 296, 323, 298, - /* 2170 */ 375, 375, 327, 328, 329, 330, 331, 332, 283, 334, - /* 2180 */ 375, 375, 375, 375, 375, 375, 291, 375, 375, 375, - /* 2190 */ 375, 296, 255, 298, 323, 375, 375, 375, 327, 328, - /* 2200 */ 329, 330, 331, 332, 255, 334, 375, 375, 375, 375, - /* 2210 */ 375, 375, 375, 375, 375, 375, 255, 375, 323, 375, - /* 2220 */ 283, 375, 327, 328, 329, 330, 331, 332, 291, 334, - /* 2230 */ 375, 375, 283, 296, 375, 298, 375, 375, 375, 375, - /* 2240 */ 291, 375, 375, 375, 283, 296, 375, 298, 375, 375, - /* 2250 */ 375, 375, 291, 375, 375, 375, 375, 296, 375, 298, - /* 2260 */ 323, 375, 375, 375, 327, 328, 329, 330, 331, 332, - /* 2270 */ 375, 334, 323, 375, 255, 375, 327, 328, 329, 330, - /* 2280 */ 331, 332, 375, 334, 323, 375, 375, 375, 327, 328, - /* 2290 */ 329, 330, 331, 332, 375, 334, 375, 375, 375, 375, - /* 2300 */ 375, 375, 283, 375, 375, 375, 375, 375, 375, 375, - /* 2310 */ 291, 375, 375, 375, 375, 296, 375, 298, 375, 375, - /* 2320 */ 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, - /* 2330 */ 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, - /* 2340 */ 375, 375, 323, 375, 375, 375, 327, 328, 329, 330, - /* 2350 */ 331, 332, 375, 334, + /* 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 (657) +#define YY_SHIFT_COUNT (660) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1898) +#define YY_SHIFT_MAX (1960) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 903, 0, 0, 66, 66, 264, 264, 264, 321, 321, - /* 10 */ 264, 264, 519, 576, 774, 576, 576, 576, 576, 576, - /* 20 */ 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, - /* 30 */ 576, 576, 576, 576, 576, 576, 576, 576, 576, 576, - /* 40 */ 576, 576, 576, 216, 216, 44, 44, 44, 1304, 1304, - /* 50 */ 1304, 176, 169, 33, 33, 43, 43, 27, 27, 32, - /* 60 */ 48, 33, 33, 43, 43, 43, 43, 43, 43, 43, - /* 70 */ 43, 43, 37, 43, 43, 43, 158, 291, 43, 43, - /* 80 */ 291, 342, 43, 291, 291, 291, 43, 393, 770, 938, - /* 90 */ 979, 979, 126, 219, 344, 344, 344, 344, 344, 344, - /* 100 */ 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, - /* 110 */ 344, 344, 344, 518, 48, 394, 394, 376, 313, 489, - /* 120 */ 538, 538, 538, 313, 361, 158, 456, 456, 291, 291, - /* 130 */ 591, 591, 596, 686, 205, 205, 205, 205, 205, 205, - /* 140 */ 205, 773, 21, 23, 381, 93, 463, 233, 63, 537, - /* 150 */ 667, 427, 625, 510, 723, 594, 638, 594, 822, 680, - /* 160 */ 680, 680, 639, 691, 1038, 897, 1108, 1083, 1100, 980, - /* 170 */ 1108, 1108, 1103, 1015, 1015, 1108, 1144, 1144, 1156, 37, - /* 180 */ 158, 37, 1167, 1179, 37, 1167, 37, 1187, 37, 37, - /* 190 */ 1108, 37, 1144, 291, 291, 291, 291, 291, 291, 291, - /* 200 */ 291, 291, 291, 291, 1108, 1144, 591, 1156, 393, 1067, - /* 210 */ 158, 393, 1108, 1108, 1167, 393, 1022, 591, 591, 591, - /* 220 */ 591, 1022, 591, 1105, 361, 1187, 393, 596, 393, 361, - /* 230 */ 1233, 591, 1025, 1022, 591, 591, 1025, 1022, 591, 591, - /* 240 */ 291, 1042, 1136, 1025, 1072, 1081, 1094, 897, 1099, 361, - /* 250 */ 1302, 1082, 1085, 1084, 1082, 1085, 1082, 1085, 1246, 1038, - /* 260 */ 591, 686, 1108, 393, 1305, 1144, 2354, 2354, 2354, 2354, - /* 270 */ 2354, 2354, 2354, 171, 513, 188, 318, 466, 659, 479, - /* 280 */ 488, 740, 996, 721, 818, 832, 832, 832, 832, 832, - /* 290 */ 832, 832, 832, 936, 584, 13, 13, 47, 255, 571, - /* 300 */ 464, 615, 330, 662, 432, 787, 787, 787, 787, 876, - /* 310 */ 81, 873, 910, 912, 927, 789, 984, 1002, 766, 767, - /* 320 */ 552, 920, 972, 985, 988, 990, 889, 913, 992, 1017, - /* 330 */ 921, 235, 837, 1001, 449, 1003, 974, 1014, 1019, 1024, - /* 340 */ 1050, 1051, 1056, 940, 703, 942, 1347, 1177, 1355, 1357, - /* 350 */ 1317, 1362, 1292, 1366, 1332, 1185, 1335, 1336, 1337, 1191, - /* 360 */ 1373, 1340, 1341, 1196, 1393, 1213, 1398, 1364, 1400, 1383, - /* 370 */ 1406, 1372, 1410, 1329, 1245, 1247, 1250, 1253, 1418, 1427, - /* 380 */ 1266, 1270, 1429, 1430, 1385, 1432, 1433, 1434, 1293, 1436, - /* 390 */ 1437, 1440, 1441, 1442, 1307, 1411, 1447, 1311, 1450, 1451, - /* 400 */ 1452, 1459, 1461, 1462, 1463, 1464, 1465, 1466, 1468, 1470, - /* 410 */ 1471, 1472, 1435, 1474, 1475, 1476, 1478, 1480, 1482, 1467, - /* 420 */ 1483, 1484, 1485, 1487, 1490, 1491, 1453, 1454, 1455, 1486, - /* 430 */ 1457, 1498, 1458, 1499, 1488, 1477, 1501, 1514, 1515, 1492, - /* 440 */ 1369, 1526, 1527, 1529, 1479, 1530, 1532, 1500, 1489, 1502, - /* 450 */ 1534, 1507, 1497, 1506, 1537, 1511, 1504, 1508, 1548, 1517, - /* 460 */ 1510, 1516, 1549, 1553, 1554, 1558, 1493, 1473, 1524, 1539, - /* 470 */ 1563, 1531, 1533, 1540, 1542, 1536, 1538, 1545, 1547, 1550, - /* 480 */ 1567, 1565, 1588, 1568, 1546, 1589, 1572, 1564, 1596, 1566, - /* 490 */ 1598, 1569, 1602, 1581, 1586, 1608, 1460, 1574, 1611, 1443, - /* 500 */ 1593, 1469, 1481, 1617, 1620, 1496, 1503, 1621, 1630, 1631, - /* 510 */ 1551, 1552, 1456, 1642, 1571, 1512, 1576, 1645, 1609, 1505, - /* 520 */ 1579, 1555, 1603, 1607, 1428, 1580, 1582, 1584, 1587, 1590, - /* 530 */ 1585, 1634, 1626, 1591, 1594, 1595, 1597, 1592, 1628, 1618, - /* 540 */ 1632, 1599, 1629, 1494, 1600, 1604, 1636, 1513, 1643, 1651, - /* 550 */ 1652, 1616, 1657, 1520, 1619, 1650, 1666, 1668, 1670, 1671, - /* 560 */ 1672, 1619, 1661, 1522, 1667, 1633, 1635, 1637, 1641, 1646, - /* 570 */ 1644, 1679, 1647, 1649, 1686, 1692, 1525, 1656, 1658, 1675, - /* 580 */ 1699, 1704, 1678, 1680, 1714, 1683, 1689, 1726, 1694, 1696, - /* 590 */ 1742, 1698, 1701, 1746, 1700, 1682, 1684, 1688, 1690, 1767, - /* 600 */ 1693, 1713, 1716, 1764, 1719, 1760, 1760, 1782, 1748, 1747, - /* 610 */ 1774, 1749, 1731, 1769, 1778, 1784, 1785, 1786, 1795, 1809, - /* 620 */ 1798, 1799, 1770, 1536, 1810, 1538, 1819, 1820, 1823, 1825, - /* 630 */ 1826, 1827, 1863, 1830, 1821, 1828, 1866, 1837, 1831, 1834, - /* 640 */ 1874, 1840, 1832, 1838, 1876, 1846, 1835, 1844, 1885, 1851, - /* 650 */ 1852, 1897, 1877, 1888, 1890, 1892, 1889, 1898, + /* 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 (272) -#define YY_REDUCE_MIN (-352) -#define YY_REDUCE_MAX (2019) +#define YY_REDUCE_COUNT (273) +#define YY_REDUCE_MIN (-295) +#define YY_REDUCE_MAX (2027) static const short yy_reduce_ofst[] = { - /* 0 */ -236, -221, 287, 89, 840, 945, 971, 1060, 1126, 1190, - /* 10 */ -155, 540, 781, 1242, 882, 1295, 1309, 1361, 1413, 1425, - /* 20 */ 1439, 1495, 1509, 1519, 1561, 1573, 1615, 1625, 1639, 1681, - /* 30 */ 1695, 1705, 1765, 1775, 1787, 1829, 1845, 1871, 1895, 1937, - /* 40 */ 1949, 1961, 2019, 695, 1073, -208, 300, 413, 36, 119, - /* 50 */ 369, -312, -309, -143, -17, 76, 290, -257, -253, -352, - /* 60 */ -287, -35, 22, -231, 110, 137, 159, 282, 285, 316, - /* 70 */ 339, 370, -250, 416, 542, 561, -117, -202, 569, 592, - /* 80 */ -196, -217, 675, -148, 62, 4, 726, 77, 19, -301, - /* 90 */ -301, -301, -187, -139, -150, 75, 109, 390, 450, 451, - /* 100 */ 495, 502, 503, 553, 557, 579, 624, 629, 631, 632, - /* 110 */ 633, 634, 660, 142, 148, -101, -80, -37, 268, -246, - /* 120 */ 225, 383, 415, 323, 208, 263, -82, 272, -268, 559, - /* 130 */ 400, 469, 534, 349, 260, 509, 671, 673, 677, 730, - /* 140 */ 741, 521, 771, 644, 661, 683, 802, 718, 714, 793, - /* 150 */ 793, 817, 834, 803, 775, 749, 749, 749, 759, 738, - /* 160 */ 751, 752, 768, 793, 839, 806, 866, 812, 871, 828, - /* 170 */ 880, 881, 855, 858, 860, 899, 909, 918, 861, 917, - /* 180 */ 887, 919, 877, 888, 935, 893, 939, 904, 948, 950, - /* 190 */ 955, 953, 964, 944, 946, 947, 949, 951, 952, 954, - /* 200 */ 956, 957, 959, 961, 960, 965, 929, 915, 966, 928, - /* 210 */ 958, 981, 986, 987, 937, 982, 963, 962, 967, 968, - /* 220 */ 969, 973, 970, 976, 993, 989, 994, 978, 995, 998, - /* 230 */ 983, 975, 902, 997, 999, 1000, 924, 1004, 1010, 1011, - /* 240 */ 793, 923, 930, 933, 977, 991, 1005, 1006, 749, 1030, - /* 250 */ 1007, 1008, 1012, 1021, 1009, 1016, 1013, 1018, 1023, 1043, - /* 260 */ 1035, 1061, 1070, 1075, 1080, 1087, 1027, 1036, 1068, 1076, - /* 270 */ 1077, 1086, 1096, + /* 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 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 10 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 20 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 30 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 40 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 50 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 60 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 70 */ 1443, 1443, 1515, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 80 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1513, 1666, 1443, - /* 90 */ 1843, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 100 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 110 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1515, 1443, 1513, - /* 120 */ 1855, 1855, 1855, 1443, 1443, 1443, 1710, 1710, 1443, 1443, - /* 130 */ 1443, 1443, 1609, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 140 */ 1443, 1702, 1443, 1443, 1924, 1443, 1443, 1708, 1878, 1443, - /* 150 */ 1443, 1443, 1443, 1562, 1870, 1847, 1861, 1848, 1845, 1909, - /* 160 */ 1909, 1909, 1864, 1443, 1578, 1874, 1443, 1443, 1443, 1694, - /* 170 */ 1443, 1443, 1671, 1668, 1668, 1443, 1443, 1443, 1443, 1515, - /* 180 */ 1443, 1515, 1443, 1443, 1515, 1443, 1515, 1443, 1515, 1515, - /* 190 */ 1443, 1515, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 200 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1513, 1704, - /* 210 */ 1443, 1513, 1443, 1443, 1443, 1513, 1883, 1443, 1443, 1443, - /* 220 */ 1443, 1883, 1443, 1443, 1443, 1443, 1513, 1443, 1513, 1443, - /* 230 */ 1443, 1443, 1885, 1883, 1443, 1443, 1885, 1883, 1443, 1443, - /* 240 */ 1443, 1897, 1893, 1885, 1901, 1899, 1876, 1874, 1861, 1443, - /* 250 */ 1443, 1915, 1911, 1927, 1915, 1911, 1915, 1911, 1443, 1578, - /* 260 */ 1443, 1443, 1443, 1513, 1475, 1443, 1696, 1710, 1612, 1612, - /* 270 */ 1612, 1516, 1448, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 280 */ 1443, 1443, 1443, 1443, 1443, 1781, 1896, 1895, 1819, 1818, - /* 290 */ 1817, 1815, 1780, 1443, 1574, 1779, 1778, 1443, 1443, 1443, - /* 300 */ 1443, 1443, 1443, 1443, 1443, 1772, 1773, 1771, 1770, 1443, - /* 310 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 320 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1844, - /* 330 */ 1443, 1912, 1916, 1443, 1443, 1443, 1755, 1443, 1443, 1443, - /* 340 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 350 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 360 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 370 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 380 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 390 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 400 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 410 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 420 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1480, 1443, - /* 430 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 440 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 450 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 460 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 470 */ 1443, 1443, 1443, 1443, 1443, 1543, 1542, 1443, 1443, 1443, - /* 480 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 490 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 500 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 510 */ 1443, 1443, 1443, 1714, 1443, 1443, 1443, 1443, 1443, 1443, - /* 520 */ 1443, 1443, 1443, 1877, 1443, 1443, 1443, 1443, 1443, 1443, - /* 530 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 540 */ 1755, 1443, 1894, 1443, 1854, 1850, 1443, 1443, 1846, 1754, - /* 550 */ 1443, 1443, 1910, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 560 */ 1443, 1443, 1839, 1443, 1812, 1797, 1443, 1443, 1443, 1443, - /* 570 */ 1443, 1443, 1443, 1443, 1443, 1443, 1766, 1443, 1443, 1443, - /* 580 */ 1443, 1443, 1606, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 590 */ 1443, 1443, 1443, 1443, 1443, 1591, 1589, 1588, 1587, 1443, - /* 600 */ 1584, 1443, 1443, 1443, 1443, 1615, 1614, 1443, 1443, 1443, - /* 610 */ 1443, 1443, 1443, 1535, 1443, 1443, 1443, 1443, 1443, 1443, - /* 620 */ 1443, 1443, 1443, 1526, 1443, 1525, 1443, 1443, 1443, 1443, - /* 630 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 640 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, - /* 650 */ 1443, 1443, 1443, 1443, 1443, 1443, 1443, 1443, + /* 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 *****************************/ @@ -941,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 */ @@ -1130,11 +1135,11 @@ static const YYCODETYPE yyFallback[] = { 0, /* ASC => nothing */ 0, /* NULLS => nothing */ 0, /* ID => nothing */ - 246, /* NK_BITNOT => ID */ - 246, /* VALUES => ID */ - 246, /* IMPORT => ID */ - 246, /* NK_SEMI => ID */ - 246, /* FILE => ID */ + 247, /* NK_BITNOT => ID */ + 247, /* VALUES => ID */ + 247, /* IMPORT => ID */ + 247, /* NK_SEMI => ID */ + 247, /* FILE => ID */ }; #endif /* YYFALLBACK */ @@ -1280,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 */ "INSERT", - /* 190 */ "NULL", - /* 191 */ "NK_QUESTION", - /* 192 */ "NK_ARROW", - /* 193 */ "ROWTS", - /* 194 */ "TBNAME", - /* 195 */ "QSTARTTS", - /* 196 */ "QENDTS", - /* 197 */ "WSTARTTS", - /* 198 */ "WENDTS", - /* 199 */ "WDURATION", - /* 200 */ "CAST", - /* 201 */ "NOW", - /* 202 */ "TODAY", - /* 203 */ "TIMEZONE", - /* 204 */ "CLIENT_VERSION", - /* 205 */ "SERVER_VERSION", - /* 206 */ "SERVER_STATUS", - /* 207 */ "CURRENT_USER", - /* 208 */ "COUNT", - /* 209 */ "LAST_ROW", - /* 210 */ "BETWEEN", - /* 211 */ "IS", - /* 212 */ "NK_LT", - /* 213 */ "NK_GT", - /* 214 */ "NK_LE", - /* 215 */ "NK_GE", - /* 216 */ "NK_NE", - /* 217 */ "MATCH", - /* 218 */ "NMATCH", - /* 219 */ "CONTAINS", - /* 220 */ "JOIN", - /* 221 */ "INNER", - /* 222 */ "SELECT", - /* 223 */ "DISTINCT", - /* 224 */ "WHERE", - /* 225 */ "PARTITION", - /* 226 */ "BY", - /* 227 */ "SESSION", - /* 228 */ "STATE_WINDOW", - /* 229 */ "SLIDING", - /* 230 */ "FILL", - /* 231 */ "VALUE", - /* 232 */ "NONE", - /* 233 */ "PREV", - /* 234 */ "LINEAR", - /* 235 */ "NEXT", - /* 236 */ "HAVING", - /* 237 */ "RANGE", - /* 238 */ "EVERY", - /* 239 */ "ORDER", - /* 240 */ "SLIMIT", - /* 241 */ "SOFFSET", - /* 242 */ "LIMIT", - /* 243 */ "OFFSET", - /* 244 */ "ASC", - /* 245 */ "NULLS", - /* 246 */ "ID", - /* 247 */ "NK_BITNOT", - /* 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_cols_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) */ @@ -1670,424 +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_cols_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_cols_opt ::=", - /* 133 */ "specific_cols_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 */ "cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression", - /* 283 */ "literal ::= NK_INTEGER", - /* 284 */ "literal ::= NK_FLOAT", - /* 285 */ "literal ::= NK_STRING", - /* 286 */ "literal ::= NK_BOOL", - /* 287 */ "literal ::= TIMESTAMP NK_STRING", - /* 288 */ "literal ::= duration_literal", - /* 289 */ "literal ::= NULL", - /* 290 */ "literal ::= NK_QUESTION", - /* 291 */ "duration_literal ::= NK_VARIABLE", - /* 292 */ "signed ::= NK_INTEGER", - /* 293 */ "signed ::= NK_PLUS NK_INTEGER", - /* 294 */ "signed ::= NK_MINUS NK_INTEGER", - /* 295 */ "signed ::= NK_FLOAT", - /* 296 */ "signed ::= NK_PLUS NK_FLOAT", - /* 297 */ "signed ::= NK_MINUS NK_FLOAT", - /* 298 */ "signed_literal ::= signed", - /* 299 */ "signed_literal ::= NK_STRING", - /* 300 */ "signed_literal ::= NK_BOOL", - /* 301 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 302 */ "signed_literal ::= duration_literal", - /* 303 */ "signed_literal ::= NULL", - /* 304 */ "signed_literal ::= literal_func", - /* 305 */ "literal_list ::= signed_literal", - /* 306 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 307 */ "db_name ::= NK_ID", - /* 308 */ "table_name ::= NK_ID", - /* 309 */ "column_name ::= NK_ID", - /* 310 */ "function_name ::= NK_ID", - /* 311 */ "table_alias ::= NK_ID", - /* 312 */ "column_alias ::= NK_ID", - /* 313 */ "user_name ::= NK_ID", - /* 314 */ "index_name ::= NK_ID", - /* 315 */ "topic_name ::= NK_ID", - /* 316 */ "stream_name ::= NK_ID", - /* 317 */ "cgroup_name ::= NK_ID", - /* 318 */ "expression ::= literal", - /* 319 */ "expression ::= pseudo_column", - /* 320 */ "expression ::= column_reference", - /* 321 */ "expression ::= function_expression", - /* 322 */ "expression ::= subquery", - /* 323 */ "expression ::= NK_LP expression NK_RP", - /* 324 */ "expression ::= NK_PLUS expression", - /* 325 */ "expression ::= NK_MINUS expression", - /* 326 */ "expression ::= expression NK_PLUS expression", - /* 327 */ "expression ::= expression NK_MINUS expression", - /* 328 */ "expression ::= expression NK_STAR expression", - /* 329 */ "expression ::= expression NK_SLASH expression", - /* 330 */ "expression ::= expression NK_REM expression", - /* 331 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 332 */ "expression ::= expression NK_BITAND expression", - /* 333 */ "expression ::= expression NK_BITOR expression", - /* 334 */ "expression_list ::= expression", - /* 335 */ "expression_list ::= expression_list NK_COMMA expression", - /* 336 */ "column_reference ::= column_name", - /* 337 */ "column_reference ::= table_name NK_DOT column_name", - /* 338 */ "pseudo_column ::= ROWTS", - /* 339 */ "pseudo_column ::= TBNAME", - /* 340 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 341 */ "pseudo_column ::= QSTARTTS", - /* 342 */ "pseudo_column ::= QENDTS", - /* 343 */ "pseudo_column ::= WSTARTTS", - /* 344 */ "pseudo_column ::= WENDTS", - /* 345 */ "pseudo_column ::= WDURATION", - /* 346 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 347 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 348 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 349 */ "function_expression ::= literal_func", - /* 350 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 351 */ "literal_func ::= NOW", - /* 352 */ "noarg_func ::= NOW", - /* 353 */ "noarg_func ::= TODAY", - /* 354 */ "noarg_func ::= TIMEZONE", - /* 355 */ "noarg_func ::= DATABASE", - /* 356 */ "noarg_func ::= CLIENT_VERSION", - /* 357 */ "noarg_func ::= SERVER_VERSION", - /* 358 */ "noarg_func ::= SERVER_STATUS", - /* 359 */ "noarg_func ::= CURRENT_USER", - /* 360 */ "noarg_func ::= USER", - /* 361 */ "star_func ::= COUNT", - /* 362 */ "star_func ::= FIRST", - /* 363 */ "star_func ::= LAST", - /* 364 */ "star_func ::= LAST_ROW", - /* 365 */ "star_func_para_list ::= NK_STAR", - /* 366 */ "star_func_para_list ::= other_para_list", - /* 367 */ "other_para_list ::= star_func_para", - /* 368 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 369 */ "star_func_para ::= expression", - /* 370 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 371 */ "predicate ::= expression compare_op expression", - /* 372 */ "predicate ::= expression BETWEEN expression AND expression", - /* 373 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 374 */ "predicate ::= expression IS NULL", - /* 375 */ "predicate ::= expression IS NOT NULL", - /* 376 */ "predicate ::= expression in_op in_predicate_value", - /* 377 */ "compare_op ::= NK_LT", - /* 378 */ "compare_op ::= NK_GT", - /* 379 */ "compare_op ::= NK_LE", - /* 380 */ "compare_op ::= NK_GE", - /* 381 */ "compare_op ::= NK_NE", - /* 382 */ "compare_op ::= NK_EQ", - /* 383 */ "compare_op ::= LIKE", - /* 384 */ "compare_op ::= NOT LIKE", - /* 385 */ "compare_op ::= MATCH", - /* 386 */ "compare_op ::= NMATCH", - /* 387 */ "compare_op ::= CONTAINS", - /* 388 */ "in_op ::= IN", - /* 389 */ "in_op ::= NOT IN", - /* 390 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 391 */ "boolean_value_expression ::= boolean_primary", - /* 392 */ "boolean_value_expression ::= NOT boolean_primary", - /* 393 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 394 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 395 */ "boolean_primary ::= predicate", - /* 396 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 397 */ "common_expression ::= expression", - /* 398 */ "common_expression ::= boolean_value_expression", - /* 399 */ "from_clause_opt ::=", - /* 400 */ "from_clause_opt ::= FROM table_reference_list", - /* 401 */ "table_reference_list ::= table_reference", - /* 402 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 403 */ "table_reference ::= table_primary", - /* 404 */ "table_reference ::= joined_table", - /* 405 */ "table_primary ::= table_name alias_opt", - /* 406 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 407 */ "table_primary ::= subquery alias_opt", - /* 408 */ "table_primary ::= parenthesized_joined_table", - /* 409 */ "alias_opt ::=", - /* 410 */ "alias_opt ::= table_alias", - /* 411 */ "alias_opt ::= AS table_alias", - /* 412 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 413 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 414 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 415 */ "join_type ::=", - /* 416 */ "join_type ::= INNER", - /* 417 */ "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", - /* 418 */ "set_quantifier_opt ::=", - /* 419 */ "set_quantifier_opt ::= DISTINCT", - /* 420 */ "set_quantifier_opt ::= ALL", - /* 421 */ "select_list ::= select_item", - /* 422 */ "select_list ::= select_list NK_COMMA select_item", - /* 423 */ "select_item ::= NK_STAR", - /* 424 */ "select_item ::= common_expression", - /* 425 */ "select_item ::= common_expression column_alias", - /* 426 */ "select_item ::= common_expression AS column_alias", - /* 427 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 428 */ "where_clause_opt ::=", - /* 429 */ "where_clause_opt ::= WHERE search_condition", - /* 430 */ "partition_by_clause_opt ::=", - /* 431 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 432 */ "twindow_clause_opt ::=", - /* 433 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 434 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 435 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 436 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 437 */ "sliding_opt ::=", - /* 438 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 439 */ "fill_opt ::=", - /* 440 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 441 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 442 */ "fill_mode ::= NONE", - /* 443 */ "fill_mode ::= PREV", - /* 444 */ "fill_mode ::= NULL", - /* 445 */ "fill_mode ::= LINEAR", - /* 446 */ "fill_mode ::= NEXT", - /* 447 */ "group_by_clause_opt ::=", - /* 448 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 449 */ "group_by_list ::= expression", - /* 450 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 451 */ "having_clause_opt ::=", - /* 452 */ "having_clause_opt ::= HAVING search_condition", - /* 453 */ "range_opt ::=", - /* 454 */ "range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP", - /* 455 */ "every_opt ::=", - /* 456 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 457 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 458 */ "query_expression_body ::= query_primary", - /* 459 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 460 */ "query_expression_body ::= query_expression_body UNION query_expression_body", - /* 461 */ "query_primary ::= query_specification", - /* 462 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP", - /* 463 */ "order_by_clause_opt ::=", - /* 464 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 465 */ "slimit_clause_opt ::=", - /* 466 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 467 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 468 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 469 */ "limit_clause_opt ::=", - /* 470 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 471 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 472 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 473 */ "subquery ::= NK_LP query_expression NK_RP", - /* 474 */ "search_condition ::= common_expression", - /* 475 */ "sort_specification_list ::= sort_specification", - /* 476 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 477 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 478 */ "ordering_specification_opt ::=", - /* 479 */ "ordering_specification_opt ::= ASC", - /* 480 */ "ordering_specification_opt ::= DESC", - /* 481 */ "null_ordering_opt ::=", - /* 482 */ "null_ordering_opt ::= NULLS FIRST", - /* 483 */ "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 */ @@ -2214,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_cols_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 */ { } @@ -2687,490 +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_cols_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_cols_opt ::= */ - { 287, -3 }, /* (133) specific_cols_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 */ - { 252, -5 }, /* (282) cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ - { 255, -1 }, /* (283) literal ::= NK_INTEGER */ - { 255, -1 }, /* (284) literal ::= NK_FLOAT */ - { 255, -1 }, /* (285) literal ::= NK_STRING */ - { 255, -1 }, /* (286) literal ::= NK_BOOL */ - { 255, -2 }, /* (287) literal ::= TIMESTAMP NK_STRING */ - { 255, -1 }, /* (288) literal ::= duration_literal */ - { 255, -1 }, /* (289) literal ::= NULL */ - { 255, -1 }, /* (290) literal ::= NK_QUESTION */ - { 296, -1 }, /* (291) duration_literal ::= NK_VARIABLE */ - { 322, -1 }, /* (292) signed ::= NK_INTEGER */ - { 322, -2 }, /* (293) signed ::= NK_PLUS NK_INTEGER */ - { 322, -2 }, /* (294) signed ::= NK_MINUS NK_INTEGER */ - { 322, -1 }, /* (295) signed ::= NK_FLOAT */ - { 322, -2 }, /* (296) signed ::= NK_PLUS NK_FLOAT */ - { 322, -2 }, /* (297) signed ::= NK_MINUS NK_FLOAT */ - { 285, -1 }, /* (298) signed_literal ::= signed */ - { 285, -1 }, /* (299) signed_literal ::= NK_STRING */ - { 285, -1 }, /* (300) signed_literal ::= NK_BOOL */ - { 285, -2 }, /* (301) signed_literal ::= TIMESTAMP NK_STRING */ - { 285, -1 }, /* (302) signed_literal ::= duration_literal */ - { 285, -1 }, /* (303) signed_literal ::= NULL */ - { 285, -1 }, /* (304) signed_literal ::= literal_func */ - { 324, -1 }, /* (305) literal_list ::= signed_literal */ - { 324, -3 }, /* (306) literal_list ::= literal_list NK_COMMA signed_literal */ - { 263, -1 }, /* (307) db_name ::= NK_ID */ - { 291, -1 }, /* (308) table_name ::= NK_ID */ - { 283, -1 }, /* (309) column_name ::= NK_ID */ - { 298, -1 }, /* (310) function_name ::= NK_ID */ - { 325, -1 }, /* (311) table_alias ::= NK_ID */ - { 326, -1 }, /* (312) column_alias ::= NK_ID */ - { 257, -1 }, /* (313) user_name ::= NK_ID */ - { 304, -1 }, /* (314) index_name ::= NK_ID */ - { 311, -1 }, /* (315) topic_name ::= NK_ID */ - { 318, -1 }, /* (316) stream_name ::= NK_ID */ - { 313, -1 }, /* (317) cgroup_name ::= NK_ID */ - { 327, -1 }, /* (318) expression ::= literal */ - { 327, -1 }, /* (319) expression ::= pseudo_column */ - { 327, -1 }, /* (320) expression ::= column_reference */ - { 327, -1 }, /* (321) expression ::= function_expression */ - { 327, -1 }, /* (322) expression ::= subquery */ - { 327, -3 }, /* (323) expression ::= NK_LP expression NK_RP */ - { 327, -2 }, /* (324) expression ::= NK_PLUS expression */ - { 327, -2 }, /* (325) expression ::= NK_MINUS expression */ - { 327, -3 }, /* (326) expression ::= expression NK_PLUS expression */ - { 327, -3 }, /* (327) expression ::= expression NK_MINUS expression */ - { 327, -3 }, /* (328) expression ::= expression NK_STAR expression */ - { 327, -3 }, /* (329) expression ::= expression NK_SLASH expression */ - { 327, -3 }, /* (330) expression ::= expression NK_REM expression */ - { 327, -3 }, /* (331) expression ::= column_reference NK_ARROW NK_STRING */ - { 327, -3 }, /* (332) expression ::= expression NK_BITAND expression */ - { 327, -3 }, /* (333) expression ::= expression NK_BITOR expression */ - { 288, -1 }, /* (334) expression_list ::= expression */ - { 288, -3 }, /* (335) expression_list ::= expression_list NK_COMMA expression */ - { 329, -1 }, /* (336) column_reference ::= column_name */ - { 329, -3 }, /* (337) column_reference ::= table_name NK_DOT column_name */ - { 328, -1 }, /* (338) pseudo_column ::= ROWTS */ - { 328, -1 }, /* (339) pseudo_column ::= TBNAME */ - { 328, -3 }, /* (340) pseudo_column ::= table_name NK_DOT TBNAME */ - { 328, -1 }, /* (341) pseudo_column ::= QSTARTTS */ - { 328, -1 }, /* (342) pseudo_column ::= QENDTS */ - { 328, -1 }, /* (343) pseudo_column ::= WSTARTTS */ - { 328, -1 }, /* (344) pseudo_column ::= WENDTS */ - { 328, -1 }, /* (345) pseudo_column ::= WDURATION */ - { 330, -4 }, /* (346) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 330, -4 }, /* (347) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 330, -6 }, /* (348) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 330, -1 }, /* (349) function_expression ::= literal_func */ - { 323, -3 }, /* (350) literal_func ::= noarg_func NK_LP NK_RP */ - { 323, -1 }, /* (351) literal_func ::= NOW */ - { 334, -1 }, /* (352) noarg_func ::= NOW */ - { 334, -1 }, /* (353) noarg_func ::= TODAY */ - { 334, -1 }, /* (354) noarg_func ::= TIMEZONE */ - { 334, -1 }, /* (355) noarg_func ::= DATABASE */ - { 334, -1 }, /* (356) noarg_func ::= CLIENT_VERSION */ - { 334, -1 }, /* (357) noarg_func ::= SERVER_VERSION */ - { 334, -1 }, /* (358) noarg_func ::= SERVER_STATUS */ - { 334, -1 }, /* (359) noarg_func ::= CURRENT_USER */ - { 334, -1 }, /* (360) noarg_func ::= USER */ - { 332, -1 }, /* (361) star_func ::= COUNT */ - { 332, -1 }, /* (362) star_func ::= FIRST */ - { 332, -1 }, /* (363) star_func ::= LAST */ - { 332, -1 }, /* (364) star_func ::= LAST_ROW */ - { 333, -1 }, /* (365) star_func_para_list ::= NK_STAR */ - { 333, -1 }, /* (366) star_func_para_list ::= other_para_list */ - { 335, -1 }, /* (367) other_para_list ::= star_func_para */ - { 335, -3 }, /* (368) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 336, -1 }, /* (369) star_func_para ::= expression */ - { 336, -3 }, /* (370) star_func_para ::= table_name NK_DOT NK_STAR */ - { 337, -3 }, /* (371) predicate ::= expression compare_op expression */ - { 337, -5 }, /* (372) predicate ::= expression BETWEEN expression AND expression */ - { 337, -6 }, /* (373) predicate ::= expression NOT BETWEEN expression AND expression */ - { 337, -3 }, /* (374) predicate ::= expression IS NULL */ - { 337, -4 }, /* (375) predicate ::= expression IS NOT NULL */ - { 337, -3 }, /* (376) predicate ::= expression in_op in_predicate_value */ - { 338, -1 }, /* (377) compare_op ::= NK_LT */ - { 338, -1 }, /* (378) compare_op ::= NK_GT */ - { 338, -1 }, /* (379) compare_op ::= NK_LE */ - { 338, -1 }, /* (380) compare_op ::= NK_GE */ - { 338, -1 }, /* (381) compare_op ::= NK_NE */ - { 338, -1 }, /* (382) compare_op ::= NK_EQ */ - { 338, -1 }, /* (383) compare_op ::= LIKE */ - { 338, -2 }, /* (384) compare_op ::= NOT LIKE */ - { 338, -1 }, /* (385) compare_op ::= MATCH */ - { 338, -1 }, /* (386) compare_op ::= NMATCH */ - { 338, -1 }, /* (387) compare_op ::= CONTAINS */ - { 339, -1 }, /* (388) in_op ::= IN */ - { 339, -2 }, /* (389) in_op ::= NOT IN */ - { 340, -3 }, /* (390) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 341, -1 }, /* (391) boolean_value_expression ::= boolean_primary */ - { 341, -2 }, /* (392) boolean_value_expression ::= NOT boolean_primary */ - { 341, -3 }, /* (393) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 341, -3 }, /* (394) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 342, -1 }, /* (395) boolean_primary ::= predicate */ - { 342, -3 }, /* (396) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 343, -1 }, /* (397) common_expression ::= expression */ - { 343, -1 }, /* (398) common_expression ::= boolean_value_expression */ - { 344, 0 }, /* (399) from_clause_opt ::= */ - { 344, -2 }, /* (400) from_clause_opt ::= FROM table_reference_list */ - { 345, -1 }, /* (401) table_reference_list ::= table_reference */ - { 345, -3 }, /* (402) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 346, -1 }, /* (403) table_reference ::= table_primary */ - { 346, -1 }, /* (404) table_reference ::= joined_table */ - { 347, -2 }, /* (405) table_primary ::= table_name alias_opt */ - { 347, -4 }, /* (406) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 347, -2 }, /* (407) table_primary ::= subquery alias_opt */ - { 347, -1 }, /* (408) table_primary ::= parenthesized_joined_table */ - { 349, 0 }, /* (409) alias_opt ::= */ - { 349, -1 }, /* (410) alias_opt ::= table_alias */ - { 349, -2 }, /* (411) alias_opt ::= AS table_alias */ - { 350, -3 }, /* (412) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 350, -3 }, /* (413) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 348, -6 }, /* (414) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 351, 0 }, /* (415) join_type ::= */ - { 351, -1 }, /* (416) join_type ::= INNER */ - { 353, -12 }, /* (417) 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 }, /* (418) set_quantifier_opt ::= */ - { 354, -1 }, /* (419) set_quantifier_opt ::= DISTINCT */ - { 354, -1 }, /* (420) set_quantifier_opt ::= ALL */ - { 355, -1 }, /* (421) select_list ::= select_item */ - { 355, -3 }, /* (422) select_list ::= select_list NK_COMMA select_item */ - { 363, -1 }, /* (423) select_item ::= NK_STAR */ - { 363, -1 }, /* (424) select_item ::= common_expression */ - { 363, -2 }, /* (425) select_item ::= common_expression column_alias */ - { 363, -3 }, /* (426) select_item ::= common_expression AS column_alias */ - { 363, -3 }, /* (427) select_item ::= table_name NK_DOT NK_STAR */ - { 321, 0 }, /* (428) where_clause_opt ::= */ - { 321, -2 }, /* (429) where_clause_opt ::= WHERE search_condition */ - { 356, 0 }, /* (430) partition_by_clause_opt ::= */ - { 356, -3 }, /* (431) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 360, 0 }, /* (432) twindow_clause_opt ::= */ - { 360, -6 }, /* (433) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 360, -4 }, /* (434) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 360, -6 }, /* (435) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 360, -8 }, /* (436) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 307, 0 }, /* (437) sliding_opt ::= */ - { 307, -4 }, /* (438) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 359, 0 }, /* (439) fill_opt ::= */ - { 359, -4 }, /* (440) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 359, -6 }, /* (441) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 364, -1 }, /* (442) fill_mode ::= NONE */ - { 364, -1 }, /* (443) fill_mode ::= PREV */ - { 364, -1 }, /* (444) fill_mode ::= NULL */ - { 364, -1 }, /* (445) fill_mode ::= LINEAR */ - { 364, -1 }, /* (446) fill_mode ::= NEXT */ - { 361, 0 }, /* (447) group_by_clause_opt ::= */ - { 361, -3 }, /* (448) group_by_clause_opt ::= GROUP BY group_by_list */ - { 365, -1 }, /* (449) group_by_list ::= expression */ - { 365, -3 }, /* (450) group_by_list ::= group_by_list NK_COMMA expression */ - { 362, 0 }, /* (451) having_clause_opt ::= */ - { 362, -2 }, /* (452) having_clause_opt ::= HAVING search_condition */ - { 357, 0 }, /* (453) range_opt ::= */ - { 357, -6 }, /* (454) range_opt ::= RANGE NK_LP expression NK_COMMA expression NK_RP */ - { 358, 0 }, /* (455) every_opt ::= */ - { 358, -4 }, /* (456) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 312, -4 }, /* (457) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 366, -1 }, /* (458) query_expression_body ::= query_primary */ - { 366, -4 }, /* (459) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 366, -3 }, /* (460) query_expression_body ::= query_expression_body UNION query_expression_body */ - { 370, -1 }, /* (461) query_primary ::= query_specification */ - { 370, -6 }, /* (462) query_primary ::= NK_LP query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP */ - { 367, 0 }, /* (463) order_by_clause_opt ::= */ - { 367, -3 }, /* (464) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 368, 0 }, /* (465) slimit_clause_opt ::= */ - { 368, -2 }, /* (466) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 368, -4 }, /* (467) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 368, -4 }, /* (468) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 369, 0 }, /* (469) limit_clause_opt ::= */ - { 369, -2 }, /* (470) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 369, -4 }, /* (471) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 369, -4 }, /* (472) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 331, -3 }, /* (473) subquery ::= NK_LP query_expression NK_RP */ - { 352, -1 }, /* (474) search_condition ::= common_expression */ - { 371, -1 }, /* (475) sort_specification_list ::= sort_specification */ - { 371, -3 }, /* (476) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 372, -3 }, /* (477) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 373, 0 }, /* (478) ordering_specification_opt ::= */ - { 373, -1 }, /* (479) ordering_specification_opt ::= ASC */ - { 373, -1 }, /* (480) ordering_specification_opt ::= DESC */ - { 374, 0 }, /* (481) null_ordering_opt ::= */ - { 374, -2 }, /* (482) null_ordering_opt ::= NULLS FIRST */ - { 374, -2 }, /* (483) 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 */ @@ -3259,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 ::= */ { } @@ -3277,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 */ @@ -3304,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); } @@ -3386,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 307: /* db_name ::= NK_ID */ yytestcase(yyruleno==307); - case 308: /* table_name ::= NK_ID */ yytestcase(yyruleno==308); - case 309: /* column_name ::= NK_ID */ yytestcase(yyruleno==309); - case 310: /* function_name ::= NK_ID */ yytestcase(yyruleno==310); - case 311: /* table_alias ::= NK_ID */ yytestcase(yyruleno==311); - case 312: /* column_alias ::= NK_ID */ yytestcase(yyruleno==312); - case 313: /* user_name ::= NK_ID */ yytestcase(yyruleno==313); - case 314: /* index_name ::= NK_ID */ yytestcase(yyruleno==314); - case 315: /* topic_name ::= NK_ID */ yytestcase(yyruleno==315); - case 316: /* stream_name ::= NK_ID */ yytestcase(yyruleno==316); - case 317: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==317); - case 352: /* noarg_func ::= NOW */ yytestcase(yyruleno==352); - case 353: /* noarg_func ::= TODAY */ yytestcase(yyruleno==353); - case 354: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==354); - case 355: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==355); - case 356: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==356); - case 357: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==357); - case 358: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==358); - case 359: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==359); - case 360: /* noarg_func ::= USER */ yytestcase(yyruleno==360); - case 361: /* star_func ::= COUNT */ yytestcase(yyruleno==361); - case 362: /* star_func ::= FIRST */ yytestcase(yyruleno==362); - case 363: /* star_func ::= LAST */ yytestcase(yyruleno==363); - case 364: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==364); -{ 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); } @@ -3444,1224 +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 418: /* set_quantifier_opt ::= */ yytestcase(yyruleno==418); -{ 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 305: /* literal_list ::= signed_literal */ yytestcase(yyruleno==305); - case 367: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==367); - case 421: /* select_list ::= select_item */ yytestcase(yyruleno==421); - case 475: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==475); -{ 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 306: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==306); - case 368: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==368); - case 422: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==422); - case 476: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==476); -{ 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_cols_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_cols_opt ::= */ - case 163: /* tags_def_opt ::= */ yytestcase(yyruleno==163); - case 430: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==430); - case 447: /* group_by_clause_opt ::= */ yytestcase(yyruleno==447); - case 463: /* order_by_clause_opt ::= */ yytestcase(yyruleno==463); -{ 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_cols_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 366: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==366); -{ 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 334: /* expression_list ::= expression */ yytestcase(yyruleno==334); -{ 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 335: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==335); -{ 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 399: /* from_clause_opt ::= */ yytestcase(yyruleno==399); - case 428: /* where_clause_opt ::= */ yytestcase(yyruleno==428); - case 432: /* twindow_clause_opt ::= */ yytestcase(yyruleno==432); - case 437: /* sliding_opt ::= */ yytestcase(yyruleno==437); - case 439: /* fill_opt ::= */ yytestcase(yyruleno==439); - case 451: /* having_clause_opt ::= */ yytestcase(yyruleno==451); - case 453: /* range_opt ::= */ yytestcase(yyruleno==453); - case 455: /* every_opt ::= */ yytestcase(yyruleno==455); - case 465: /* slimit_clause_opt ::= */ yytestcase(yyruleno==465); - case 469: /* limit_clause_opt ::= */ yytestcase(yyruleno==469); -{ 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 419: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==419); -{ 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 400: /* from_clause_opt ::= FROM table_reference_list */ yytestcase(yyruleno==400); - case 429: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==429); - case 452: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==452); -{ 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: /* cmd ::= INSERT INTO full_table_name specific_cols_opt query_expression */ -{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-2].minor.yy212, yymsp[-1].minor.yy424, yymsp[0].minor.yy212); } - break; - case 283: /* 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 284: /* 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 285: /* 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 286: /* 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 287: /* 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 288: /* literal ::= duration_literal */ - case 298: /* signed_literal ::= signed */ yytestcase(yyruleno==298); - case 318: /* expression ::= literal */ yytestcase(yyruleno==318); - case 319: /* expression ::= pseudo_column */ yytestcase(yyruleno==319); - case 320: /* expression ::= column_reference */ yytestcase(yyruleno==320); - case 321: /* expression ::= function_expression */ yytestcase(yyruleno==321); - case 322: /* expression ::= subquery */ yytestcase(yyruleno==322); - case 349: /* function_expression ::= literal_func */ yytestcase(yyruleno==349); - case 391: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==391); - case 395: /* boolean_primary ::= predicate */ yytestcase(yyruleno==395); - case 397: /* common_expression ::= expression */ yytestcase(yyruleno==397); - case 398: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==398); - case 401: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==401); - case 403: /* table_reference ::= table_primary */ yytestcase(yyruleno==403); - case 404: /* table_reference ::= joined_table */ yytestcase(yyruleno==404); - case 408: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==408); - case 458: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==458); - case 461: /* query_primary ::= query_specification */ yytestcase(yyruleno==461); -{ yylhsminor.yy212 = yymsp[0].minor.yy212; } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 289: /* 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 290: /* 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 291: /* 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 292: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 293: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy212 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - break; - case 294: /* 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 295: /* 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 296: /* 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 297: /* 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 299: /* 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 300: /* 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 301: /* 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 302: /* signed_literal ::= duration_literal */ - case 304: /* signed_literal ::= literal_func */ yytestcase(yyruleno==304); - case 369: /* star_func_para ::= expression */ yytestcase(yyruleno==369); - case 424: /* select_item ::= common_expression */ yytestcase(yyruleno==424); - case 474: /* search_condition ::= common_expression */ yytestcase(yyruleno==474); -{ 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 303: /* 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 323: /* expression ::= NK_LP expression NK_RP */ - case 396: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==396); -{ 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 324: /* 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 325: /* 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 326: /* 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 327: /* 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 328: /* 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 329: /* 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 330: /* 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 331: /* 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 332: /* 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 333: /* 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 336: /* 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 337: /* 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 338: /* pseudo_column ::= ROWTS */ - case 339: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==339); - case 341: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==341); - case 342: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==342); - case 343: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==343); - case 344: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==344); - case 345: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==345); - case 351: /* literal_func ::= NOW */ yytestcase(yyruleno==351); -{ yylhsminor.yy212 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy212 = yylhsminor.yy212; - break; - case 340: /* 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 346: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 347: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==347); -{ 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 348: /* 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 350: /* 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 365: /* 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 370: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 427: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==427); -{ yylhsminor.yy212 = createColumnNode(pCxt, &yymsp[-2].minor.yy329, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy212 = yylhsminor.yy212; - break; - case 371: /* predicate ::= expression compare_op expression */ - case 376: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==376); + 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 372: /* 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 373: /* 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 374: /* 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 375: /* 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 377: /* 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 378: /* 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 379: /* 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 380: /* 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 381: /* 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 382: /* 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 383: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy290 = OP_TYPE_LIKE; } + case 384: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy716 = OP_TYPE_LIKE; } break; - case 384: /* 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 385: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy290 = OP_TYPE_MATCH; } + case 386: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy716 = OP_TYPE_MATCH; } break; - case 386: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy290 = OP_TYPE_NMATCH; } + case 387: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy716 = OP_TYPE_NMATCH; } break; - case 387: /* 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 388: /* in_op ::= IN */ -{ yymsp[0].minor.yy290 = OP_TYPE_IN; } + case 389: /* in_op ::= IN */ +{ yymsp[0].minor.yy716 = OP_TYPE_IN; } break; - case 389: /* 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 390: /* 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 392: /* 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 393: /* 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 394: /* 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 402: /* 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 405: /* 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 406: /* 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 407: /* 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 409: /* alias_opt ::= */ -{ yymsp[1].minor.yy329 = nil_token; } + case 410: /* alias_opt ::= */ +{ yymsp[1].minor.yy401 = nil_token; } break; - case 410: /* 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 411: /* 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 412: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 413: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==413); -{ 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 414: /* 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 415: /* join_type ::= */ -{ yymsp[1].minor.yy162 = JOIN_TYPE_INNER; } + case 416: /* join_type ::= */ +{ yymsp[1].minor.yy52 = JOIN_TYPE_INNER; } break; - case 416: /* join_type ::= INNER */ -{ yymsp[0].minor.yy162 = JOIN_TYPE_INNER; } + case 417: /* join_type ::= INNER */ +{ yymsp[0].minor.yy52 = JOIN_TYPE_INNER; } break; - case 417: /* 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 420: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy737 = false; } + case 421: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy89 = false; } break; - case 423: /* 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 425: /* 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 426: /* 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 431: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 448: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==448); - case 464: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==464); -{ 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 433: /* 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 434: /* 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 435: /* 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 436: /* 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 438: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - case 456: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==456); -{ 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 440: /* 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 441: /* 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 442: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy294 = FILL_MODE_NONE; } + case 443: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy582 = FILL_MODE_NONE; } break; - case 443: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy294 = FILL_MODE_PREV; } + case 444: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy582 = FILL_MODE_PREV; } break; - case 444: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy294 = FILL_MODE_NULL; } + case 445: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy582 = FILL_MODE_NULL; } break; - case 445: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy294 = FILL_MODE_LINEAR; } + case 446: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy582 = FILL_MODE_LINEAR; } break; - case 446: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy294 = FILL_MODE_NEXT; } + case 447: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy582 = FILL_MODE_NEXT; } break; - case 449: /* 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 450: /* 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 454: /* 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 457: /* 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 459: /* 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 460: /* 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 462: /* 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 466: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 470: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==470); -{ 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 467: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 471: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==471); -{ 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 468: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 472: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==472); -{ 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 473: /* 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 477: /* 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 478: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy188 = ORDER_ASC; } + case 479: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy482 = ORDER_ASC; } break; - case 479: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy188 = ORDER_ASC; } + case 480: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy482 = ORDER_ASC; } break; - case 480: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy188 = ORDER_DESC; } + case 481: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy482 = ORDER_DESC; } break; - case 481: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy607 = NULL_ORDER_DEFAULT; } + case 482: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy345 = NULL_ORDER_DEFAULT; } break; - case 482: /* 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 483: /* 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/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 74d780b8c7d808a9d98c0a124d18cff79f338a81..e7589fb0df363bd0cf6c9c5945cd80d6da9bca00 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -1138,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; } @@ -1279,10 +1281,16 @@ static int32_t createVnodeModifLogicNodeByInsert(SLogicPlanContext* pCxt, SInser 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; diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index ea8bae8259be21b40ff83f22d5a756d12a3669a1..458e0f545dc95424b0f02a229280e05b982c01a4 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -890,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)) { @@ -905,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; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 7ec3af31b211c3d8a2109bde5dd8b1a9f7567997..2356eb368e61035307f97665c2f2ce183ab99a9f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -1510,18 +1510,21 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod } 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 = TSDB_CODE_SUCCESS; - - pInserter->sink.pInputDataBlockDesc = - (SDataBlockDescNode*)nodesCloneNode((SNode*)pSubplan->pNode->pOutputDataBlockDesc); - if (NULL == pInserter->sink.pInputDataBlockDesc) { - code = TSDB_CODE_OUT_OF_MEMORY; + 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) { @@ -1530,7 +1533,7 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod nodesDestroyNode((SNode*)pInserter); } - return TSDB_CODE_SUCCESS; + return code; } static int32_t buildInsertSelectSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan) { diff --git a/source/libs/planner/test/planOtherTest.cpp b/source/libs/planner/test/planOtherTest.cpp index 7fd38cc5c8dbce3e36ab517728dcd91912f8c437..6add1cf630416b7adaff1394f2af0e2791a9e3f6 100644 --- a/source/libs/planner/test/planOtherTest.cpp +++ b/source/libs/planner/test/planOtherTest.cpp @@ -96,4 +96,8 @@ 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/qworker/inc/qwMsg.h b/source/libs/qworker/inc/qwMsg.h index 654631749b3258aaabd6caceb1a23c9e839d5388..7becaf06eb414da2636e43889fd05a84deb7dd14 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/qwMsg.c b/source/libs/qworker/src/qwMsg.c index facb146cc8a5a03ed1959f0e1ad8e20aab19731a..ea5aa3c563bf8f7527395bd0bcd4f72b1149019d 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 412f5234a46810b9818c208f17e16faf2bed6916..3f8d62b1aad38f2ed159c2eb9139ee0a85bb65e9 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -242,9 +242,8 @@ int32_t qwGetQueryResFromSink(QW_FPARAMS_DEF, SQWTaskCtx *ctx, int32_t *dataLen, 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; } @@ -928,7 +917,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; @@ -943,7 +932,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)); @@ -960,7 +949,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/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 4224201595cf2b1349b728d90e258d1827965f29..e1035c4fca59c15bdedc1c0ae1011a994bfb9398 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -21,7 +21,6 @@ #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); @@ -42,7 +41,7 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy 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: case TDMT_SCH_MERGE_FETCH_RSP: @@ -58,13 +57,14 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy 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)); @@ -83,7 +83,7 @@ int32_t schValidateReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t msgTy 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; } @@ -106,6 +106,11 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa } 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) { @@ -127,8 +132,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa } SCH_ERR_JRET(rspCode); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -153,8 +158,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa } SCH_ERR_JRET(rspCode); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -167,7 +172,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa tDecoderClear(&coder); SCH_ERR_JRET(code); SCH_ERR_JRET(rsp.code); - + pJob->execRes.res = rsp.pMeta; pJob->execRes.msgType = TDMT_VND_ALTER_TABLE; } @@ -178,8 +183,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); } - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; } @@ -227,7 +232,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_UNLOCK(SCH_WRITE, &pJob->resLock); } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(msg); SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); @@ -237,7 +242,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(rspCode); if (msg) { - SDecoder coder = {0}; + SDecoder coder = {0}; SVDeleteRsp rsp = {0}; tDecoderInit(&coder, msg, msgSize); tDecodeSVDeleteRsp(&coder, &rsp); @@ -251,7 +256,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; - } + } case TDMT_SCH_QUERY_RSP: case TDMT_SCH_MERGE_QUERY_RSP: { SQueryTableRsp *rsp = (SQueryTableRsp *)msg; @@ -264,8 +269,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(schSaveJobQueryRes(pJob, rsp)); - taosMemoryFreeClear(msg); - + taosMemoryFreeClear(msg); + SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); break; @@ -317,14 +322,14 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_ERR_JRET(schProcessOnExplainDone(pJob, pTask, pRsp)); } - taosMemoryFreeClear(msg); + taosMemoryFreeClear(msg); return TSDB_CODE_SUCCESS; } SCH_ERR_JRET(schLaunchFetchTask(pJob)); - taosMemoryFreeClear(msg); + taosMemoryFreeClear(msg); return TSDB_CODE_SUCCESS; } @@ -344,7 +349,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa SCH_TASK_DLOG("got fetch rsp, rows:%d, complete:%d", htonl(rsp->numOfRows), rsp->completed); - msg = NULL; + msg = NULL; schProcessOnDataFetched(pJob); break; @@ -373,7 +378,6 @@ _return: SCH_RET(schProcessOnTaskFailure(pJob, pTask, code)); } - int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { int32_t code = 0; SSchTaskCallbackParam *pParam = (SSchTaskCallbackParam *)param; @@ -383,7 +387,7 @@ int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { qDebug("begin to handle rsp msg, type:%s, handle:%p, code:%s", TMSG_INFO(pMsg->msgType), pMsg->handle, tstrerror(rspCode)); SCH_ERR_RET(schProcessOnCbBegin(&pJob, &pTask, pParam->queryId, pParam->refId, pParam->taskId)); - + code = schHandleResponseMsg(pJob, pTask, pParam->execId, pMsg, rspCode); pMsg->pData = NULL; @@ -399,7 +403,8 @@ int32_t schHandleCallback(void *param, SDataBuf *pMsg, int32_t rspCode) { 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; } @@ -423,6 +428,9 @@ 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}; @@ -462,7 +470,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); @@ -479,19 +487,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)); @@ -499,14 +507,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) { @@ -521,7 +530,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; @@ -540,7 +549,6 @@ _return: SCH_RET(code); } - int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) { switch (msgType) { case TDMT_VND_CREATE_TABLE: @@ -561,6 +569,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; @@ -638,7 +649,6 @@ _return: SCH_RET(code); } - int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { int32_t code = 0; SSchHbCallbackParam *param = NULL; @@ -698,9 +708,9 @@ _return: } 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)); @@ -821,19 +831,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; @@ -868,8 +877,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}; @@ -913,7 +921,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; @@ -948,7 +956,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) { @@ -968,7 +977,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); @@ -980,7 +989,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)); @@ -1083,8 +1092,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)); @@ -1100,6 +1109,3 @@ _return: taosMemoryFreeClear(msg); SCH_RET(code); } - - - diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 82e017e309c876755ba1f83222aa8d9333518df6..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 "schInt.h" #include "tmsg.h" #include "tref.h" -#include "trpc.h" SSchedulerMgmt schMgmt = { .jobRef = -1, diff --git a/source/libs/sync/inc/syncRaftCfg.h b/source/libs/sync/inc/syncRaftCfg.h index 086a6aa074a83e4626c786cf09aa8297ed550add..fead7cdc762b46b4d3e26a2af0d5f370eb19c6cf 100644 --- a/source/libs/sync/inc/syncRaftCfg.h +++ b/source/libs/sync/inc/syncRaftCfg.h @@ -36,6 +36,7 @@ typedef struct SRaftCfg { TdFilePtr pFile; char path[TSDB_FILENAME_LEN * 2]; int8_t isStandBy; + int32_t batchSize; int8_t snapshotStrategy; SyncIndex lastConfigIndex; @@ -49,19 +50,20 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg); int32_t raftCfgPersist(SRaftCfg *pRaftCfg); int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex); -cJSON *syncCfg2Json(SSyncCfg *pSyncCfg); -char *syncCfg2Str(SSyncCfg *pSyncCfg); -char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg); +cJSON * syncCfg2Json(SSyncCfg *pSyncCfg); +char * syncCfg2Str(SSyncCfg *pSyncCfg); +char * syncCfg2SimpleStr(SSyncCfg *pSyncCfg); int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg); int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg); -cJSON *raftCfg2Json(SRaftCfg *pRaftCfg); -char *raftCfg2Str(SRaftCfg *pRaftCfg); +cJSON * raftCfg2Json(SRaftCfg *pRaftCfg); +char * raftCfg2Str(SRaftCfg *pRaftCfg); int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg); int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg); typedef struct SRaftCfgMeta { int8_t isStandBy; + 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/syncMain.c b/source/libs/sync/src/syncMain.c index d04cbb6163a1db8e0c791c494ae7a84bb92dd904..cc6057b031db0e92ed062e26b64973c63e6d5d58 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) { @@ -783,6 +815,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; @@ -843,6 +876,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { meta.isStandBy = pSyncInfo->isStandBy; meta.snapshotStrategy = pSyncInfo->snapshotStrategy; meta.lastConfigIndex = SYNC_INDEX_INVALID; + meta.batchSize = pSyncInfo->batchSize; ret = raftCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), meta, pSyncNode->configPath); ASSERT(ret == 0); diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 7eb7eb0db15b2188873c46b52ac2df3030fd3fe0..ead1168632a154be285c07c4a7183a2a202451dd 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -101,7 +101,7 @@ cJSON *syncCfg2Json(SSyncCfg *pSyncCfg) { char *syncCfg2Str(SSyncCfg *pSyncCfg) { cJSON *pJson = syncCfg2Json(pSyncCfg); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -109,7 +109,7 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) { if (pSyncCfg != NULL) { int32_t len = 512; - char *s = taosMemoryMalloc(len); + char * s = taosMemoryMalloc(len); memset(s, 0, len); snprintf(s, len, "{replica-num:%d, my-index:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); @@ -183,6 +183,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { cJSON_AddItemToObject(pRoot, "SSyncCfg", syncCfg2Json(&(pRaftCfg->cfg))); cJSON_AddNumberToObject(pRoot, "isStandBy", pRaftCfg->isStandBy); cJSON_AddNumberToObject(pRoot, "snapshotStrategy", pRaftCfg->snapshotStrategy); + cJSON_AddNumberToObject(pRoot, "batchSize", pRaftCfg->batchSize); char buf64[128]; snprintf(buf64, sizeof(buf64), "%ld", pRaftCfg->lastConfigIndex); @@ -205,7 +206,7 @@ cJSON *raftCfg2Json(SRaftCfg *pRaftCfg) { char *raftCfg2Str(SRaftCfg *pRaftCfg) { cJSON *pJson = raftCfg2Json(pRaftCfg); - char *serialized = cJSON_Print(pJson); + char * serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } @@ -228,6 +229,7 @@ int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) { SRaftCfg raftCfg; raftCfg.cfg = *pCfg; raftCfg.isStandBy = meta.isStandBy; + raftCfg.batchSize = meta.batchSize; raftCfg.snapshotStrategy = meta.snapshotStrategy; raftCfg.lastConfigIndex = meta.lastConfigIndex; raftCfg.configIndexCount = 1; @@ -257,6 +259,9 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) { cJSON *pJsonIsStandBy = cJSON_GetObjectItem(pJson, "isStandBy"); pRaftCfg->isStandBy = cJSON_GetNumberValue(pJsonIsStandBy); + cJSON *pJsonBatchSize = cJSON_GetObjectItem(pJson, "batchSize"); + pRaftCfg->batchSize = cJSON_GetNumberValue(pJsonBatchSize); + cJSON *pJsonSnapshotStrategy = cJSON_GetObjectItem(pJson, "snapshotStrategy"); pRaftCfg->snapshotStrategy = cJSON_GetNumberValue(pJsonSnapshotStrategy); @@ -280,7 +285,7 @@ int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg) { (pRaftCfg->configIndexArr)[i] = atoll(pIndex->valuestring); } - cJSON *pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); + cJSON * pJsonSyncCfg = cJSON_GetObjectItem(pJson, "SSyncCfg"); int32_t code = syncCfgFromJson(pJsonSyncCfg, &(pRaftCfg->cfg)); ASSERT(code == 0); 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 a3773604fb39673b7fe82438f871f39bf3c3a159..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) { @@ -84,6 +85,7 @@ void test3() { SRaftCfgMeta meta; meta.isStandBy = 7; meta.snapshotStrategy = 9; + meta.batchSize = 10; meta.lastConfigIndex = 789; raftCfgCreateFile(pCfg, meta, s); printf("%s create json file: %s \n", (char*)__FUNCTION__, s); @@ -109,6 +111,7 @@ void test5() { pCfg->cfg.myIndex = taosGetTimestampSec(); pCfg->isStandBy += 2; 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/util/src/terror.c b/source/util/src/terror.c index e05b63422262316bcb2c883dbe067a4c9e64182d..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") 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/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 0783aa0fd1d7007cd4389383b0cc9b74a6de0b42..4e009e702d35038904ef3f39097eed5141a4e8a6 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -163,8 +163,8 @@ # --- 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/checkError1.sim 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/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/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_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 70cf34e76693bb3736f74058a7a95fea9f29cae1..9c595a8c8c20b6fc7821fbef2a95db66396c9e36 100644 --- a/tests/system-test/2-query/Timediff.py +++ b/tests/system-test/2-query/Timediff.py @@ -123,10 +123,10 @@ class TDTestCase: 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]/1000000)-self.subtractor*1000000000))) + 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}') 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/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 ee302a1d8ee9f2524799ba350b2898dc0269b946..ea4f963b716d45b2a2e77d8db52286442fb658a5 100644 --- a/tests/system-test/2-query/timetruncate.py +++ b/tests/system-test/2-query/timetruncate.py @@ -21,7 +21,6 @@ class TDTestCase: 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.error_unit = ['2w','2d','2h','2m','2s','2a','2u','1c','#1'] self.ntbname = 'ntb' self.stbname = 'stb' self.ctbname = 'ctb' 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/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/taos-tools b/tools/taos-tools index 50b68d85f7cbaf7a9adfa4082e88ca758770f75e..7105027650b51e701cfa1dac11b8fb42d447dd01 160000 --- a/tools/taos-tools +++ b/tools/taos-tools @@ -1 +1 @@ -Subproject commit 50b68d85f7cbaf7a9adfa4082e88ca758770f75e +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