Merge branch '3.0' into feature/tq
This commit is contained in:
commit
c56743d85a
|
@ -18,6 +18,13 @@ IF(${TD_WINDOWS})
|
|||
ON
|
||||
)
|
||||
|
||||
MESSAGE("build iconv Win32")
|
||||
option(
|
||||
BUILD_WITH_ICONV
|
||||
"If build iconv on Windows"
|
||||
ON
|
||||
)
|
||||
|
||||
ENDIF ()
|
||||
|
||||
IF(${TD_LINUX} MATCHES TRUE)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
|
||||
# iconv
|
||||
ExternalProject_Add(iconv
|
||||
GIT_REPOSITORY https://github.com/win-iconv/win-iconv.git
|
||||
GIT_TAG v0.0.8
|
||||
SOURCE_DIR "${CMAKE_CONTRIB_DIR}/iconv"
|
||||
BINARY_DIR ""
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND ""
|
||||
TEST_COMMAND ""
|
||||
)
|
|
@ -83,6 +83,11 @@ if(${BUILD_WITH_NURAFT})
|
|||
cat("${CMAKE_SUPPORT_DIR}/nuraft_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_WITH_NURAFT})
|
||||
|
||||
# iconv
|
||||
if(${BUILD_WITH_ICONV})
|
||||
cat("${CMAKE_SUPPORT_DIR}/iconv_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(${BUILD_WITH_ICONV})
|
||||
|
||||
# download dependencies
|
||||
configure_file(${CONTRIB_TMP_FILE} "${CMAKE_CONTRIB_DIR}/deps-download/CMakeLists.txt")
|
||||
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
||||
|
@ -208,14 +213,10 @@ endif(${BUILD_WITH_TRAFT})
|
|||
|
||||
# LIBUV
|
||||
if(${BUILD_WITH_UV})
|
||||
if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
MESSAGE("Windows need set no-sign-compare")
|
||||
add_compile_options(-Wno-sign-compare)
|
||||
endif ()
|
||||
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
file(READ "libuv/include/uv.h" CONTENTS)
|
||||
string(REGEX REPLACE "/([\r]*)\nstruct uv_tcp_s {" "/\\1\ntypedef BOOL (PASCAL *LPFN_CONNECTEX) (SOCKET s, const struct sockaddr* name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength,LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped);\\1\nstruct uv_tcp_s {" CONTENTS_NEW "${CONTENTS}")
|
||||
file(WRITE "libuv/include/uv.h" "${CONTENTS_NEW}")
|
||||
if (${TD_WINDOWS})
|
||||
file(READ "libuv/include/uv.h" CONTENTS)
|
||||
string(REGEX REPLACE "/([\r]*)\nstruct uv_tcp_s {" "/\\1\ntypedef BOOL (PASCAL *LPFN_CONNECTEX) (SOCKET s, const struct sockaddr* name, int namelen, PVOID lpSendBuffer, DWORD dwSendDataLength,LPDWORD lpdwBytesSent, LPOVERLAPPED lpOverlapped);\\1\nstruct uv_tcp_s {" CONTENTS_NEW "${CONTENTS}")
|
||||
file(WRITE "libuv/include/uv.h" "${CONTENTS_NEW}")
|
||||
endif ()
|
||||
add_subdirectory(libuv)
|
||||
endif(${BUILD_WITH_UV})
|
||||
|
@ -249,10 +250,14 @@ endif(${BUILD_WITH_SQLITE})
|
|||
|
||||
# pthread
|
||||
if(${BUILD_PTHREAD})
|
||||
ADD_DEFINITIONS("-DPTW32_STATIC_LIB")
|
||||
add_subdirectory(pthread-win32)
|
||||
add_definitions(-DPTW32_STATIC_LIB)
|
||||
add_subdirectory(pthread)
|
||||
endif(${BUILD_PTHREAD})
|
||||
|
||||
# iconv
|
||||
if(${BUILD_WITH_ICONV})
|
||||
add_subdirectory(iconv)
|
||||
endif(${BUILD_WITH_ICONV})
|
||||
|
||||
# ================================================================================================
|
||||
# Build test
|
||||
|
|
|
@ -111,15 +111,16 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_MAX,
|
||||
} EShowType;
|
||||
|
||||
#define TSDB_ALTER_TABLE_ADD_TAG 1
|
||||
#define TSDB_ALTER_TABLE_DROP_TAG 2
|
||||
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME 3
|
||||
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4
|
||||
|
||||
#define TSDB_ALTER_TABLE_ADD_TAG 1
|
||||
#define TSDB_ALTER_TABLE_DROP_TAG 2
|
||||
#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME 3
|
||||
#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4
|
||||
#define TSDB_ALTER_TABLE_ADD_COLUMN 5
|
||||
#define TSDB_ALTER_TABLE_DROP_COLUMN 6
|
||||
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES 7
|
||||
#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES 8
|
||||
#define TSDB_ALTER_TABLE_UPDATE_OPTIONS 9
|
||||
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME 10
|
||||
|
||||
#define TSDB_FILL_NONE 0
|
||||
#define TSDB_FILL_NULL 1
|
||||
|
@ -2052,27 +2053,19 @@ static FORCE_INLINE void* tDecodeTSma(void* buf, STSma* pSma) {
|
|||
buf = taosDecodeFixedI64(buf, &pSma->sliding);
|
||||
|
||||
if (pSma->exprLen > 0) {
|
||||
pSma->expr = (char*)calloc(pSma->exprLen, 1);
|
||||
if (pSma->expr != NULL) {
|
||||
buf = taosDecodeStringTo(buf, pSma->expr);
|
||||
} else {
|
||||
if ((buf = taosDecodeString(buf, &pSma->expr)) == NULL) {
|
||||
tdDestroyTSma(pSma);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} else {
|
||||
pSma->expr = NULL;
|
||||
}
|
||||
|
||||
if (pSma->tagsFilterLen > 0) {
|
||||
pSma->tagsFilter = (char*)calloc(pSma->tagsFilterLen, 1);
|
||||
if (pSma->tagsFilter != NULL) {
|
||||
buf = taosDecodeStringTo(buf, pSma->tagsFilter);
|
||||
} else {
|
||||
if ((buf = taosDecodeString(buf, &pSma->tagsFilter)) == NULL) {
|
||||
tdDestroyTSma(pSma);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} else {
|
||||
pSma->tagsFilter = NULL;
|
||||
}
|
||||
|
|
|
@ -34,128 +34,147 @@
|
|||
#define TK_NK_REM 16
|
||||
#define TK_NK_CONCAT 17
|
||||
#define TK_CREATE 18
|
||||
#define TK_USER 19
|
||||
#define TK_PASS 20
|
||||
#define TK_NK_STRING 21
|
||||
#define TK_ALTER 22
|
||||
#define TK_PRIVILEGE 23
|
||||
#define TK_DROP 24
|
||||
#define TK_SHOW 25
|
||||
#define TK_USERS 26
|
||||
#define TK_DNODE 27
|
||||
#define TK_PORT 28
|
||||
#define TK_NK_INTEGER 29
|
||||
#define TK_DNODES 30
|
||||
#define TK_NK_ID 31
|
||||
#define TK_NK_IPTOKEN 32
|
||||
#define TK_QNODE 33
|
||||
#define TK_ON 34
|
||||
#define TK_QNODES 35
|
||||
#define TK_DATABASE 36
|
||||
#define TK_DATABASES 37
|
||||
#define TK_USE 38
|
||||
#define TK_IF 39
|
||||
#define TK_NOT 40
|
||||
#define TK_EXISTS 41
|
||||
#define TK_BLOCKS 42
|
||||
#define TK_CACHE 43
|
||||
#define TK_CACHELAST 44
|
||||
#define TK_COMP 45
|
||||
#define TK_DAYS 46
|
||||
#define TK_FSYNC 47
|
||||
#define TK_MAXROWS 48
|
||||
#define TK_MINROWS 49
|
||||
#define TK_KEEP 50
|
||||
#define TK_PRECISION 51
|
||||
#define TK_QUORUM 52
|
||||
#define TK_REPLICA 53
|
||||
#define TK_TTL 54
|
||||
#define TK_WAL 55
|
||||
#define TK_VGROUPS 56
|
||||
#define TK_SINGLE_STABLE 57
|
||||
#define TK_STREAM_MODE 58
|
||||
#define TK_TABLE 59
|
||||
#define TK_NK_LP 60
|
||||
#define TK_NK_RP 61
|
||||
#define TK_STABLE 62
|
||||
#define TK_TABLES 63
|
||||
#define TK_STABLES 64
|
||||
#define TK_USING 65
|
||||
#define TK_TAGS 66
|
||||
#define TK_NK_DOT 67
|
||||
#define TK_NK_COMMA 68
|
||||
#define TK_COMMENT 69
|
||||
#define TK_BOOL 70
|
||||
#define TK_TINYINT 71
|
||||
#define TK_SMALLINT 72
|
||||
#define TK_INT 73
|
||||
#define TK_INTEGER 74
|
||||
#define TK_BIGINT 75
|
||||
#define TK_FLOAT 76
|
||||
#define TK_DOUBLE 77
|
||||
#define TK_BINARY 78
|
||||
#define TK_TIMESTAMP 79
|
||||
#define TK_NCHAR 80
|
||||
#define TK_UNSIGNED 81
|
||||
#define TK_JSON 82
|
||||
#define TK_VARCHAR 83
|
||||
#define TK_MEDIUMBLOB 84
|
||||
#define TK_BLOB 85
|
||||
#define TK_VARBINARY 86
|
||||
#define TK_DECIMAL 87
|
||||
#define TK_SMA 88
|
||||
#define TK_INDEX 89
|
||||
#define TK_FULLTEXT 90
|
||||
#define TK_FUNCTION 91
|
||||
#define TK_INTERVAL 92
|
||||
#define TK_TOPIC 93
|
||||
#define TK_AS 94
|
||||
#define TK_MNODES 95
|
||||
#define TK_NK_FLOAT 96
|
||||
#define TK_NK_BOOL 97
|
||||
#define TK_NK_VARIABLE 98
|
||||
#define TK_BETWEEN 99
|
||||
#define TK_IS 100
|
||||
#define TK_NULL 101
|
||||
#define TK_NK_LT 102
|
||||
#define TK_NK_GT 103
|
||||
#define TK_NK_LE 104
|
||||
#define TK_NK_GE 105
|
||||
#define TK_NK_NE 106
|
||||
#define TK_NK_EQ 107
|
||||
#define TK_LIKE 108
|
||||
#define TK_MATCH 109
|
||||
#define TK_NMATCH 110
|
||||
#define TK_IN 111
|
||||
#define TK_FROM 112
|
||||
#define TK_JOIN 113
|
||||
#define TK_INNER 114
|
||||
#define TK_SELECT 115
|
||||
#define TK_DISTINCT 116
|
||||
#define TK_WHERE 117
|
||||
#define TK_PARTITION 118
|
||||
#define TK_BY 119
|
||||
#define TK_SESSION 120
|
||||
#define TK_STATE_WINDOW 121
|
||||
#define TK_SLIDING 122
|
||||
#define TK_FILL 123
|
||||
#define TK_VALUE 124
|
||||
#define TK_NONE 125
|
||||
#define TK_PREV 126
|
||||
#define TK_LINEAR 127
|
||||
#define TK_NEXT 128
|
||||
#define TK_GROUP 129
|
||||
#define TK_HAVING 130
|
||||
#define TK_ORDER 131
|
||||
#define TK_SLIMIT 132
|
||||
#define TK_SOFFSET 133
|
||||
#define TK_LIMIT 134
|
||||
#define TK_OFFSET 135
|
||||
#define TK_ASC 136
|
||||
#define TK_DESC 137
|
||||
#define TK_NULLS 138
|
||||
#define TK_FIRST 139
|
||||
#define TK_LAST 140
|
||||
#define TK_ACCOUNT 19
|
||||
#define TK_NK_ID 20
|
||||
#define TK_PASS 21
|
||||
#define TK_NK_STRING 22
|
||||
#define TK_ALTER 23
|
||||
#define TK_PPS 24
|
||||
#define TK_TSERIES 25
|
||||
#define TK_STORAGE 26
|
||||
#define TK_STREAMS 27
|
||||
#define TK_QTIME 28
|
||||
#define TK_DBS 29
|
||||
#define TK_USERS 30
|
||||
#define TK_CONNS 31
|
||||
#define TK_STATE 32
|
||||
#define TK_USER 33
|
||||
#define TK_PRIVILEGE 34
|
||||
#define TK_DROP 35
|
||||
#define TK_SHOW 36
|
||||
#define TK_DNODE 37
|
||||
#define TK_PORT 38
|
||||
#define TK_NK_INTEGER 39
|
||||
#define TK_DNODES 40
|
||||
#define TK_NK_IPTOKEN 41
|
||||
#define TK_LOCAL 42
|
||||
#define TK_QNODE 43
|
||||
#define TK_ON 44
|
||||
#define TK_QNODES 45
|
||||
#define TK_DATABASE 46
|
||||
#define TK_DATABASES 47
|
||||
#define TK_USE 48
|
||||
#define TK_IF 49
|
||||
#define TK_NOT 50
|
||||
#define TK_EXISTS 51
|
||||
#define TK_BLOCKS 52
|
||||
#define TK_CACHE 53
|
||||
#define TK_CACHELAST 54
|
||||
#define TK_COMP 55
|
||||
#define TK_DAYS 56
|
||||
#define TK_FSYNC 57
|
||||
#define TK_MAXROWS 58
|
||||
#define TK_MINROWS 59
|
||||
#define TK_KEEP 60
|
||||
#define TK_PRECISION 61
|
||||
#define TK_QUORUM 62
|
||||
#define TK_REPLICA 63
|
||||
#define TK_TTL 64
|
||||
#define TK_WAL 65
|
||||
#define TK_VGROUPS 66
|
||||
#define TK_SINGLE_STABLE 67
|
||||
#define TK_STREAM_MODE 68
|
||||
#define TK_RETENTIONS 69
|
||||
#define TK_FILE_FACTOR 70
|
||||
#define TK_NK_FLOAT 71
|
||||
#define TK_TABLE 72
|
||||
#define TK_NK_LP 73
|
||||
#define TK_NK_RP 74
|
||||
#define TK_STABLE 75
|
||||
#define TK_TABLES 76
|
||||
#define TK_STABLES 77
|
||||
#define TK_ADD 78
|
||||
#define TK_COLUMN 79
|
||||
#define TK_MODIFY 80
|
||||
#define TK_RENAME 81
|
||||
#define TK_TAG 82
|
||||
#define TK_SET 83
|
||||
#define TK_NK_EQ 84
|
||||
#define TK_USING 85
|
||||
#define TK_TAGS 86
|
||||
#define TK_NK_DOT 87
|
||||
#define TK_NK_COMMA 88
|
||||
#define TK_COMMENT 89
|
||||
#define TK_BOOL 90
|
||||
#define TK_TINYINT 91
|
||||
#define TK_SMALLINT 92
|
||||
#define TK_INT 93
|
||||
#define TK_INTEGER 94
|
||||
#define TK_BIGINT 95
|
||||
#define TK_FLOAT 96
|
||||
#define TK_DOUBLE 97
|
||||
#define TK_BINARY 98
|
||||
#define TK_TIMESTAMP 99
|
||||
#define TK_NCHAR 100
|
||||
#define TK_UNSIGNED 101
|
||||
#define TK_JSON 102
|
||||
#define TK_VARCHAR 103
|
||||
#define TK_MEDIUMBLOB 104
|
||||
#define TK_BLOB 105
|
||||
#define TK_VARBINARY 106
|
||||
#define TK_DECIMAL 107
|
||||
#define TK_SMA 108
|
||||
#define TK_ROLLUP 109
|
||||
#define TK_INDEX 110
|
||||
#define TK_FULLTEXT 111
|
||||
#define TK_FUNCTION 112
|
||||
#define TK_INTERVAL 113
|
||||
#define TK_TOPIC 114
|
||||
#define TK_AS 115
|
||||
#define TK_MNODES 116
|
||||
#define TK_NK_BOOL 117
|
||||
#define TK_NK_VARIABLE 118
|
||||
#define TK_BETWEEN 119
|
||||
#define TK_IS 120
|
||||
#define TK_NULL 121
|
||||
#define TK_NK_LT 122
|
||||
#define TK_NK_GT 123
|
||||
#define TK_NK_LE 124
|
||||
#define TK_NK_GE 125
|
||||
#define TK_NK_NE 126
|
||||
#define TK_LIKE 127
|
||||
#define TK_MATCH 128
|
||||
#define TK_NMATCH 129
|
||||
#define TK_IN 130
|
||||
#define TK_FROM 131
|
||||
#define TK_JOIN 132
|
||||
#define TK_INNER 133
|
||||
#define TK_SELECT 134
|
||||
#define TK_DISTINCT 135
|
||||
#define TK_WHERE 136
|
||||
#define TK_PARTITION 137
|
||||
#define TK_BY 138
|
||||
#define TK_SESSION 139
|
||||
#define TK_STATE_WINDOW 140
|
||||
#define TK_SLIDING 141
|
||||
#define TK_FILL 142
|
||||
#define TK_VALUE 143
|
||||
#define TK_NONE 144
|
||||
#define TK_PREV 145
|
||||
#define TK_LINEAR 146
|
||||
#define TK_NEXT 147
|
||||
#define TK_GROUP 148
|
||||
#define TK_HAVING 149
|
||||
#define TK_ORDER 150
|
||||
#define TK_SLIMIT 151
|
||||
#define TK_SOFFSET 152
|
||||
#define TK_LIMIT 153
|
||||
#define TK_OFFSET 154
|
||||
#define TK_ASC 155
|
||||
#define TK_DESC 156
|
||||
#define TK_NULLS 157
|
||||
#define TK_FIRST 158
|
||||
#define TK_LAST 159
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -27,7 +27,7 @@ extern "C" {
|
|||
typedef int32_t VarDataOffsetT;
|
||||
typedef uint32_t TDRowLenT;
|
||||
typedef uint8_t TDRowValT;
|
||||
typedef uint16_t col_id_t;
|
||||
typedef int16_t col_id_t;
|
||||
typedef int8_t col_type_t;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
|
|
@ -31,7 +31,7 @@ typedef struct SVariant {
|
|||
uint64_t u;
|
||||
double d;
|
||||
char *pz;
|
||||
wchar_t *wpz;
|
||||
TdUcs4 *ucs4;
|
||||
SArray *arr; // only for 'in' query to hold value list, not value for a field
|
||||
};
|
||||
} SVariant;
|
||||
|
|
|
@ -127,6 +127,18 @@ typedef struct SDropSuperTableStmt {
|
|||
bool ignoreNotExists;
|
||||
} SDropSuperTableStmt;
|
||||
|
||||
typedef struct SAlterTableStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
int8_t alterType;
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
char newColName[TSDB_COL_NAME_LEN];
|
||||
STableOptions* pOptions;
|
||||
SDataType dataType;
|
||||
SValueNode* pVal;
|
||||
} SAlterTableStmt;
|
||||
|
||||
typedef struct SCreateUserStmt {
|
||||
ENodeType type;
|
||||
char useName[TSDB_USER_LEN];
|
||||
|
@ -158,6 +170,13 @@ typedef struct SDropDnodeStmt {
|
|||
int32_t port;
|
||||
} SDropDnodeStmt;
|
||||
|
||||
typedef struct SAlterDnodeStmt {
|
||||
ENodeType type;
|
||||
int32_t dnodeId;
|
||||
char config[TSDB_DNODE_CONFIG_LEN];
|
||||
char value[TSDB_DNODE_VALUE_LEN];
|
||||
} SAlterDnodeStmt;
|
||||
|
||||
typedef struct SShowStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
|
@ -215,6 +234,12 @@ typedef struct SDropTopicStmt {
|
|||
bool ignoreNotExists;
|
||||
} SDropTopicStmt;
|
||||
|
||||
typedef struct SAlterLocalStmt {
|
||||
ENodeType type;
|
||||
char config[TSDB_DNODE_CONFIG_LEN];
|
||||
char value[TSDB_DNODE_VALUE_LEN];
|
||||
} SAlterLocalStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -85,6 +85,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_DROP_TABLE_CLAUSE,
|
||||
QUERY_NODE_DROP_TABLE_STMT,
|
||||
QUERY_NODE_DROP_SUPER_TABLE_STMT,
|
||||
QUERY_NODE_ALTER_TABLE_STMT,
|
||||
QUERY_NODE_SHOW_TABLES_STMT, // temp
|
||||
QUERY_NODE_SHOW_STABLES_STMT,
|
||||
QUERY_NODE_CREATE_USER_STMT,
|
||||
|
@ -94,6 +95,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_USE_DATABASE_STMT,
|
||||
QUERY_NODE_CREATE_DNODE_STMT,
|
||||
QUERY_NODE_DROP_DNODE_STMT,
|
||||
QUERY_NODE_ALTER_DNODE_STMT,
|
||||
QUERY_NODE_SHOW_DNODES_STMT,
|
||||
QUERY_NODE_SHOW_VGROUPS_STMT,
|
||||
QUERY_NODE_SHOW_MNODES_STMT,
|
||||
|
@ -104,6 +106,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_DROP_QNODE_STMT,
|
||||
QUERY_NODE_CREATE_TOPIC_STMT,
|
||||
QUERY_NODE_DROP_TOPIC_STMT,
|
||||
QUERY_NODE_ALTER_LOCAL_STMT,
|
||||
|
||||
// logic plan node
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN,
|
||||
|
@ -163,6 +166,7 @@ SNodeList* nodesMakeList();
|
|||
int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode);
|
||||
int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode);
|
||||
int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc);
|
||||
int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc);
|
||||
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell);
|
||||
SNodeptr nodesListGetNode(SNodeList* pList, int32_t index);
|
||||
void nodesDestroyList(SNodeList* pList);
|
||||
|
|
|
@ -26,7 +26,6 @@ extern "C" {
|
|||
|
||||
typedef struct SLogicNode {
|
||||
ENodeType type;
|
||||
int32_t id;
|
||||
SNodeList* pTargets; // SColumnNode
|
||||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
|
@ -167,6 +166,7 @@ typedef struct SScanPhysiNode {
|
|||
|
||||
typedef SScanPhysiNode SSystemTableScanPhysiNode;
|
||||
typedef SScanPhysiNode STagScanPhysiNode;
|
||||
typedef SScanPhysiNode SStreamScanPhysiNode;
|
||||
|
||||
typedef struct STableScanPhysiNode {
|
||||
SScanPhysiNode scan;
|
||||
|
|
|
@ -23,6 +23,9 @@ extern "C" {
|
|||
#include "nodes.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags) * sizeof(SSchema)))
|
||||
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
|
||||
|
||||
typedef struct SRawExprNode {
|
||||
ENodeType nodeType;
|
||||
char* p;
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef struct SParseContext {
|
|||
uint64_t requestId;
|
||||
int32_t acctId;
|
||||
const char *db;
|
||||
bool streamQuery;
|
||||
void *pTransporter;
|
||||
SEpSet mgmtEpSet;
|
||||
const char *pSql; // sql string
|
||||
|
|
|
@ -49,6 +49,10 @@ typedef struct STableComInfo {
|
|||
int32_t rowSize; // row size of the schema
|
||||
} STableComInfo;
|
||||
|
||||
typedef struct SIndexMeta {
|
||||
|
||||
} SIndexMeta;
|
||||
|
||||
/*
|
||||
* ASSERT(sizeof(SCTableMeta) == 24)
|
||||
* ASSERT(tableType == TSDB_CHILD_TABLE)
|
||||
|
|
|
@ -22,15 +22,6 @@ extern "C" {
|
|||
|
||||
#include "osSocket.h"
|
||||
|
||||
#if defined(WINDOWS)
|
||||
typedef int32_t FileFd;
|
||||
typedef int32_t SocketFd;
|
||||
#else
|
||||
typedef int32_t FileFd;
|
||||
typedef int32_t SocketFd;
|
||||
#endif
|
||||
|
||||
int64_t taosRead(FileFd fd, void *buf, int64_t count);
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define open OPEN_FUNC_TAOS_FORBID
|
||||
|
@ -42,6 +33,7 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
|
|||
#define close CLOSE_FUNC_TAOS_FORBID
|
||||
#define fclose FCLOSE_FUNC_TAOS_FORBID
|
||||
#define fsync FSYNC_FUNC_TAOS_FORBID
|
||||
#define getline GETLINE_FUNC_TAOS_FORBID
|
||||
// #define fflush FFLUSH_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
|
@ -49,15 +41,6 @@ int64_t taosRead(FileFd fd, void *buf, int64_t count);
|
|||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
typedef int32_t FileFd;
|
||||
|
||||
typedef struct TdFile {
|
||||
pthread_rwlock_t rwlock;
|
||||
int refId;
|
||||
FileFd fd;
|
||||
FILE *fp;
|
||||
} * TdFilePtr, TdFile;
|
||||
|
||||
typedef struct TdFile *TdFilePtr;
|
||||
|
||||
#define TD_FILE_CTEATE 0x0001
|
||||
|
@ -95,10 +78,6 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
|||
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
|
||||
void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
|
||||
|
||||
#if defined(WINDOWS)
|
||||
#define __restrict__
|
||||
#endif // WINDOWS
|
||||
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict__ ptrBuf);
|
||||
|
||||
int32_t taosEOFFile(TdFilePtr pFile);
|
||||
|
@ -111,15 +90,7 @@ int32_t taosRemoveFile(const char *path);
|
|||
|
||||
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath);
|
||||
|
||||
#if defined(_TD_DARWIN_64)
|
||||
typedef int32_t SocketFd;
|
||||
|
||||
int64_t taosSendFile(SocketFd fdDst, FileFd pFileSrc, int64_t *offset, int64_t size);
|
||||
int64_t taosFSendFile(FILE *pFileOut, FILE *pFileIn, int64_t *offset, int64_t size);
|
||||
#else
|
||||
int64_t taosSendFile(SocketFd fdDst, TdFilePtr pFileSrc, int64_t *offset, int64_t size);
|
||||
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size);
|
||||
#endif
|
||||
|
||||
void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length);
|
||||
bool taosValidFile(TdFilePtr pFile);
|
||||
|
|
|
@ -20,16 +20,28 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef wchar_t TdWchar;
|
||||
typedef int32_t TdUcs4;
|
||||
|
||||
// If the error is in a third-party library, place this header file under the third-party library header file.
|
||||
#ifndef ALLOW_FORBID_FUNC
|
||||
#define iconv_open ICONV_OPEN_FUNC_TAOS_FORBID
|
||||
#define iconv_close ICONV_CLOSE_FUNC_TAOS_FORBID
|
||||
#define iconv ICONV_FUNC_TAOS_FORBID
|
||||
#define wcwidth WCWIDTH_FUNC_TAOS_FORBID
|
||||
#define wcswidth WCSWIDTH_FUNC_TAOS_FORBID
|
||||
#define mbtowc MBTOWC_FUNC_TAOS_FORBID
|
||||
#define mbstowcs MBSTOWCS_FUNC_TAOS_FORBID
|
||||
#define wctomb WCTOMB_FUNC_TAOS_FORBID
|
||||
#define wcstombs WCSTOMBS_FUNC_TAOS_FORBID
|
||||
#define wcsncpy WCSNCPY_FUNC_TAOS_FORBID
|
||||
#define wchar_t WCHAR_T_FUNC_TAOS_FORBID
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
#define tstrdup(str) _strdup(str)
|
||||
#define tstrndup(str, size) _strndup(str, size)
|
||||
int32_t tgetline(char **lineptr, size_t *n, FILE *stream);
|
||||
int32_t twcslen(const wchar_t *wcs);
|
||||
#else
|
||||
#define tstrdup(str) strdup(str)
|
||||
#define tstrndup(str, size) strndup(str, size)
|
||||
#define tgetline(lineptr, n, stream) getline(lineptr, n, stream)
|
||||
#define twcslen wcslen
|
||||
#endif
|
||||
|
||||
#define tstrncpy(dst, src, size) \
|
||||
|
@ -38,14 +50,22 @@ extern "C" {
|
|||
(dst)[(size)-1] = 0; \
|
||||
} while (0)
|
||||
|
||||
int32_t taosUcs4len(TdUcs4 *ucs4);
|
||||
int64_t taosStr2int64(const char *str);
|
||||
|
||||
// USE_LIBICONV
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncharSize);
|
||||
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs);
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len);
|
||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||
TdUcs4* tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
|
||||
int32_t taosWcharWidth(TdWchar wchar);
|
||||
int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size);
|
||||
int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size);
|
||||
int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size);
|
||||
int32_t taosWcharToMb(char *pStr, TdWchar wchar);
|
||||
int32_t taosWcharsToMbs(char *pStrs, TdWchar *pWchars, int32_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -482,6 +482,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_PASSWD_EMPTY TAOS_DEF_ERROR_CODE(0, 0x2611)
|
||||
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
|
||||
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
|
||||
#define TSDB_CODE_PAR_EXPRIE_STATEMENT TAOS_DEF_ERROR_CODE(0, 0x2614)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ typedef struct SPatternCompareInfo {
|
|||
|
||||
int32_t patternMatch(const char *pattern, const char *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
|
||||
int32_t WCSPatternMatch(const wchar_t *pattern, const wchar_t *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
int32_t WCSPatternMatch(const TdUcs4 *pattern, const TdUcs4 *str, size_t size, const SPatternCompareInfo *pInfo);
|
||||
|
||||
int32_t taosArrayCompareString(const void *a, const void *b);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define DOUBLE_BYTES sizeof(double)
|
||||
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
|
||||
#define TSDB_KEYSIZE sizeof(TSKEY)
|
||||
#define TSDB_NCHAR_SIZE sizeof(int32_t)
|
||||
#define TSDB_NCHAR_SIZE sizeof(TdUcs4)
|
||||
|
||||
// NULL definition
|
||||
#define TSDB_DATA_BOOL_NULL 0x02
|
||||
|
|
|
@ -44,6 +44,7 @@ int32_t tjsonGetIntValue(const SJson* pJson, const char* pName, int32_t* pVal);
|
|||
int32_t tjsonGetSmallIntValue(const SJson* pJson, const char* pName, int16_t* pVal);
|
||||
int32_t tjsonGetTinyIntValue(const SJson* pJson, const char* pName, int8_t* pVal);
|
||||
int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pVal);
|
||||
int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal);
|
||||
int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal);
|
||||
int32_t tjsonGetBoolValue(const SJson* pJson, const char* pName, bool* pVal);
|
||||
int32_t tjsonGetDoubleValue(const SJson* pJson, const char* pName, double* pVal);
|
||||
|
@ -60,6 +61,7 @@ int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void*
|
|||
typedef int32_t (*FToObject)(const SJson* pJson, void* pObj);
|
||||
|
||||
int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, void* pObj);
|
||||
int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, void** pObj, int32_t objSize);
|
||||
int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void* pArray, int32_t itemSize);
|
||||
|
||||
char* tjsonToString(const SJson* pJson);
|
||||
|
|
|
@ -179,6 +179,7 @@ typedef struct SRequestObj {
|
|||
uint64_t requestId;
|
||||
int32_t type; // request type
|
||||
STscObj* pTscObj;
|
||||
char* pDb;
|
||||
char* sqlstr; // sql string
|
||||
int32_t sqlLen;
|
||||
int64_t self;
|
||||
|
@ -229,7 +230,7 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
|
|||
|
||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery);
|
||||
int32_t parseSql(SRequestObj* pRequest, bool streamQuery, SQuery** pQuery);
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||
|
||||
// --- heartbeat
|
||||
|
|
|
@ -150,6 +150,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pRequest->pDb = getDbOfConnection(pObj);
|
||||
pRequest->requestId = generateRequestId();
|
||||
pRequest->metric.start = taosGetTimestampMs();
|
||||
|
||||
|
@ -180,6 +181,7 @@ static void doDestroyRequest(void *p) {
|
|||
tfree(pRequest->msgBuf);
|
||||
tfree(pRequest->sqlstr);
|
||||
tfree(pRequest->pInfo);
|
||||
tfree(pRequest->pDb);
|
||||
|
||||
doFreeReqResultInfo(&pRequest->body.resInfo);
|
||||
qDestroyQueryPlan(pRequest->body.pDag);
|
||||
|
|
|
@ -137,13 +137,14 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
|
||||
int32_t parseSql(SRequestObj* pRequest, bool streamQuery, SQuery** pQuery) {
|
||||
STscObj* pTscObj = pRequest->pTscObj;
|
||||
|
||||
SParseContext cxt = {
|
||||
.requestId = pRequest->requestId,
|
||||
.acctId = pTscObj->acctId,
|
||||
.db = getDbOfConnection(pTscObj),
|
||||
.db = pRequest->pDb,
|
||||
.streamQuery = streamQuery,
|
||||
.pSql = pRequest->sqlstr,
|
||||
.sqlLen = pRequest->sqlLen,
|
||||
.pMsg = pRequest->msgBuf,
|
||||
|
@ -154,7 +155,6 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
|
|||
cxt.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
int32_t code = catalogGetHandle(pTscObj->pAppInfo->clusterId, &cxt.pCatalog);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tfree(cxt.db);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,6 @@ int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery) {
|
|||
setResSchemaInfo(&pRequest->body.resInfo, (*pQuery)->pResSchema, (*pQuery)->numOfResCols);
|
||||
}
|
||||
|
||||
tfree(cxt.db);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -249,7 +248,7 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) {
|
|||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQuery), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, false, &pQuery), _return);
|
||||
|
||||
if (pQuery->directRpc) {
|
||||
CHECK_CODE_GOTO(execDdlQuery(pRequest, pQuery), _return);
|
||||
|
|
|
@ -482,38 +482,24 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
|||
}
|
||||
|
||||
tscDebug("start to create topic, %s", topicName);
|
||||
#if 0
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
||||
|
||||
pQueryNode->streamQuery = true;
|
||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||
CHECK_CODE_GOTO(parseSql(pRequest, true, &pQueryNode), _return);
|
||||
|
||||
// todo check for invalid sql statement and return with error code
|
||||
|
||||
SSchema* schema = NULL;
|
||||
int32_t numOfCols = 0;
|
||||
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag, NULL), _return);
|
||||
|
||||
pStr = qQueryPlanToString(pRequest->body.pDag);
|
||||
if (pStr == NULL) {
|
||||
goto _return;
|
||||
}
|
||||
CHECK_CODE_GOTO(nodesNodeToString(pQueryNode->pRoot, false, &pStr, NULL), _return);
|
||||
|
||||
/*printf("%s\n", pStr);*/
|
||||
|
||||
// The topic should be related to a database that the queried table is belonged to.
|
||||
SName name = {0};
|
||||
char dbName[TSDB_DB_FNAME_LEN] = {0};
|
||||
// tNameGetFullDbName(&((SQueryStmtInfo*)pQueryNode)->pTableMetaInfo[0]->name, dbName);
|
||||
|
||||
tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB);
|
||||
tNameFromString(&name, topicName, T_NAME_TABLE);
|
||||
SName name = { .acctId = pTscObj->acctId, .type = TSDB_TABLE_NAME_T };
|
||||
strcpy(name.dbname, pRequest->pDb);
|
||||
strcpy(name.tname, topicName);
|
||||
|
||||
SCMCreateTopicReq req = {
|
||||
.igExists = 1,
|
||||
.physicalPlan = (char*)pStr,
|
||||
.ast = (char*)pStr,
|
||||
.sql = (char*)sql,
|
||||
.logicalPlan = (char*)"no logic plan",
|
||||
};
|
||||
tNameExtractFullName(&name, req.name);
|
||||
|
||||
|
@ -536,7 +522,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
|||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||
|
||||
tsem_wait(&pRequest->body.rspSem);
|
||||
#endif
|
||||
|
||||
_return:
|
||||
qDestroyQuery(pQueryNode);
|
||||
/*if (sendInfo != NULL) {*/
|
||||
|
|
|
@ -1072,6 +1072,10 @@ void blockDataClearup(SSDataBlock* pDataBlock) {
|
|||
}
|
||||
|
||||
int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRows) {
|
||||
if (0 == numOfRows) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pColumn->info.type)) {
|
||||
char* tmp = realloc(pColumn->varmeta.offset, sizeof(int32_t) * numOfRows);
|
||||
if (tmp == NULL) {
|
||||
|
@ -1092,7 +1096,7 @@ int32_t blockDataEnsureColumnCapacity(SColumnInfoData* pColumn, uint32_t numOfRo
|
|||
|
||||
pColumn->nullbitmap = tmp;
|
||||
memset(pColumn->nullbitmap, 0, BitmapLen(numOfRows));
|
||||
|
||||
assert(pColumn->info.bytes);
|
||||
tmp = realloc(pColumn->pData, numOfRows * pColumn->info.bytes);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -1137,7 +1141,7 @@ void* blockDataDestroy(SSDataBlock* pBlock) {
|
|||
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
tfree(pBlock->pBlockAgg);
|
||||
tfree(pBlock);
|
||||
// tfree(pBlock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1190,7 +1194,7 @@ int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
int32_t len = colDataGetLength(pColData, rows);
|
||||
taosEncodeFixedI32(buf, len);
|
||||
tlen += taosEncodeFixedI32(buf, len);
|
||||
|
||||
tlen += taosEncodeBinary(buf, pColData->pData, len);
|
||||
}
|
||||
|
|
|
@ -199,8 +199,8 @@ void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uin
|
|||
case TSDB_DATA_TYPE_NCHAR: { // here we get the nchar length from raw binary bits length
|
||||
size_t lenInwchar = len / TSDB_NCHAR_SIZE;
|
||||
|
||||
pVar->wpz = calloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE);
|
||||
memcpy(pVar->wpz, pz, lenInwchar * TSDB_NCHAR_SIZE);
|
||||
pVar->ucs4 = calloc(1, (lenInwchar + 1) * TSDB_NCHAR_SIZE);
|
||||
memcpy(pVar->ucs4, pz, lenInwchar * TSDB_NCHAR_SIZE);
|
||||
pVar->nLen = (int32_t)len;
|
||||
|
||||
break;
|
||||
|
@ -343,7 +343,7 @@ int32_t taosVariantToString(SVariant *pVar, char *dst) {
|
|||
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
dst[0] = '\'';
|
||||
taosUcs4ToMbs(pVar->wpz, (twcslen(pVar->wpz) + 1) * TSDB_NCHAR_SIZE, dst + 1);
|
||||
taosUcs4ToMbs(pVar->ucs4, (taosUcs4len(pVar->ucs4) + 1) * TSDB_NCHAR_SIZE, dst + 1);
|
||||
int32_t len = (int32_t)strlen(dst);
|
||||
dst[len] = '\'';
|
||||
dst[len + 1] = 0;
|
||||
|
@ -384,7 +384,7 @@ static FORCE_INLINE int32_t convertToBoolImpl(char *pStr, int32_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t wcsconvertToBoolImpl(wchar_t *pstr, int32_t len) {
|
||||
static FORCE_INLINE int32_t wcsconvertToBoolImpl(TdUcs4 *pstr, int32_t len) {
|
||||
if ((wcsncasecmp(pstr, L"true", len) == 0) && (len == 4)) {
|
||||
return TSDB_TRUE;
|
||||
} else if (wcsncasecmp(pstr, L"false", len) == 0 && (len == 5)) {
|
||||
|
@ -412,11 +412,11 @@ static int32_t toBinary(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
pBuf = realloc(pBuf, newSize + 1);
|
||||
}
|
||||
|
||||
taosUcs4ToMbs(pVariant->wpz, (int32_t)newSize, pBuf);
|
||||
free(pVariant->wpz);
|
||||
taosUcs4ToMbs(pVariant->ucs4, (int32_t)newSize, pBuf);
|
||||
free(pVariant->ucs4);
|
||||
pBuf[newSize] = 0;
|
||||
} else {
|
||||
taosUcs4ToMbs(pVariant->wpz, (int32_t)newSize, *pDest);
|
||||
taosUcs4ToMbs(pVariant->ucs4, (int32_t)newSize, *pDest);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -460,8 +460,8 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
}
|
||||
|
||||
if (*pDest == pVariant->pz) {
|
||||
wchar_t *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE);
|
||||
bool ret = taosMbsToUcs4(pDst, nLen, (char *)pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL);
|
||||
TdUcs4 *pWStr = calloc(1, (nLen + 1) * TSDB_NCHAR_SIZE);
|
||||
bool ret = taosMbsToUcs4(pDst, nLen, pWStr, (nLen + 1) * TSDB_NCHAR_SIZE, NULL);
|
||||
if (!ret) {
|
||||
tfree(pWStr);
|
||||
return -1;
|
||||
|
@ -469,21 +469,21 @@ static int32_t toNchar(SVariant *pVariant, char **pDest, int32_t *pDestSize) {
|
|||
|
||||
// free the binary buffer in the first place
|
||||
if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
|
||||
free(pVariant->wpz);
|
||||
free(pVariant->ucs4);
|
||||
}
|
||||
|
||||
pVariant->wpz = pWStr;
|
||||
*pDestSize = twcslen(pVariant->wpz);
|
||||
pVariant->ucs4 = pWStr;
|
||||
*pDestSize = taosUcs4len(pVariant->ucs4);
|
||||
|
||||
// shrink the allocate memory, no need to check here.
|
||||
char *tmp = realloc(pVariant->wpz, (*pDestSize + 1) * TSDB_NCHAR_SIZE);
|
||||
char *tmp = realloc(pVariant->ucs4, (*pDestSize + 1) * TSDB_NCHAR_SIZE);
|
||||
assert(tmp != NULL);
|
||||
|
||||
pVariant->wpz = (wchar_t *)tmp;
|
||||
pVariant->ucs4 = (TdUcs4 *)tmp;
|
||||
} else {
|
||||
int32_t output = 0;
|
||||
|
||||
bool ret = taosMbsToUcs4(pDst, nLen, *pDest, (nLen + 1) * TSDB_NCHAR_SIZE, &output);
|
||||
bool ret = taosMbsToUcs4(pDst, nLen, (TdUcs4*)*pDest, (nLen + 1) * TSDB_NCHAR_SIZE, &output);
|
||||
if (!ret) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -554,7 +554,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
|
|||
*result = res;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
errno = 0;
|
||||
wchar_t *endPtr = NULL;
|
||||
TdUcs4 *endPtr = NULL;
|
||||
|
||||
SToken token = {0};
|
||||
token.n = tGetToken(pVariant->pz, &token.type);
|
||||
|
@ -564,7 +564,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
|
|||
}
|
||||
|
||||
if (token.type == TK_FLOAT) {
|
||||
double v = wcstod(pVariant->wpz, &endPtr);
|
||||
double v = wcstod(pVariant->ucs4, &endPtr);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
|
@ -583,7 +583,7 @@ static FORCE_INLINE int32_t convertToInteger(SVariant *pVariant, int64_t *result
|
|||
setNull((char *)result, type, tDataTypes[type].bytes);
|
||||
return 0;
|
||||
} else {
|
||||
int64_t val = wcstoll(pVariant->wpz, &endPtr, 10);
|
||||
int64_t val = wcstoll(pVariant->ucs4, &endPtr, 10);
|
||||
if (releaseVariantPtr) {
|
||||
free(pVariant->pz);
|
||||
pVariant->nLen = 0;
|
||||
|
@ -649,7 +649,7 @@ static int32_t convertToBool(SVariant *pVariant, int64_t *pDest) {
|
|||
*pDest = ret;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t ret = 0;
|
||||
if ((ret = wcsconvertToBoolImpl(pVariant->wpz, pVariant->nLen)) < 0) {
|
||||
if ((ret = wcsconvertToBoolImpl(pVariant->ucs4, pVariant->nLen)) < 0) {
|
||||
return ret;
|
||||
}
|
||||
*pDest = ret;
|
||||
|
@ -899,7 +899,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
wcsncpy((wchar_t *)payload, pVariant->wpz, pVariant->nLen);
|
||||
tasoUcs4Copy((TdUcs4*)payload, pVariant->ucs4, pVariant->nLen);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -913,7 +913,7 @@ int32_t tVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool inc
|
|||
return -1;
|
||||
}
|
||||
} else {
|
||||
memcpy(p, pVariant->wpz, pVariant->nLen);
|
||||
memcpy(p, pVariant->ucs4, pVariant->nLen);
|
||||
newlen = pVariant->nLen;
|
||||
}
|
||||
|
||||
|
@ -979,7 +979,7 @@ int32_t taosVariantTypeSetType(SVariant *pVariant, char type) {
|
|||
pVariant->d = v;
|
||||
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
|
||||
errno = 0;
|
||||
double v = wcstod(pVariant->wpz, NULL);
|
||||
double v = wcstod(pVariant->ucs4, NULL);
|
||||
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
|
||||
free(pVariant->pz);
|
||||
return -1;
|
||||
|
|
|
@ -26,8 +26,9 @@ typedef struct SDBFile SDBFile;
|
|||
typedef DB_ENV* TDBEnv;
|
||||
|
||||
struct SDBFile {
|
||||
DB* pDB;
|
||||
char* path;
|
||||
int32_t fid;
|
||||
DB* pDB;
|
||||
char* path;
|
||||
};
|
||||
|
||||
int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile* pDBF);
|
||||
|
|
|
@ -884,7 +884,7 @@ const char *metaSmaCursorNext(SMSmaCursor *pCur) {
|
|||
STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
||||
STSmaWrapper *pSW = NULL;
|
||||
|
||||
pSW = calloc(sizeof(*pSW), 1);
|
||||
pSW = calloc(1, sizeof(*pSW));
|
||||
if (pSW == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tdatablock.h"
|
||||
#include "vnode.h"
|
||||
|
||||
STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) {
|
||||
|
@ -128,10 +129,13 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
|||
|
||||
int j = 0;
|
||||
for (int32_t i = 0; i < colNumNeed; i++) {
|
||||
int32_t colId = *(int32_t*)taosArrayGet(pHandle->pColIdList, i);
|
||||
int16_t colId = *(int16_t*)taosArrayGet(pHandle->pColIdList, i);
|
||||
while (j < pSchemaWrapper->nCols && pSchemaWrapper->pSchema[j].colId < colId) {
|
||||
j++;
|
||||
}
|
||||
if (j >= pSchemaWrapper->nCols) {
|
||||
continue;
|
||||
}
|
||||
SSchema* pColSchema = &pSchemaWrapper->pSchema[j];
|
||||
SColumnInfoData colInfo = {0};
|
||||
int sz = numOfRows * pColSchema->bytes;
|
||||
|
@ -145,6 +149,8 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) {
|
|||
taosArrayDestroy(pArray);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
blockDataEnsureColumnCapacity(&colInfo, numOfRows);
|
||||
taosArrayPush(pArray, &colInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -3386,7 +3386,7 @@ void filterPrepare(void* expr, void* param) {
|
|||
if (size < (uint32_t)pSchema->bytes) {
|
||||
size = pSchema->bytes;
|
||||
}
|
||||
// to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(wchar_t) space.
|
||||
// to make sure tonchar does not cause invalid write, since the '\0' needs at least sizeof(TdUcs4) space.
|
||||
pInfo->q = calloc(1, size + TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
|
||||
tVariantDump(pCond, pInfo->q, pSchema->type, true);
|
||||
}
|
||||
|
|
|
@ -156,10 +156,6 @@ static int32_t tsdbInitSmaEnv(STsdb *pTsdb, const char *path, SSmaEnv **pEnv) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (*pEnv) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (*pEnv == NULL) {
|
||||
if ((*pEnv = tsdbNewSmaEnv(pTsdb, path)) == NULL) {
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -213,11 +209,14 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO: lock. lazy mode when update expired window, or hungry mode during tsdbNew.
|
||||
/**
|
||||
* 1. Lazy mode utilized when init SSmaStat to update expired window(or hungry mode when tsdbNew).
|
||||
* 2. Currently, there is mutex lock when init SSmaEnv, thus no need add lock on SSmaStat, and please add lock if
|
||||
* tsdbInitSmaStat invoked in other multithread environment later.
|
||||
*/
|
||||
if (*pSmaStat == NULL) {
|
||||
*pSmaStat = (SSmaStat *)calloc(1, sizeof(SSmaStat));
|
||||
if (*pSmaStat == NULL) {
|
||||
// TODO: unlock
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -227,11 +226,9 @@ static int32_t tsdbInitSmaStat(SSmaStat **pSmaStat) {
|
|||
|
||||
if ((*pSmaStat)->smaStatItems == NULL) {
|
||||
tfree(*pSmaStat);
|
||||
// TODO: unlock
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
// TODO: unlock
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -259,10 +256,15 @@ static SSmaStatItem *tsdbNewSmaStatItem(int8_t state) {
|
|||
int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
||||
if (pSmaStat) {
|
||||
// TODO: use taosHashSetFreeFp when taosHashSetFreeFp is ready.
|
||||
SSmaStatItem *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
|
||||
void *item = taosHashIterate(pSmaStat->smaStatItems, NULL);
|
||||
while (item != NULL) {
|
||||
tfree(item->pSma);
|
||||
taosHashCleanup(item->expiredWindows);
|
||||
SSmaStatItem *pItem = *(SSmaStatItem **)item;
|
||||
if (pItem != NULL) {
|
||||
tdDestroyTSma(pItem->pSma);
|
||||
tfree(pItem->pSma);
|
||||
taosHashCleanup(pItem->expiredWindows);
|
||||
tfree(pItem);
|
||||
}
|
||||
item = taosHashIterate(pSmaStat->smaStatItems, item);
|
||||
}
|
||||
taosHashCleanup(pSmaStat->smaStatItems);
|
||||
|
@ -270,15 +272,17 @@ int32_t tsdbDestroySmaState(SSmaStat *pSmaStat) {
|
|||
}
|
||||
|
||||
static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
||||
SSmaEnv *pEnv = NULL;
|
||||
|
||||
// return if already init
|
||||
switch (smaType) {
|
||||
case TSDB_SMA_TYPE_TIME_RANGE:
|
||||
if (pTsdb->pTSmaEnv) {
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&pTsdb->pTSmaEnv)) != NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case TSDB_SMA_TYPE_ROLLUP:
|
||||
if (pTsdb->pRSmaEnv) {
|
||||
if ((pEnv = (SSmaEnv *)atomic_load_ptr(&pTsdb->pRSmaEnv)) != NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
break;
|
||||
|
@ -289,9 +293,10 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
|
||||
// init sma env
|
||||
tsdbLockRepo(pTsdb);
|
||||
if (pTsdb->pTSmaEnv == NULL) {
|
||||
pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&pTsdb->pTSmaEnv) : atomic_load_ptr(&pTsdb->pRSmaEnv);
|
||||
if (pEnv == NULL) {
|
||||
char rname[TSDB_FILENAME_LEN] = {0};
|
||||
char aname[TSDB_FILENAME_LEN * 2 + 32] = {0}; // TODO: make TMPNAME_LEN public as TSDB_FILENAME_LEN?
|
||||
char aname[TSDB_FILENAME_LEN] = {0}; // use TSDB_FILENAME_LEN currently
|
||||
|
||||
SDiskID did = {0};
|
||||
tfsAllocDisk(pTsdb->pTfs, TFS_PRIMARY_LEVEL, &did);
|
||||
|
@ -307,17 +312,13 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSmaEnv *pEnv = NULL;
|
||||
if (tsdbInitSmaEnv(pTsdb, aname, &pEnv) != TSDB_CODE_SUCCESS) {
|
||||
tsdbUnlockRepo(pTsdb);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
if (smaType == TSDB_SMA_TYPE_TIME_RANGE) {
|
||||
pTsdb->pTSmaEnv = pEnv;
|
||||
} else {
|
||||
pTsdb->pRSmaEnv = pEnv;
|
||||
}
|
||||
(smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&pTsdb->pTSmaEnv, pEnv)
|
||||
: atomic_store_ptr(&pTsdb->pRSmaEnv, pEnv);
|
||||
}
|
||||
tsdbUnlockRepo(pTsdb);
|
||||
|
||||
|
@ -357,8 +358,10 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, ETsdbSmaType smaType, char *msg) {
|
|||
SSmaStat *pStat = SMA_ENV_STAT(pEnv);
|
||||
SHashObj *pItemsHash = SMA_ENV_STAT_ITEMS(pEnv);
|
||||
|
||||
TASSERT(pEnv != NULL && pStat != NULL && pItemsHash != NULL);
|
||||
|
||||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
SSmaStatItem *pItem = (SSmaStatItem *)taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||
SSmaStatItem *pItem = taosHashGet(pItemsHash, &indexUid, sizeof(indexUid));
|
||||
if (pItem == NULL) {
|
||||
pItem = tsdbNewSmaStatItem(TSDB_SMA_STAT_EXPIRED); // TODO use the real state
|
||||
if (pItem == NULL) {
|
||||
|
@ -419,9 +422,9 @@ static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, SSmaStat *pStat, int64_t ind
|
|||
tsdbRefSmaStat(pTsdb, pStat);
|
||||
|
||||
if (pStat && pStat->smaStatItems) {
|
||||
pItem = *(SSmaStatItem **)taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
pItem = taosHashGet(pStat->smaStatItems, &indexUid, sizeof(indexUid));
|
||||
}
|
||||
if (pItem != NULL) {
|
||||
if ((pItem != NULL) && ((pItem = *(SSmaStatItem **)pItem) != NULL)) {
|
||||
// pItem resides in hash buffer all the time unless drop sma index
|
||||
// TODO: multithread protect
|
||||
if (taosHashRemove(pItem->expiredWindows, &skey, sizeof(TSKEY)) != 0) {
|
||||
|
@ -492,7 +495,7 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
|
|||
* @brief Insert TSma data blocks to DB File build by B+Tree
|
||||
*
|
||||
* @param pSmaH
|
||||
* @param smaKey
|
||||
* @param smaKey tableUid-colId-skeyOfWindow(8-2-8)
|
||||
* @param keyLen
|
||||
* @param pData
|
||||
* @param dataLen
|
||||
|
@ -500,12 +503,11 @@ static int32_t tsdbGetSmaStorageLevel(int64_t interval, int8_t intervalUnit) {
|
|||
*/
|
||||
static int32_t tsdbInsertTSmaBlocks(STSmaWriteH *pSmaH, void *smaKey, uint32_t keyLen, void *pData, uint32_t dataLen) {
|
||||
SDBFile *pDBFile = &pSmaH->dFile;
|
||||
|
||||
// TODO: insert sma data blocks into B+Tree
|
||||
tsdbDebug("vgId:%d insert sma data blocks into %s: smaKey %" PRIx64 "-%" PRIu16 "-%" PRIx64 ", dataLen %d",
|
||||
REPO_ID(pSmaH->pTsdb), pDBFile->path, *(tb_uid_t *)smaKey, *(uint16_t *)POINTER_SHIFT(smaKey, 8),
|
||||
*(int64_t *)POINTER_SHIFT(smaKey, 10), dataLen);
|
||||
|
||||
// TODO: insert sma data blocks into B+Tree(TDB)
|
||||
if (tsdbSaveSmaToDB(pDBFile, smaKey, keyLen, pData, dataLen) != 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -562,34 +564,34 @@ static int64_t tsdbGetIntervalByPrecision(int64_t interval, uint8_t intervalUnit
|
|||
return interval / 1e3;
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||
return interval / 1e6;
|
||||
} else {
|
||||
} else { // ms
|
||||
return interval;
|
||||
}
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_MICRO:
|
||||
if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
|
||||
return interval;
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // ns
|
||||
return interval / 1e3;
|
||||
} else {
|
||||
} else { // ms
|
||||
return interval * 1e3;
|
||||
}
|
||||
break;
|
||||
case TSDB_TIME_PRECISION_NANO:
|
||||
if (TIME_UNIT_MICROSECOND == intervalUnit) {
|
||||
if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
|
||||
return interval * 1e3;
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // ns
|
||||
return interval;
|
||||
} else {
|
||||
} else { // ms
|
||||
return interval * 1e6;
|
||||
}
|
||||
break;
|
||||
default: // ms
|
||||
if (TIME_UNIT_MICROSECOND == intervalUnit) { // us
|
||||
return interval / 1e3;
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // nano second
|
||||
} else if (TIME_UNIT_NANOSECOND == intervalUnit) { // ns
|
||||
return interval / 1e6;
|
||||
} else {
|
||||
} else { // ms
|
||||
return interval;
|
||||
}
|
||||
break;
|
||||
|
@ -661,9 +663,13 @@ static void tsdbDestroyTSmaWriteH(STSmaWriteH *pSmaH) {
|
|||
static int32_t tsdbSetTSmaDataFile(STSmaWriteH *pSmaH, STSmaDataWrapper *pData, int32_t storageLevel, int32_t fid) {
|
||||
STsdb *pTsdb = pSmaH->pTsdb;
|
||||
ASSERT(pSmaH->dFile.path == NULL && pSmaH->dFile.pDB == NULL);
|
||||
|
||||
pSmaH->dFile.fid = fid;
|
||||
|
||||
char tSmaFile[TSDB_FILENAME_LEN] = {0};
|
||||
snprintf(tSmaFile, TSDB_FILENAME_LEN, "v%df%d.tsma", REPO_ID(pTsdb), fid);
|
||||
pSmaH->dFile.path = strdup(tSmaFile);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -703,7 +709,7 @@ static int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, char *msg) {
|
|||
STsdbCfg * pCfg = REPO_CFG(pTsdb);
|
||||
STSmaDataWrapper *pData = (STSmaDataWrapper *)msg;
|
||||
|
||||
if (!pTsdb->pTSmaEnv) {
|
||||
if (!atomic_load_ptr(&pTsdb->pTSmaEnv)) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d insert tSma data failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
return terrno;
|
||||
|
@ -881,15 +887,15 @@ static bool tsdbSetAndOpenTSmaFile(STSmaReadH *pReadH, TSKEY *queryKey) {
|
|||
static int32_t tsdbGetTSmaDataImpl(STsdb *pTsdb, STSmaDataWrapper *pData, int64_t indexUid, int64_t interval,
|
||||
int8_t intervalUnit, tb_uid_t tableUid, col_id_t colId, TSKEY querySKey,
|
||||
int32_t nMaxResult) {
|
||||
if (!pTsdb->pTSmaEnv) {
|
||||
if (!atomic_load_ptr(&pTsdb->pTSmaEnv)) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
tsdbWarn("vgId:%d getTSmaDataImpl failed since pTSmaEnv is NULL", REPO_ID(pTsdb));
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
tsdbRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
||||
SSmaStatItem *pItem = *(SSmaStatItem **)taosHashGet(SMA_ENV_STAT_ITEMS(pTsdb->pTSmaEnv), &indexUid, sizeof(indexUid));
|
||||
if (pItem == NULL) {
|
||||
SSmaStatItem *pItem = taosHashGet(SMA_ENV_STAT_ITEMS(pTsdb->pTSmaEnv), &indexUid, sizeof(indexUid));
|
||||
if ((pItem == NULL) || ((pItem = *(SSmaStatItem **)pItem) == NULL)) {
|
||||
// Normally pItem should not be NULL, mark all windows as expired and notify query module to fetch raw TS data if
|
||||
// it's NULL.
|
||||
tsdbUnRefSmaStat(pTsdb, SMA_ENV_STAT(pTsdb->pTSmaEnv));
|
||||
|
|
|
@ -144,6 +144,9 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
// record current timezone of server side
|
||||
tstrncpy(vCreateSmaReq.tSma.timezone, tsTimezone, TD_TIMEZONE_LEN);
|
||||
|
||||
if (metaCreateTSma(pVnode->pMeta, &vCreateSmaReq) < 0) {
|
||||
// TODO: handle error
|
||||
tdDestroyTSma(&vCreateSmaReq.tSma);
|
||||
|
|
|
@ -49,7 +49,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
|||
STSmaWrapper tSmaWrapper = {.number = 1, .tSma = &tSma};
|
||||
uint32_t bufLen = tEncodeTSmaWrapper(NULL, &tSmaWrapper);
|
||||
|
||||
void *buf = calloc(bufLen, 1);
|
||||
void *buf = calloc(1, bufLen);
|
||||
ASSERT_NE(buf, nullptr);
|
||||
|
||||
STSmaWrapper *pSW = (STSmaWrapper *)buf;
|
||||
|
@ -84,6 +84,7 @@ TEST(testCase, tSma_Meta_Encode_Decode_Test) {
|
|||
}
|
||||
|
||||
// resource release
|
||||
tfree(pSW);
|
||||
tdDestroyTSma(&tSma);
|
||||
tdDestroyTSmaWrapper(&dstTSmaWrapper);
|
||||
}
|
||||
|
@ -113,7 +114,7 @@ TEST(testCase, tSma_metaDB_Put_Get_Del_Test) {
|
|||
tSma.tableUid = tbUid;
|
||||
|
||||
tSma.exprLen = strlen(expr);
|
||||
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
||||
tSma.expr = (char *)calloc(1, tSma.exprLen + 1);
|
||||
ASSERT_NE(tSma.expr, nullptr);
|
||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||
|
||||
|
@ -251,12 +252,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
tSma.tableUid = tbUid;
|
||||
|
||||
tSma.exprLen = strlen(expr);
|
||||
tSma.expr = (char *)calloc(tSma.exprLen + 1, 1);
|
||||
tSma.expr = (char *)calloc(1, tSma.exprLen + 1);
|
||||
ASSERT_NE(tSma.expr, nullptr);
|
||||
tstrncpy(tSma.expr, expr, tSma.exprLen + 1);
|
||||
|
||||
tSma.tagsFilterLen = strlen(tagsFilter);
|
||||
tSma.tagsFilter = (char *)calloc(tSma.tagsFilterLen + 1, 1);
|
||||
tSma.tagsFilter = (char *)calloc(1, tSma.tagsFilterLen + 1);
|
||||
ASSERT_NE(tSma.tagsFilter, nullptr);
|
||||
tstrncpy(tSma.tagsFilter, tagsFilter, tSma.tagsFilterLen + 1);
|
||||
|
||||
|
@ -273,20 +274,20 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
|
||||
// step 2: insert data
|
||||
STSmaDataWrapper *pSmaData = NULL;
|
||||
STsdb tsdb = {0};
|
||||
STsdbCfg * pCfg = &tsdb.config;
|
||||
STsdb * pTsdb = (STsdb *)calloc(1, sizeof(STsdb));
|
||||
STsdbCfg * pCfg = &pTsdb->config;
|
||||
|
||||
tsdb.pMeta = pMeta;
|
||||
tsdb.vgId = 2;
|
||||
tsdb.config.daysPerFile = 10; // default days is 10
|
||||
tsdb.config.keep1 = 30;
|
||||
tsdb.config.keep2 = 90;
|
||||
tsdb.config.keep = 365;
|
||||
tsdb.config.precision = TSDB_TIME_PRECISION_MILLI;
|
||||
tsdb.config.update = TD_ROW_OVERWRITE_UPDATE;
|
||||
tsdb.config.compression = TWO_STAGE_COMP;
|
||||
pTsdb->pMeta = pMeta;
|
||||
pTsdb->vgId = 2;
|
||||
pTsdb->config.daysPerFile = 10; // default days is 10
|
||||
pTsdb->config.keep1 = 30;
|
||||
pTsdb->config.keep2 = 90;
|
||||
pTsdb->config.keep = 365;
|
||||
pTsdb->config.precision = TSDB_TIME_PRECISION_MILLI;
|
||||
pTsdb->config.update = TD_ROW_OVERWRITE_UPDATE;
|
||||
pTsdb->config.compression = TWO_STAGE_COMP;
|
||||
|
||||
switch (tsdb.config.precision) {
|
||||
switch (pTsdb->config.precision) {
|
||||
case TSDB_TIME_PRECISION_MILLI:
|
||||
skey1 *= 1e3;
|
||||
break;
|
||||
|
@ -304,12 +305,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
SDiskCfg pDisks = {.level = 0, .primary = 1};
|
||||
strncpy(pDisks.dir, "/var/lib/taos", TSDB_FILENAME_LEN);
|
||||
int32_t numOfDisks = 1;
|
||||
tsdb.pTfs = tfsOpen(&pDisks, numOfDisks);
|
||||
ASSERT_NE(tsdb.pTfs, nullptr);
|
||||
pTsdb->pTfs = tfsOpen(&pDisks, numOfDisks);
|
||||
ASSERT_NE(pTsdb->pTfs, nullptr);
|
||||
|
||||
char *msg = (char *)calloc(1, 100);
|
||||
ASSERT_NE(msg, nullptr);
|
||||
ASSERT_EQ(tsdbUpdateSmaWindow(&tsdb, TSDB_SMA_TYPE_TIME_RANGE, msg), 0);
|
||||
ASSERT_EQ(tsdbUpdateSmaWindow(pTsdb, TSDB_SMA_TYPE_TIME_RANGE, msg), 0);
|
||||
|
||||
// init
|
||||
int32_t allocCnt = 0;
|
||||
|
@ -367,13 +368,13 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
ASSERT_GE(bufSize, pSmaData->dataLen);
|
||||
|
||||
// execute
|
||||
ASSERT_EQ(tsdbInsertTSmaData(&tsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||
ASSERT_EQ(tsdbInsertTSmaData(pTsdb, (char *)pSmaData), TSDB_CODE_SUCCESS);
|
||||
|
||||
// step 3: query
|
||||
uint32_t checkDataCnt = 0;
|
||||
for (int32_t t = 0; t < numOfTables; ++t) {
|
||||
for (col_id_t c = 0; c < numOfCols; ++c) {
|
||||
ASSERT_EQ(tsdbGetTSmaData(&tsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
|
||||
ASSERT_EQ(tsdbGetTSmaData(pTsdb, NULL, indexUid1, interval1, intervalUnit1, tbUid + t,
|
||||
c + PRIMARYKEY_TIMESTAMP_COL_ID, skey1, 1),
|
||||
TSDB_CODE_SUCCESS);
|
||||
++checkDataCnt;
|
||||
|
@ -383,9 +384,12 @@ TEST(testCase, tSma_Data_Insert_Query_Test) {
|
|||
printf("%s:%d The sma data check count for insert and query is %" PRIu32 "\n", __FILE__, __LINE__, checkDataCnt);
|
||||
|
||||
// release data
|
||||
tfree(msg);
|
||||
taosTZfree(buf);
|
||||
// release meta
|
||||
tdDestroyTSma(&tSma);
|
||||
tfsClose(pTsdb->pTfs);
|
||||
tsdbClose(pTsdb);
|
||||
metaClose(pMeta);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2349,6 +2349,9 @@ _return:
|
|||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet *epSet) {
|
||||
|
||||
}
|
||||
|
||||
int32_t catalogRemoveDB(SCatalog* pCtg, const char* dbFName, uint64_t dbId) {
|
||||
CTG_API_ENTER();
|
||||
|
@ -2394,6 +2397,9 @@ _return:
|
|||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, const char *pIndexName, SIndexMeta** pIndexMeta) {
|
||||
|
||||
}
|
||||
|
||||
int32_t catalogGetTableMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) {
|
||||
CTG_API_ENTER();
|
||||
|
@ -2662,12 +2668,15 @@ _return:
|
|||
|
||||
int32_t catalogGetQnodeList(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, SArray* pQnodeList) {
|
||||
CTG_API_ENTER();
|
||||
|
||||
|
||||
int32_t code = 0;
|
||||
if (NULL == pCtg || NULL == pRpc || NULL == pMgmtEps || NULL == pQnodeList) {
|
||||
CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT);
|
||||
}
|
||||
|
||||
//TODO
|
||||
CTG_ERR_JRET(ctgGetQnodeListFromMnode(pCtg, pRpc, pMgmtEps, &pQnodeList));
|
||||
|
||||
_return:
|
||||
|
||||
CTG_API_LEAVE(TSDB_CODE_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -190,7 +190,6 @@ static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
|
|||
}
|
||||
|
||||
static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
|
||||
COPY_SCALAR_FIELD(id);
|
||||
CLONE_NODE_LIST_FIELD(pTargets);
|
||||
CLONE_NODE_FIELD(pConditions);
|
||||
CLONE_NODE_LIST_FIELD(pChildren);
|
||||
|
@ -198,7 +197,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
|
|||
}
|
||||
|
||||
static STableMeta* tableMetaClone(const STableMeta* pSrc) {
|
||||
int32_t len = sizeof(STableMeta) + (pSrc->tableInfo.numOfTags + pSrc->tableInfo.numOfColumns) * sizeof(SSchema);
|
||||
int32_t len = TABLE_META_SIZE(pSrc);
|
||||
STableMeta* pDst = malloc(len);
|
||||
if (NULL == pDst) {
|
||||
return NULL;
|
||||
|
@ -208,7 +207,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) {
|
|||
}
|
||||
|
||||
static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) {
|
||||
int32_t len = sizeof(SVgroupsInfo) + pSrc->numOfVgroups * sizeof(SVgroupInfo);
|
||||
int32_t len = VGROUPS_INFO_SIZE(pSrc);
|
||||
SVgroupsInfo* pDst = malloc(len);
|
||||
if (NULL == pDst) {
|
||||
return NULL;
|
||||
|
|
|
@ -193,7 +193,17 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkLogicPlanId = "Id";
|
||||
static int32_t jsonToTableMeta(const SJson* pJson, void* pObj) {
|
||||
STableMeta* pNode = (STableMeta*)pObj;
|
||||
|
||||
int32_t code = tjsonGetUBigIntValue(pJson, jkTableMetaUid, &pNode->uid);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUBigIntValue(pJson, jkTableMetaSuid, &pNode->suid);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkLogicPlanTargets = "Targets";
|
||||
static const char* jkLogicPlanConditions = "Conditions";
|
||||
static const char* jkLogicPlanChildren = "Children";
|
||||
|
@ -201,10 +211,7 @@ static const char* jkLogicPlanChildren = "Children";
|
|||
static int32_t logicPlanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SLogicNode* pNode = (const SLogicNode*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkLogicPlanId, pNode->id);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkLogicPlanTargets, pNode->pTargets);
|
||||
}
|
||||
int32_t code = nodeListToJson(pJson, jkLogicPlanTargets, pNode->pTargets);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkLogicPlanConditions, nodeToJson, pNode->pConditions);
|
||||
}
|
||||
|
@ -445,6 +452,14 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t physiStreamScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
return physiScanNodeToJson(pObj, pJson);
|
||||
}
|
||||
|
||||
static int32_t jsonToPhysiStreamScanNode(const SJson* pJson, void* pObj) {
|
||||
return jsonToPhysiScanNode(pJson, pObj);
|
||||
}
|
||||
|
||||
static const char* jkProjectPhysiPlanProjections = "Projections";
|
||||
|
||||
static int32_t physiProjectNodeToJson(const void* pObj, SJson* pJson) {
|
||||
|
@ -1273,6 +1288,193 @@ static int32_t jsonToFunctionNode(const SJson* pJson, void* pObj) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static const char* jkTableDbName = "DbName";
|
||||
static const char* jkTableTableName = "tableName";
|
||||
static const char* jkTableTableAlias = "tableAlias";
|
||||
|
||||
static int32_t tableNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const STableNode* pNode = (const STableNode*)pObj;
|
||||
|
||||
int32_t code = exprNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkTableDbName, pNode->dbName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkTableTableName, pNode->tableName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddStringToObject(pJson, jkTableTableAlias, pNode->tableAlias);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToTableNode(const SJson* pJson, void* pObj) {
|
||||
STableNode* pNode = (STableNode*)pObj;
|
||||
|
||||
int32_t code = jsonToExprNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkTableDbName, pNode->dbName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkTableTableName, pNode->tableName);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetStringValue(pJson, jkTableTableAlias, pNode->tableAlias);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkEpSetInUse = "InUse";
|
||||
static const char* jkEpSetNumOfEps = "NumOfEps";
|
||||
static const char* jkEpSetEps = "Eps";
|
||||
|
||||
static int32_t epSetToJson(const void* pObj, SJson* pJson) {
|
||||
const SEpSet* pNode = (const SEpSet*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkEpSetInUse, pNode->inUse);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkEpSetNumOfEps, pNode->numOfEps);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddArray(pJson, jkEpSetEps, epToJson, pNode->eps, sizeof(SEp), pNode->numOfEps);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToEpSet(const SJson* pJson, void* pObj) {
|
||||
SEpSet* pNode = (SEpSet*)pObj;
|
||||
|
||||
int32_t code = tjsonGetTinyIntValue(pJson, jkEpSetInUse, &pNode->inUse);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetTinyIntValue(pJson, jkEpSetNumOfEps, &pNode->numOfEps);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToArray(pJson, jkEpSetEps, jsonToEp, pNode->eps, sizeof(SEp));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkVgroupInfoVgId = "VgId";
|
||||
static const char* jkVgroupInfoHashBegin = "HashBegin";
|
||||
static const char* jkVgroupInfoHashEnd = "HashEnd";
|
||||
static const char* jkVgroupInfoEpSet = "EpSet";
|
||||
static const char* jkVgroupInfoNumOfTable = "NumOfTable";
|
||||
|
||||
static int32_t vgroupInfoToJson(const void* pObj, SJson* pJson) {
|
||||
const SVgroupInfo* pNode = (const SVgroupInfo*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupInfoVgId, pNode->vgId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashBegin, pNode->hashBegin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkVgroupInfoHashEnd, pNode->hashEnd);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkVgroupInfoEpSet, epSetToJson, &pNode->epSet);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkVgroupInfoNumOfTable, pNode->numOfTable);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToVgroupInfo(const SJson* pJson, void* pObj) {
|
||||
SVgroupInfo* pNode = (SVgroupInfo*)pObj;
|
||||
|
||||
int32_t code = tjsonGetIntValue(pJson, jkVgroupInfoVgId, &pNode->vgId);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUIntValue(pJson, jkVgroupInfoHashBegin, &pNode->hashBegin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUIntValue(pJson, jkVgroupInfoHashEnd, &pNode->hashEnd);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToObject(pJson, jkVgroupInfoEpSet, jsonToEpSet, &pNode->epSet);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkVgroupInfoNumOfTable, &pNode->numOfTable);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkVgroupsInfoNum = "Num";
|
||||
static const char* jkVgroupsInfoVgroups = "Vgroups";
|
||||
|
||||
static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) {
|
||||
const SVgroupsInfo* pNode = (const SVgroupsInfo*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkVgroupsInfoNum, pNode->numOfVgroups);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddArray(pJson, jkVgroupsInfoVgroups, vgroupInfoToJson, pNode->vgroups, sizeof(SVgroupInfo), pNode->numOfVgroups);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToVgroupsInfo(const SJson* pJson, void* pObj) {
|
||||
SVgroupsInfo* pNode = (SVgroupsInfo*)pObj;
|
||||
|
||||
int32_t code = tjsonGetIntValue(pJson, jkVgroupsInfoNum, &pNode->numOfVgroups);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonToArray(pJson, jkVgroupsInfoVgroups, jsonToVgroupInfo, pNode->vgroups, sizeof(SVgroupInfo));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkRealTableMetaSize = "MetaSize";
|
||||
static const char* jkRealTableMeta = "Meta";
|
||||
static const char* jkRealTableVgroupsInfoSize = "VgroupsInfoSize";
|
||||
static const char* jkRealTableVgroupsInfo = "VgroupsInfo";
|
||||
|
||||
static int32_t realTableNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SRealTableNode* pNode = (const SRealTableNode*)pObj;
|
||||
|
||||
int32_t code = tableNodeToJson(pObj, pJson);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkRealTableMetaSize, TABLE_META_SIZE(pNode->pMeta));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkRealTableMeta, tableMetaToJson, pNode->pMeta);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkRealTableVgroupsInfoSize, VGROUPS_INFO_SIZE(pNode->pVgroupList));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkRealTableVgroupsInfo, vgroupsInfoToJson, pNode->pVgroupList);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToRealTableNode(const SJson* pJson, void* pObj) {
|
||||
SRealTableNode* pNode = (SRealTableNode*)pObj;
|
||||
|
||||
int32_t objSize = 0;
|
||||
int32_t code = jsonToTableNode(pJson, pObj);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkRealTableMetaSize, &objSize);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonMakeObject(pJson, jkRealTableMeta, jsonToTableMeta, (void**)&pNode->pMeta, objSize);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetIntValue(pJson, jkRealTableVgroupsInfoSize, &objSize);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonMakeObject(pJson, jkRealTableVgroupsInfo, jsonToVgroupsInfo, (void**)&pNode->pVgroupList, objSize);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static const char* jkGroupingSetType = "GroupingSetType";
|
||||
static const char* jkGroupingSetParameter = "Parameters";
|
||||
|
||||
|
@ -1464,7 +1666,7 @@ static const char* jkSelectStmtSlimit = "Slimit";
|
|||
static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
||||
const SSelectStmt* pNode = (const SSelectStmt*)pObj;
|
||||
|
||||
int32_t code = tjsonAddIntegerToObject(pJson, jkSelectStmtDistinct, pNode->isDistinct);
|
||||
int32_t code = tjsonAddBoolToObject(pJson, jkSelectStmtDistinct, pNode->isDistinct);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkSelectStmtProjections, pNode->pProjectionList);
|
||||
}
|
||||
|
@ -1499,6 +1701,44 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
|
||||
SSelectStmt* pNode = (SSelectStmt*)pObj;
|
||||
|
||||
int32_t code = tjsonGetBoolValue(pJson, jkSelectStmtDistinct, &pNode->isDistinct);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSelectStmtProjections, &pNode->pProjectionList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtFrom, &pNode->pFromTable);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtWhere, &pNode->pWhere);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSelectStmtPartitionBy, &pNode->pPartitionByList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtWindow, &pNode->pWindow);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSelectStmtGroupBy, &pNode->pGroupByList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtHaving, &pNode->pHaving);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkSelectStmtOrderBy, &pNode->pOrderByList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtLimit, &pNode->pLimit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkSelectStmtSlimit, &pNode->pSlimit);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
||||
switch (nodeType(pObj)) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
|
@ -1512,6 +1752,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_FUNCTION:
|
||||
return functionNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
return realTableNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
case QUERY_NODE_JOIN_TABLE:
|
||||
break;
|
||||
|
@ -1565,9 +1806,8 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
return physiTagScanNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||
return physiTableScanNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
break;
|
||||
return physiStreamScanNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return physiProjectNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
|
@ -1589,6 +1829,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
return planToJson(pObj, pJson);
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
nodesWarn("specificNodeToJson unknown node = %s", nodesNodeName(nodeType(pObj)));
|
||||
|
@ -1607,7 +1848,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToLogicConditionNode(pJson, pObj);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return jsonToFunctionNode(pJson, pObj);
|
||||
// case QUERY_NODE_REAL_TABLE:
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
return jsonToRealTableNode(pJson, pObj);
|
||||
// case QUERY_NODE_TEMP_TABLE:
|
||||
// case QUERY_NODE_JOIN_TABLE:
|
||||
// break;
|
||||
|
@ -1633,8 +1875,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToDownstreamSourceNode(pJson, pObj);
|
||||
// case QUERY_NODE_SET_OPERATOR:
|
||||
// break;
|
||||
// case QUERY_NODE_SELECT_STMT:
|
||||
// return jsonToSelectStmt(pJson, pObj);
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return jsonToSelectStmt(pJson, pObj);
|
||||
// case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
// return jsonToLogicScanNode(pJson, pObj);
|
||||
// case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -1647,6 +1889,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
return jsonToPhysiTagScanNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||
return jsonToPhysiTableScanNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
return jsonToPhysiStreamScanNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return jsonToPhysiProjectNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
|
@ -1768,6 +2012,7 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
|
|||
int32_t code = makeNodeByJson(pJson, pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = NULL;
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -125,6 +125,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SCreateDnodeStmt));
|
||||
case QUERY_NODE_DROP_DNODE_STMT:
|
||||
return makeNode(type, sizeof(SDropDnodeStmt));
|
||||
case QUERY_NODE_ALTER_DNODE_STMT:
|
||||
return makeNode(type, sizeof(SAlterDnodeStmt));
|
||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_SHOW_VGROUPS_STMT:
|
||||
|
@ -168,7 +170,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||
return makeNode(type, sizeof(STableSeqScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
return makeNode(type, sizeof(SStreamScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return makeNode(type, sizeof(SProjectPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
|
@ -357,6 +359,17 @@ int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc) {
|
||||
if (NULL == pSrc) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
int32_t code = nodesListAppendList(pTarget, pSrc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(pSrc);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
SListCell* nodesListErase(SNodeList* pList, SListCell* pCell) {
|
||||
if (NULL == pCell->pPrev) {
|
||||
pList->pHead = pCell->pNext;
|
||||
|
@ -571,7 +584,7 @@ typedef struct SCollectFuncsCxt {
|
|||
static EDealRes collectFuncs(SNode* pNode, void* pContext) {
|
||||
SCollectFuncsCxt* pCxt = (SCollectFuncsCxt*)pContext;
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId)) {
|
||||
pCxt->errCode = nodesListAppend(pCxt->pFuncs, pNode);
|
||||
pCxt->errCode = nodesListStrictAppend(pCxt->pFuncs, nodesCloneNode(pNode));
|
||||
return (TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_IGNORE_CHILD : DEAL_RES_ERROR);
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
|
|
|
@ -50,8 +50,10 @@ typedef enum EDatabaseOptionType {
|
|||
DB_OPTION_TTL,
|
||||
DB_OPTION_WAL,
|
||||
DB_OPTION_VGROUPS,
|
||||
DB_OPTION_SINGLESTABLE,
|
||||
DB_OPTION_STREAMMODE,
|
||||
DB_OPTION_SINGLE_STABLE,
|
||||
DB_OPTION_STREAM_MODE,
|
||||
DB_OPTION_RETENTIONS,
|
||||
DB_OPTION_FILE_FACTOR,
|
||||
|
||||
DB_OPTION_MAX
|
||||
} EDatabaseOptionType;
|
||||
|
@ -65,6 +67,11 @@ typedef enum ETableOptionType {
|
|||
TABLE_OPTION_MAX
|
||||
} ETableOptionType;
|
||||
|
||||
typedef struct SAlterOption {
|
||||
int32_t type;
|
||||
SToken val;
|
||||
} SAlterOption;
|
||||
|
||||
extern SToken nil_token;
|
||||
|
||||
void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt);
|
||||
|
@ -110,13 +117,16 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
|
|||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
|
||||
|
||||
SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
|
||||
SNode* createDefaultAlterDatabaseOptions(SAstCreateContext* pCxt);
|
||||
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal);
|
||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pDbName, SNode* pOptions);
|
||||
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pDbName);
|
||||
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName, SNode* pOptions);
|
||||
SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
|
||||
SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt);
|
||||
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal);
|
||||
SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pSma);
|
||||
SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pFuncs);
|
||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment);
|
||||
SDataType createDataType(uint8_t type);
|
||||
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
|
||||
|
@ -126,6 +136,11 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables
|
|||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
|
||||
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType);
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName);
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName);
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal);
|
||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName);
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDbName);
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword);
|
||||
|
@ -133,6 +148,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int
|
|||
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName);
|
||||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort);
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode);
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue);
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions);
|
||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset, SNode* pSliding);
|
||||
SNode* createDropIndexStmt(SAstCreateContext* pCxt, const SToken* pIndexName, const SToken* pTableName);
|
||||
|
@ -140,6 +156,7 @@ SNode* createCreateQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
|
|||
SNode* createDropQnodeStmt(SAstCreateContext* pCxt, const SToken* pDnodeId);
|
||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery, const SToken* pSubscribeDbName);
|
||||
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
||||
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,13 +21,15 @@
|
|||
#include "parAst.h"
|
||||
}
|
||||
|
||||
%syntax_error {
|
||||
if(TOKEN.z) {
|
||||
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
|
||||
} else {
|
||||
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
|
||||
%syntax_error {
|
||||
if (pCxt->valid) {
|
||||
if(TOKEN.z) {
|
||||
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
|
||||
} else {
|
||||
generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
|
||||
}
|
||||
pCxt->valid = false;
|
||||
}
|
||||
pCxt->valid = false;
|
||||
}
|
||||
|
||||
%left OR.
|
||||
|
@ -41,6 +43,41 @@
|
|||
%left NK_CONCAT.
|
||||
//%right NK_BITNOT.
|
||||
|
||||
/************************************************ create/alter account *****************************************/
|
||||
cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||
cmd ::= ALTER ACCOUNT NK_ID alter_account_options. { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||
|
||||
%type account_options { int32_t }
|
||||
%destructor account_options { }
|
||||
account_options ::= . { }
|
||||
account_options ::= account_options PPS literal. { }
|
||||
account_options ::= account_options TSERIES literal. { }
|
||||
account_options ::= account_options STORAGE literal. { }
|
||||
account_options ::= account_options STREAMS literal. { }
|
||||
account_options ::= account_options QTIME literal. { }
|
||||
account_options ::= account_options DBS literal. { }
|
||||
account_options ::= account_options USERS literal. { }
|
||||
account_options ::= account_options CONNS literal. { }
|
||||
account_options ::= account_options STATE literal. { }
|
||||
|
||||
%type alter_account_options { int32_t }
|
||||
%destructor alter_account_options { }
|
||||
alter_account_options ::= alter_account_option. { }
|
||||
alter_account_options ::= alter_account_options alter_account_option. { }
|
||||
|
||||
%type alter_account_option { int32_t }
|
||||
%destructor alter_account_option { }
|
||||
alter_account_option ::= PASS literal. { }
|
||||
alter_account_option ::= PPS literal. { }
|
||||
alter_account_option ::= TSERIES literal. { }
|
||||
alter_account_option ::= STORAGE literal. { }
|
||||
alter_account_option ::= STREAMS literal. { }
|
||||
alter_account_option ::= QTIME literal. { }
|
||||
alter_account_option ::= DBS literal. { }
|
||||
alter_account_option ::= USERS literal. { }
|
||||
alter_account_option ::= CONNS literal. { }
|
||||
alter_account_option ::= STATE literal. { }
|
||||
|
||||
/************************************************ create/alter/drop/show user *****************************************/
|
||||
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); }
|
||||
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); }
|
||||
|
@ -48,12 +85,16 @@ cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B).
|
|||
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
|
||||
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
|
||||
|
||||
/************************************************ create/drop/show dnode **********************************************/
|
||||
/************************************************ create/drop/alter/show dnode ****************************************/
|
||||
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
|
||||
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
|
||||
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
|
||||
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
|
||||
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
|
||||
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, NULL); }
|
||||
cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B) NK_STRING(C). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, &C); }
|
||||
cmd ::= ALTER ALL DNODES NK_STRING(A). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, NULL); }
|
||||
cmd ::= ALTER ALL DNODES NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, &B); }
|
||||
|
||||
%type dnode_endpoint { SToken }
|
||||
%destructor dnode_endpoint { }
|
||||
|
@ -64,9 +105,13 @@ dnode_endpoint(A) ::= NK_STRING(B).
|
|||
dnode_host_name(A) ::= NK_ID(B). { A = B; }
|
||||
dnode_host_name(A) ::= NK_IPTOKEN(B). { A = B; }
|
||||
|
||||
/************************************************ alter local *********************************************************/
|
||||
cmd ::= ALTER LOCAL NK_STRING(A). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, NULL); }
|
||||
cmd ::= ALTER LOCAL NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, &B); }
|
||||
|
||||
/************************************************ create/drop qnode ***************************************************/
|
||||
cmd ::= CREATE QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateQnodeStmt(pCxt, &A); }
|
||||
cmd ::= DROP QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropQnodeStmt(pCxt, &A); }
|
||||
cmd ::= DROP QNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropQnodeStmt(pCxt, &A); }
|
||||
cmd ::= SHOW QNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT, NULL); }
|
||||
|
||||
/************************************************ create/drop/show/use database ***************************************/
|
||||
|
@ -74,7 +119,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 ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
|
||||
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); }
|
||||
cmd ::= ALTER DATABASE db_name(A) db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); }
|
||||
cmd ::= ALTER DATABASE db_name(A) alter_db_options(B). { pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &A, B); }
|
||||
|
||||
%type not_exists_opt { bool }
|
||||
%destructor not_exists_opt { }
|
||||
|
@ -102,20 +147,55 @@ db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C).
|
|||
db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_TTL, &C); }
|
||||
db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_WAL, &C); }
|
||||
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
|
||||
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLESTABLE, &C); }
|
||||
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAMMODE, &C); }
|
||||
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); }
|
||||
db_options(A) ::= db_options(B) STREAM_MODE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STREAM_MODE, &C); }
|
||||
db_options(A) ::= db_options(B) RETENTIONS NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, &C); }
|
||||
db_options(A) ::= db_options(B) FILE_FACTOR NK_FLOAT(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FILE_FACTOR, &C); }
|
||||
|
||||
alter_db_options(A) ::= alter_db_option(B). { A = createDefaultAlterDatabaseOptions(pCxt); A = setDatabaseOption(pCxt, A, B.type, &B.val); }
|
||||
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseOption(pCxt, B, C.type, &C.val); }
|
||||
|
||||
%type alter_db_option { SAlterOption }
|
||||
%destructor alter_db_option { }
|
||||
alter_db_option(A) ::= BLOCKS NK_INTEGER(B). { A.type = DB_OPTION_BLOCKS; A.val = B; }
|
||||
alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; }
|
||||
alter_db_option(A) ::= KEEP NK_INTEGER(B). { A.type = DB_OPTION_KEEP; A.val = B; }
|
||||
alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; }
|
||||
alter_db_option(A) ::= QUORUM NK_INTEGER(B). { A.type = DB_OPTION_QUORUM; A.val = B; }
|
||||
alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.val = B; }
|
||||
|
||||
/************************************************ create/drop/show table/stable ***************************************/
|
||||
cmd ::= CREATE TABLE not_exists_opt(A) full_table_name(B)
|
||||
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
|
||||
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A);}
|
||||
NK_LP column_def_list(C) NK_RP tags_def_opt(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); }
|
||||
cmd ::= CREATE TABLE multi_create_clause(A). { pCxt->pRootNode = createCreateMultiTableStmt(pCxt, A); }
|
||||
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
|
||||
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
|
||||
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); }
|
||||
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
|
||||
cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
|
||||
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
|
||||
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
|
||||
|
||||
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
||||
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
||||
|
||||
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableOption(pCxt, B, C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) ADD COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D); }
|
||||
alter_table_clause(A) ::= full_table_name(B) DROP COLUMN column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_COLUMN, &C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) MODIFY COLUMN column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &C, D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) RENAME COLUMN column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &C, &D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) ADD TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_ADD_TAG, &C, D); }
|
||||
alter_table_clause(A) ::= full_table_name(B) DROP TAG column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_TAG, &C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) MODIFY TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &C, D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) SET TAG column_name(C) NK_EQ literal(D). { A = createAlterTableSetTag(pCxt, B, &C, D); }
|
||||
|
||||
%type multi_create_clause { SNodeList* }
|
||||
%destructor multi_create_clause { nodesDestroyList($$); }
|
||||
multi_create_clause(A) ::= create_subtable_clause(B). { A = createNodeList(pCxt, B); }
|
||||
|
@ -183,11 +263,21 @@ tags_def_opt(A) ::= tags_def(B).
|
|||
%destructor tags_def { nodesDestroyList($$); }
|
||||
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
|
||||
|
||||
table_options(A) ::= . { A = createDefaultTableOptions(pCxt);}
|
||||
table_options(A) ::= . { A = createDefaultTableOptions(pCxt); }
|
||||
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { A = setTableOption(pCxt, B, TABLE_OPTION_COMMENT, &C); }
|
||||
table_options(A) ::= table_options(B) KEEP NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_KEEP, &C); }
|
||||
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
|
||||
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableSmaOption(pCxt, B, C); }
|
||||
table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableRollupOption(pCxt, B, C); }
|
||||
|
||||
alter_table_options(A) ::= alter_table_option(B). { A = createDefaultAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); }
|
||||
alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableOption(pCxt, B, C.type, &C.val); }
|
||||
|
||||
%type alter_table_option { SAlterOption }
|
||||
%destructor alter_table_option { }
|
||||
alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.val = B; }
|
||||
alter_table_option(A) ::= KEEP NK_INTEGER(B). { A.type = TABLE_OPTION_KEEP; A.val = B; }
|
||||
alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.val = B; }
|
||||
|
||||
%type col_name_list { SNodeList* }
|
||||
%destructor col_name_list { nodesDestroyList($$); }
|
||||
|
@ -196,6 +286,13 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C).
|
|||
|
||||
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
|
||||
|
||||
%type func_name_list { SNodeList* }
|
||||
%destructor func_name_list { nodesDestroyList($$); }
|
||||
func_name_list(A) ::= func_name(B). { A = createNodeList(pCxt, B); }
|
||||
func_name_list(A) ::= func_name_list(B) NK_COMMA col_name(C). { A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
func_name(A) ::= function_name(B). { A = createFunctionNode(pCxt, &B, NULL); }
|
||||
|
||||
/************************************************ create index ********************************************************/
|
||||
cmd ::= CREATE SMA INDEX index_name(A) ON table_name(B) index_options(C). { pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, &A, &B, NULL, C); }
|
||||
cmd ::= CREATE FULLTEXT INDEX
|
||||
|
@ -546,7 +643,7 @@ query_expression_body(A) ::=
|
|||
query_primary(A) ::= query_specification(B). { A = B; }
|
||||
//query_primary(A) ::=
|
||||
// NK_LP query_expression_body(B)
|
||||
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B;}
|
||||
// order_by_clause_opt slimit_clause_opt limit_clause_opt NK_RP. { A = B; }
|
||||
|
||||
%type order_by_clause_opt { SNodeList* }
|
||||
%destructor order_by_clause_opt { nodesDestroyList($$); }
|
||||
|
|
|
@ -246,6 +246,16 @@ static SDatabaseOptions* setDbStreamMode(SAstCreateContext* pCxt, SDatabaseOptio
|
|||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbRetentions(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
// todo
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static SDatabaseOptions* setDbFileFactor(SAstCreateContext* pCxt, SDatabaseOptions* pOptions, const SToken* pVal) {
|
||||
// todo
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
static void initSetDatabaseOptionFp() {
|
||||
setDbOptionFuncs[DB_OPTION_BLOCKS] = setDbBlocks;
|
||||
setDbOptionFuncs[DB_OPTION_CACHE] = setDbCache;
|
||||
|
@ -262,8 +272,10 @@ static void initSetDatabaseOptionFp() {
|
|||
setDbOptionFuncs[DB_OPTION_TTL] = setDbTtl;
|
||||
setDbOptionFuncs[DB_OPTION_WAL] = setDbWal;
|
||||
setDbOptionFuncs[DB_OPTION_VGROUPS] = setDbVgroups;
|
||||
setDbOptionFuncs[DB_OPTION_SINGLESTABLE] = setDbSingleStable;
|
||||
setDbOptionFuncs[DB_OPTION_STREAMMODE] = setDbStreamMode;
|
||||
setDbOptionFuncs[DB_OPTION_SINGLE_STABLE] = setDbSingleStable;
|
||||
setDbOptionFuncs[DB_OPTION_STREAM_MODE] = setDbStreamMode;
|
||||
setDbOptionFuncs[DB_OPTION_RETENTIONS] = setDbRetentions;
|
||||
setDbOptionFuncs[DB_OPTION_FILE_FACTOR] = setDbFileFactor;
|
||||
}
|
||||
|
||||
static STableOptions* setTableKeep(SAstCreateContext* pCxt, STableOptions* pOptions, const SToken* pVal) {
|
||||
|
@ -772,6 +784,29 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* createDefaultAlterDatabaseOptions(SAstCreateContext* pCxt) {
|
||||
SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->numOfBlocks = -1;
|
||||
pOptions->cacheBlockSize = -1;
|
||||
pOptions->cachelast = -1;
|
||||
pOptions->compressionLevel = -1;
|
||||
pOptions->daysPerFile = -1;
|
||||
pOptions->fsyncPeriod = -1;
|
||||
pOptions->maxRowsPerBlock = -1;
|
||||
pOptions->minRowsPerBlock = -1;
|
||||
pOptions->keep = -1;
|
||||
pOptions->precision = -1;
|
||||
pOptions->quorum = -1;
|
||||
pOptions->replica = -1;
|
||||
pOptions->ttl = -1;
|
||||
pOptions->walLevel = -1;
|
||||
pOptions->numOfVgroups = -1;
|
||||
pOptions->singleStable = -1;
|
||||
pOptions->streamMode = -1;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, const SToken* pVal) {
|
||||
return (SNode*)setDbOptionFuncs[type](pCxt, (SDatabaseOptions*)pOptions, pVal);
|
||||
}
|
||||
|
@ -818,6 +853,14 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
|||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* createDefaultAlterTableOptions(SAstCreateContext* pCxt) {
|
||||
STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->keep = -1;
|
||||
pOptions->ttl = -1;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, const SToken* pVal) {
|
||||
return (SNode*)setTableOptionFuncs[type](pCxt, (STableOptions*)pOptions, pVal);
|
||||
}
|
||||
|
@ -827,6 +870,11 @@ SNode* setTableSmaOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pS
|
|||
return pOptions;
|
||||
}
|
||||
|
||||
SNode* setTableRollupOption(SAstCreateContext* pCxt, SNode* pOptions, SNodeList* pFuncs) {
|
||||
// todo
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, const SToken* pColName, SDataType dataType, const SToken* pComment) {
|
||||
SColumnDefNode* pCol = (SColumnDefNode*)nodesMakeNode(QUERY_NODE_COLUMN_DEF);
|
||||
CHECK_OUT_OF_MEM(pCol);
|
||||
|
@ -912,6 +960,49 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) {
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
|
||||
pStmt->pOptions = (STableOptions*)pOptions;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName, SDataType dataType) {
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
strncpy(pStmt->colName, pColName->z, pColName->n);
|
||||
pStmt->dataType = dataType;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName) {
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
strncpy(pStmt->colName, pColName->z, pColName->n);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pOldColName, const SToken* pNewColName) {
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = alterType;
|
||||
strncpy(pStmt->colName, pOldColName->z, pOldColName->n);
|
||||
strncpy(pStmt->newColName, pNewColName->z, pNewColName->n);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, const SToken* pTagName, SNode* pVal) {
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
|
||||
strncpy(pStmt->colName, pTagName->z, pTagName->n);
|
||||
pStmt->pVal = (SValueNode*)pVal;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
SUseDatabaseStmt* pStmt = (SUseDatabaseStmt*)nodesMakeNode(QUERY_NODE_USE_DATABASE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
|
@ -1009,6 +1100,17 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue) {
|
||||
SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = strtol(pDnode->z, NULL, 10);
|
||||
trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
if (NULL != pValue) {
|
||||
trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
}
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, const SToken* pIndexName, const SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
||||
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
||||
return NULL;
|
||||
|
@ -1077,3 +1179,13 @@ SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const
|
|||
pStmt->ignoreNotExists = ignoreNotExists;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue) {
|
||||
SAlterLocalStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_LOCAL_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
if (NULL != pValue) {
|
||||
trimString(pValue->z, pValue->n, pStmt->value, sizeof(pStmt->value));
|
||||
}
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
|
|
@ -622,7 +622,7 @@ static FORCE_INLINE int32_t MemRowAppend(const void* value, int32_t len, void* p
|
|||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||
int32_t output = 0;
|
||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
||||
if (!taosMbsToUcs4(value, len, (char*)varDataVal(rowEnd), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(rowEnd), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||
}
|
||||
varDataSetLen(rowEnd, output);
|
||||
|
@ -725,7 +725,7 @@ static int32_t KvRowAppend(const void *value, int32_t len, void *param) {
|
|||
} else if (TSDB_DATA_TYPE_NCHAR == type) {
|
||||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||
int32_t output = 0;
|
||||
if (!taosMbsToUcs4(value, len, varDataVal(pa->buf), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
if (!taosMbsToUcs4(value, len, (TdUcs4*)varDataVal(pa->buf), pa->schema->bytes - VARSTR_HEADER_SIZE, &output)) {
|
||||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ typedef struct SKeyword {
|
|||
|
||||
// keywords in sql string
|
||||
static SKeyword keywordTable[] = {
|
||||
{"ACCOUNT", TK_ACCOUNT},
|
||||
{"ALL", TK_ALL},
|
||||
{"ALTER", TK_ALTER},
|
||||
{"AND", TK_AND},
|
||||
|
@ -168,7 +169,6 @@ static SKeyword keywordTable[] = {
|
|||
// {"SCORES", TK_SCORES},
|
||||
// {"GRANTS", TK_GRANTS},
|
||||
// {"DOT", TK_DOT},
|
||||
// {"ACCOUNT", TK_ACCOUNT},
|
||||
// {"DESCRIBE", TK_DESCRIBE},
|
||||
// {"SYNCDB", TK_SYNCDB},
|
||||
// {"LOCAL", TK_LOCAL},
|
||||
|
|
|
@ -126,7 +126,7 @@ static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SCol
|
|||
static int32_t createColumnNodeByTable(STranslateContext* pCxt, const STableNode* pTable, SNodeList* pList) {
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta;
|
||||
int32_t nums = pMeta->tableInfo.numOfColumns + ((TSDB_SUPER_TABLE == pMeta->tableType)? pMeta->tableInfo.numOfTags:0);
|
||||
int32_t nums = pMeta->tableInfo.numOfColumns + ((TSDB_SUPER_TABLE == pMeta->tableType) ? pMeta->tableInfo.numOfTags : 0);
|
||||
for (int32_t i = 0; i < nums; ++i) {
|
||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == pCol) {
|
||||
|
@ -499,6 +499,10 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
|
|||
}
|
||||
|
||||
static int32_t setTableVgroupList(SParseContext* pCxt, SName* name, SRealTableNode* pRealTable) {
|
||||
if (pCxt->streamQuery) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (TSDB_SUPER_TABLE == pRealTable->pMeta->tableType) {
|
||||
SArray* vgroupList = NULL;
|
||||
int32_t code = catalogGetTableDistVgInfo(pCxt->pCatalog, pCxt->pTransporter, &pCxt->mgmtEpSet, name, &vgroupList);
|
||||
|
@ -962,6 +966,73 @@ static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableS
|
|||
return doTranslateDropSuperTable(pCxt, &tableName, pStmt->ignoreNotExists);
|
||||
}
|
||||
|
||||
static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAltertbReq* pAlterReq) {
|
||||
pAlterReq->pFields = taosArrayInit(2, sizeof(TAOS_FIELD));
|
||||
if (NULL == pAlterReq->pFields) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
switch (pStmt->alterType) {
|
||||
case TSDB_ALTER_TABLE_ADD_TAG:
|
||||
case TSDB_ALTER_TABLE_DROP_TAG:
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
case TSDB_ALTER_TABLE_DROP_COLUMN:
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES:
|
||||
case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES: {
|
||||
TAOS_FIELD field = { .type = pStmt->dataType.type, .bytes = pStmt->dataType.bytes };
|
||||
strcpy(field.name, pStmt->colName);
|
||||
taosArrayPush(pAlterReq->pFields, &field);
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_UPDATE_TAG_NAME:
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: {
|
||||
TAOS_FIELD oldField = {0};
|
||||
strcpy(oldField.name, pStmt->colName);
|
||||
taosArrayPush(pAlterReq->pFields, &oldField);
|
||||
TAOS_FIELD newField = {0};
|
||||
strcpy(oldField.name, pStmt->newColName);
|
||||
taosArrayPush(pAlterReq->pFields, &newField);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateAlterTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) {
|
||||
SMAltertbReq alterReq = {0};
|
||||
SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId };
|
||||
strcpy(tableName.dbname, pStmt->dbName);
|
||||
strcpy(tableName.tname, pStmt->tableName);
|
||||
tNameExtractFullName(&tableName, alterReq.name);
|
||||
alterReq.alterType = pStmt->alterType;
|
||||
alterReq.numOfFields = 1;
|
||||
if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) {
|
||||
// todo
|
||||
} else {
|
||||
if (TSDB_CODE_SUCCESS != setAlterTableField(pStmt, &alterReq)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||
if (NULL == pCxt->pCmdMsg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||
pCxt->pCmdMsg->msgType = TDMT_MND_ALTER_STB;
|
||||
pCxt->pCmdMsg->msgLen = tSerializeSMAlterStbReq(NULL, 0, &alterReq);
|
||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tSerializeSMAlterStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &alterReq);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) {
|
||||
SName name = {0};
|
||||
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
|
||||
|
@ -1099,6 +1170,28 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateAlterDnode(STranslateContext* pCxt, SAlterDnodeStmt* pStmt) {
|
||||
SMCfgDnodeReq cfgReq = {0};
|
||||
cfgReq.dnodeId = pStmt->dnodeId;
|
||||
strcpy(cfgReq.config, pStmt->config);
|
||||
strcpy(cfgReq.value, pStmt->value);
|
||||
|
||||
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
|
||||
if (NULL == pCxt->pCmdMsg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
|
||||
pCxt->pCmdMsg->msgType = TDMT_MND_CONFIG_DNODE;
|
||||
pCxt->pCmdMsg->msgLen = tSerializeSMCfgDnodeReq(NULL, 0, &cfgReq);
|
||||
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
|
||||
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
tSerializeSMCfgDnodeReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &cfgReq);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t nodeTypeToShowType(ENodeType nt) {
|
||||
switch (nt) {
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
|
@ -1300,6 +1393,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p
|
|||
SCMCreateTopicReq createReq = {0};
|
||||
|
||||
if (NULL != pStmt->pQuery) {
|
||||
pCxt->pParseCxt->streamQuery = true;
|
||||
int32_t code = translateQuery(pCxt, pStmt->pQuery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesNodeToString(pStmt->pQuery, false, &createReq.ast, NULL);
|
||||
|
@ -1364,6 +1458,11 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) {
|
||||
// todo
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pNode)) {
|
||||
|
@ -1388,6 +1487,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||
code = translateDropSuperTable(pCxt, (SDropSuperTableStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||
code = translateAlterTable(pCxt, (SAlterTableStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_CREATE_USER_STMT:
|
||||
code = translateCreateUser(pCxt, (SCreateUserStmt*)pNode);
|
||||
break;
|
||||
|
@ -1406,6 +1508,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_DROP_DNODE_STMT:
|
||||
code = translateDropDnode(pCxt, (SDropDnodeStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_DNODE_STMT:
|
||||
code = translateAlterDnode(pCxt, (SAlterDnodeStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_DATABASES_STMT:
|
||||
case QUERY_NODE_SHOW_STABLES_STMT:
|
||||
case QUERY_NODE_SHOW_USERS_STMT:
|
||||
|
@ -1436,6 +1541,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_DROP_TOPIC_STMT:
|
||||
code = translateDropTopic(pCxt, (SDropTopicStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_LOCAL_STMT:
|
||||
code = translateAlterLocal(pCxt, (SAlterLocalStmt*)pNode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1855,6 +1963,11 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
|
|||
return rewriteToVnodeModifOpStmt(pQuery, pBufArray);
|
||||
}
|
||||
|
||||
static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
// todo
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pQuery->pRoot)) {
|
||||
|
@ -1866,6 +1979,11 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||
code = rewriteCreateMultiTable(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||
if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == ((SAlterTableStmt*)pQuery->pRoot)->alterType) {
|
||||
code = rewriteAlterTable(pCxt, pQuery);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -46,17 +46,19 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
case TSDB_CODE_PAR_NOT_SINGLE_GROUP:
|
||||
return "Not a single-group group function";
|
||||
case TSDB_CODE_PAR_TAGS_NOT_MATCHED:
|
||||
return "tags number not matched";
|
||||
return "Tags number not matched";
|
||||
case TSDB_CODE_PAR_INVALID_TAG_NAME:
|
||||
return "invalid tag name : %s";
|
||||
return "Invalid tag name : %s";
|
||||
case TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG:
|
||||
return "name or password too long";
|
||||
return "Name or password too long";
|
||||
case TSDB_CODE_PAR_PASSWD_EMPTY:
|
||||
return "password can not be empty";
|
||||
return "Password can not be empty";
|
||||
case TSDB_CODE_PAR_INVALID_PORT:
|
||||
return "port should be an integer that is less than 65535 and greater than 0";
|
||||
return "Port should be an integer that is less than 65535 and greater than 0";
|
||||
case TSDB_CODE_PAR_INVALID_ENDPOINT:
|
||||
return "endpoint should be in the format of 'fqdn:port'";
|
||||
return "Endpoint should be in the format of 'fqdn:port'";
|
||||
case TSDB_CODE_PAR_EXPRIE_STATEMENT:
|
||||
return "This statement is no longer supported";
|
||||
case TSDB_CODE_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
default:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -13,12 +13,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "mockCatalogService.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include "tdatablock.h"
|
||||
#include "mockCatalogService.h"
|
||||
|
||||
#include "tname.h"
|
||||
#include "ttypes.h"
|
||||
|
|
|
@ -302,6 +302,13 @@ TEST_F(ParserTest, createUser) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, alterAccount) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("alter account ac_wxy pass '123456'");
|
||||
ASSERT_TRUE(run(TSDB_CODE_PAR_EXPRIE_STATEMENT));
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, createDnode) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
|
@ -312,6 +319,16 @@ TEST_F(ParserTest, createDnode) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, alterDnode) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("alter dnode 1 'resetLog'");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("alter dnode 1 'debugFlag' '134'");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, createDatabase) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
|
|
|
@ -18,13 +18,13 @@
|
|||
#include "functionMgt.h"
|
||||
|
||||
typedef struct SLogicPlanContext {
|
||||
int32_t errCode;
|
||||
int32_t planNodeId;
|
||||
int32_t acctId;
|
||||
SPlanContext* pPlanCxt;
|
||||
} SLogicPlanContext;
|
||||
|
||||
static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt);
|
||||
static SLogicNode* createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable);
|
||||
typedef int32_t (*FCreateLogicNode)(SLogicPlanContext*, SSelectStmt*, SLogicNode**);
|
||||
|
||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode);
|
||||
static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode);
|
||||
|
||||
typedef struct SRewriteExprCxt {
|
||||
int32_t errCode;
|
||||
|
@ -66,7 +66,6 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
}
|
||||
|
||||
typedef struct SNameExprCxt {
|
||||
int32_t planNodeId;
|
||||
int32_t rewriteId;
|
||||
} SNameExprCxt;
|
||||
|
||||
|
@ -76,7 +75,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
|||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
case QUERY_NODE_FUNCTION: {
|
||||
SNameExprCxt* pCxt = (SNameExprCxt*)pContext;
|
||||
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%d_%d", pCxt->planNodeId, pCxt->rewriteId++);
|
||||
sprintf(((SExprNode*)pNode)->aliasName, "#expr_%d", pCxt->rewriteId++);
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
default:
|
||||
|
@ -86,131 +85,194 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t rewriteExpr(int32_t planNodeId, int32_t rewriteId, SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
|
||||
SNameExprCxt nameCxt = { .planNodeId = planNodeId, .rewriteId = rewriteId };
|
||||
static int32_t rewriteExpr(SNodeList* pExprs, SSelectStmt* pSelect, ESqlClause clause) {
|
||||
static int32_t rewriteId = 1;
|
||||
SNameExprCxt nameCxt = { .rewriteId = rewriteId };
|
||||
nodesWalkList(pExprs, doNameExpr, &nameCxt);
|
||||
SRewriteExprCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pExprs = pExprs };
|
||||
nodesRewriteSelectStmt(pSelect, clause, doRewriteExpr, &cxt);
|
||||
return cxt.errCode;
|
||||
}
|
||||
|
||||
static SLogicNode* pushLogicNode(SLogicPlanContext* pCxt, SLogicNode* pRoot, SLogicNode* pNode) {
|
||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (NULL == pRoot) {
|
||||
return pNode;
|
||||
}
|
||||
|
||||
if (NULL == pNode) {
|
||||
return pRoot;
|
||||
}
|
||||
|
||||
if (NULL == pNode->pChildren) {
|
||||
pNode->pChildren = nodesMakeList();
|
||||
if (NULL == pNode->pChildren) {
|
||||
goto error;
|
||||
static int32_t pushLogicNode(SLogicPlanContext* pCxt, SLogicNode** pOldRoot, SLogicNode* pNewRoot) {
|
||||
if (NULL == pNewRoot->pChildren) {
|
||||
pNewRoot->pChildren = nodesMakeList();
|
||||
if (NULL == pNewRoot->pChildren) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pNode->pChildren, (SNode*)pRoot)) {
|
||||
goto error;
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pNewRoot->pChildren, (SNode*)*pOldRoot)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pRoot->pParent = pNode;
|
||||
return pNode;
|
||||
error:
|
||||
nodesDestroyNode((SNode*)pNode);
|
||||
return pRoot;
|
||||
|
||||
(*pOldRoot)->pParent = pNewRoot;
|
||||
*pOldRoot = pNewRoot;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SLogicNode* createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable) {
|
||||
static int32_t createChildLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, FCreateLogicNode func, SLogicNode** pRoot) {
|
||||
SLogicNode* pNode = NULL;
|
||||
int32_t code = func(pCxt, pSelect, &pNode);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pNode) {
|
||||
code = pushLogicNode(pCxt, pRoot, pNode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pNode);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SRealTableNode* pRealTable, SLogicNode** pLogicNode) {
|
||||
SScanLogicNode* pScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN);
|
||||
CHECK_ALLOC(pScan, NULL);
|
||||
pScan->node.id = pCxt->planNodeId++;
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
TSWAP(pScan->pMeta, pRealTable->pMeta, STableMeta*);
|
||||
TSWAP(pScan->pVgroupList, pRealTable->pVgroupList, SVgroupsInfo*);
|
||||
|
||||
// set columns to scan
|
||||
SNodeList* pCols = NULL;
|
||||
CHECK_CODE(nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, &pCols), (SLogicNode*)pScan);
|
||||
if (NULL != pCols) {
|
||||
pScan->pScanCols = nodesCloneList(pCols);
|
||||
CHECK_ALLOC(pScan->pScanCols, (SLogicNode*)pScan);
|
||||
}
|
||||
|
||||
// set output
|
||||
if (NULL != pCols) {
|
||||
pScan->node.pTargets = nodesCloneList(pCols);
|
||||
CHECK_ALLOC(pScan->node.pTargets, (SLogicNode*)pScan);
|
||||
}
|
||||
|
||||
pScan->scanType = SCAN_TYPE_TABLE;
|
||||
pScan->scanType = pCxt->pPlanCxt->streamQuery ? SCAN_TYPE_STREAM : SCAN_TYPE_TABLE;
|
||||
pScan->scanFlag = MAIN_SCAN;
|
||||
pScan->scanRange = TSWINDOW_INITIALIZER;
|
||||
pScan->tableName.type = TSDB_TABLE_NAME_T;
|
||||
pScan->tableName.acctId = pCxt->acctId;
|
||||
pScan->tableName.acctId = pCxt->pPlanCxt->acctId;
|
||||
strcpy(pScan->tableName.dbname, pRealTable->table.dbName);
|
||||
strcpy(pScan->tableName.tname, pRealTable->table.tableName);
|
||||
|
||||
return (SLogicNode*)pScan;
|
||||
}
|
||||
|
||||
static SLogicNode* createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable) {
|
||||
SLogicNode* pRoot = createQueryLogicNode(pCxt, pTable->pSubquery);
|
||||
CHECK_ALLOC(pRoot, NULL);
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pRoot->pTargets) {
|
||||
strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias);
|
||||
// set columns to scan
|
||||
SNodeList* pCols = NULL;
|
||||
int32_t code = nodesCollectColumns(pSelect, SQL_CLAUSE_FROM, pRealTable->table.tableAlias, &pCols);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCols) {
|
||||
pScan->pScanCols = nodesCloneList(pCols);
|
||||
if (NULL == pScan) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return pRoot;
|
||||
|
||||
// set output
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pCols) {
|
||||
pScan->node.pTargets = nodesCloneList(pCols);
|
||||
if (NULL == pScan) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pScan;
|
||||
} else {
|
||||
nodesDestroyNode(pScan);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLogicNode* createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable) {
|
||||
static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) {
|
||||
int32_t code = createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, (*pLogicNode)->pTargets) {
|
||||
strcpy(((SColumnNode*)pNode)->tableAlias, pTable->table.tableAlias);
|
||||
}
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SJoinTableNode* pJoinTable, SLogicNode** pLogicNode) {
|
||||
SJoinLogicNode* pJoin = (SJoinLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_JOIN);
|
||||
CHECK_ALLOC(pJoin, NULL);
|
||||
pJoin->node.id = pCxt->planNodeId++;
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pJoin->joinType = pJoinTable->joinType;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// set left and right node
|
||||
pJoin->node.pChildren = nodesMakeList();
|
||||
CHECK_ALLOC(pJoin->node.pChildren, (SLogicNode*)pJoin);
|
||||
SLogicNode* pLeft = createLogicNodeByTable(pCxt, pSelect, pJoinTable->pLeft);
|
||||
CHECK_ALLOC(pLeft, (SLogicNode*)pJoin);
|
||||
CHECK_CODE(nodesListAppend(pJoin->node.pChildren, (SNode*)pLeft), (SLogicNode*)pJoin);
|
||||
SLogicNode* pRight = createLogicNodeByTable(pCxt, pSelect, pJoinTable->pRight);
|
||||
CHECK_ALLOC(pRight, (SLogicNode*)pJoin);
|
||||
CHECK_CODE(nodesListAppend(pJoin->node.pChildren, (SNode*)pRight), (SLogicNode*)pJoin);
|
||||
if (NULL == pJoin->node.pChildren) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SLogicNode* pLeft = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = doCreateLogicNodeByTable(pCxt, pSelect, pJoinTable->pLeft, &pLeft);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pJoin->node.pChildren, (SNode*)pLeft);
|
||||
}
|
||||
}
|
||||
|
||||
SLogicNode* pRight = NULL;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = doCreateLogicNodeByTable(pCxt, pSelect, pJoinTable->pRight, &pRight);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pJoin->node.pChildren, (SNode*)pRight);
|
||||
}
|
||||
}
|
||||
|
||||
// set on conditions
|
||||
if (NULL != pJoinTable->pOnCond) {
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinTable->pOnCond) {
|
||||
pJoin->pOnConditions = nodesCloneNode(pJoinTable->pOnCond);
|
||||
CHECK_ALLOC(pJoin->pOnConditions, (SLogicNode*)pJoin);
|
||||
if (NULL == pJoin->pOnConditions) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// set the output
|
||||
pJoin->node.pTargets = nodesCloneList(pLeft->pTargets);
|
||||
CHECK_ALLOC(pJoin->node.pTargets, (SLogicNode*)pJoin);
|
||||
SNodeList* pTargets = nodesCloneList(pRight->pTargets);
|
||||
CHECK_ALLOC(pTargets, (SLogicNode*)pJoin);
|
||||
nodesListAppendList(pJoin->node.pTargets, pTargets);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pJoin->node.pTargets = nodesCloneList(pLeft->pTargets);
|
||||
if (NULL == pJoin->pOnConditions) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppendList(pJoin->node.pTargets, nodesCloneList(pRight->pTargets));
|
||||
}
|
||||
}
|
||||
|
||||
return (SLogicNode*)pJoin;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pJoin;
|
||||
} else {
|
||||
nodesDestroyNode(pJoin);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLogicNode* createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable) {
|
||||
static int32_t doCreateLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) {
|
||||
switch (nodeType(pTable)) {
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable);
|
||||
return createScanLogicNode(pCxt, pSelect, (SRealTableNode*)pTable, pLogicNode);
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
return createSubqueryLogicNode(pCxt, pSelect, (STempTableNode*)pTable);
|
||||
return createSubqueryLogicNode(pCxt, pSelect, (STempTableNode*)pTable, pLogicNode);
|
||||
case QUERY_NODE_JOIN_TABLE:
|
||||
return createJoinLogicNode(pCxt, pSelect, (SJoinTableNode*)pTable);
|
||||
return createJoinLogicNode(pCxt, pSelect, (SJoinTableNode*)pTable, pLogicNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createLogicNodeByTable(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNode* pTable, SLogicNode** pLogicNode) {
|
||||
SLogicNode* pNode = NULL;
|
||||
int32_t code = doCreateLogicNodeByTable(pCxt, pSelect, pTable, &pNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pNode->pConditions = nodesCloneNode(pSelect->pWhere);
|
||||
if (NULL != pSelect->pWhere && NULL == pNode->pConditions) {
|
||||
nodesDestroyNode(pNode);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
*pLogicNode = pNode;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static SColumnNode* createColumnByExpr(SExprNode* pExpr) {
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == pCol) {
|
||||
return NULL;
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
return pCol;
|
||||
}
|
||||
|
||||
typedef struct SCreateColumnCxt {
|
||||
|
@ -245,196 +307,241 @@ static EDealRes doCreateColumn(SNode* pNode, void* pContext) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static SNodeList* createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pExprs) {
|
||||
SCreateColumnCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pList = nodesMakeList() };
|
||||
CHECK_ALLOC(cxt.pList, NULL);
|
||||
static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pExprs, SNodeList** pList) {
|
||||
SCreateColumnCxt cxt = { .errCode = TSDB_CODE_SUCCESS, .pList = (NULL == *pList ? nodesMakeList() : *pList) };
|
||||
if (NULL == cxt.pList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nodesWalkList(pExprs, doCreateColumn, &cxt);
|
||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||
nodesDestroyList(cxt.pList);
|
||||
return NULL;
|
||||
return cxt.errCode;
|
||||
}
|
||||
return cxt.pList;
|
||||
if (NULL == *pList) {
|
||||
*pList = cxt.pList;
|
||||
}
|
||||
return cxt.errCode;
|
||||
}
|
||||
|
||||
static SLogicNode* createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect) {
|
||||
static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SNodeList* pAggFuncs = NULL;
|
||||
CHECK_CODE(nodesCollectFuncs(pSelect, fmIsAggFunc, &pAggFuncs), NULL);
|
||||
int32_t code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pAggFuncs);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (NULL == pAggFuncs && NULL == pSelect->pGroupByList) {
|
||||
return NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SAggLogicNode* pAgg = (SAggLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_AGG);
|
||||
CHECK_ALLOC(pAgg, NULL);
|
||||
pAgg->node.id = pCxt->planNodeId++;
|
||||
if (NULL == pAgg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
// set grouyp keys, agg funcs and having conditions
|
||||
if (NULL != pSelect->pGroupByList) {
|
||||
pAgg->pGroupKeys = nodesCloneList(pSelect->pGroupByList);
|
||||
CHECK_ALLOC(pAgg->pGroupKeys, (SLogicNode*)pAgg);
|
||||
if (NULL == pAgg->pGroupKeys) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
if (NULL != pAggFuncs) {
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pAggFuncs) {
|
||||
pAgg->pAggFuncs = nodesCloneList(pAggFuncs);
|
||||
CHECK_ALLOC(pAgg->pAggFuncs, (SLogicNode*)pAgg);
|
||||
if (NULL == pAgg->pAggFuncs) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// rewrite the expression in subsequent clauses
|
||||
CHECK_CODE(rewriteExpr(pAgg->node.id, 1, pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY), (SLogicNode*)pAgg);
|
||||
CHECK_CODE(rewriteExpr(pAgg->node.id, 1 + LIST_LENGTH(pAgg->pGroupKeys), pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY), (SLogicNode*)pAgg);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExpr(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExpr(pAgg->pAggFuncs, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||
}
|
||||
|
||||
if (NULL != pSelect->pHaving) {
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pSelect->pHaving) {
|
||||
pAgg->node.pConditions = nodesCloneNode(pSelect->pHaving);
|
||||
CHECK_ALLOC(pAgg->node.pConditions, (SLogicNode*)pAgg);
|
||||
if (NULL == pAgg->node.pConditions) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
// set the output
|
||||
pAgg->node.pTargets = nodesMakeList();
|
||||
CHECK_ALLOC(pAgg->node.pTargets, (SLogicNode*)pAgg);
|
||||
if (NULL != pAgg->pGroupKeys) {
|
||||
SNodeList* pTargets = createColumnByRewriteExps(pCxt, pAgg->pGroupKeys);
|
||||
CHECK_ALLOC(pAgg->node.pTargets, (SLogicNode*)pAgg);
|
||||
nodesListAppendList(pAgg->node.pTargets, pTargets);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pAgg->pGroupKeys) {
|
||||
code = createColumnByRewriteExps(pCxt, pAgg->pGroupKeys, &pAgg->node.pTargets);
|
||||
}
|
||||
if (NULL != pAgg->pAggFuncs) {
|
||||
SNodeList* pTargets = createColumnByRewriteExps(pCxt, pAgg->pAggFuncs);
|
||||
CHECK_ALLOC(pTargets, (SLogicNode*)pAgg);
|
||||
nodesListAppendList(pAgg->node.pTargets, pTargets);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pAgg->pAggFuncs) {
|
||||
code = createColumnByRewriteExps(pCxt, pAgg->pAggFuncs, &pAgg->node.pTargets);
|
||||
}
|
||||
|
||||
return (SLogicNode*)pAgg;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pAgg;
|
||||
} else {
|
||||
nodesDestroyNode(pAgg);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLogicNode* createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, SSelectStmt* pSelect) {
|
||||
static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SIntervalWindowNode* pInterval, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SWindowLogicNode* pWindow = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_WINDOW);
|
||||
CHECK_ALLOC(pWindow, NULL);
|
||||
pWindow->node.id = pCxt->planNodeId++;
|
||||
if (NULL == pWindow) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pWindow->winType = WINDOW_TYPE_INTERVAL;
|
||||
SValueNode* pIntervalNode = (SValueNode*)((SRawExprNode*)(pInterval->pInterval))->pNode;
|
||||
|
||||
pWindow->interval = pIntervalNode->datum.i;
|
||||
pWindow->interval = ((SValueNode*)pInterval->pInterval)->datum.i;
|
||||
pWindow->intervalUnit = ((SValueNode*)pInterval->pInterval)->unit;
|
||||
pWindow->offset = (NULL != pInterval->pOffset ? ((SValueNode*)pInterval->pOffset)->datum.i : 0);
|
||||
pWindow->sliding = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->datum.i : pWindow->interval);
|
||||
pWindow->slidingUnit = (NULL != pInterval->pSliding ? ((SValueNode*)pInterval->pSliding)->unit : pWindow->intervalUnit);
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
if (NULL != pInterval->pFill) {
|
||||
pWindow->pFill = nodesCloneNode(pInterval->pFill);
|
||||
CHECK_ALLOC(pWindow->pFill, (SLogicNode*)pWindow);
|
||||
if (NULL == pWindow->pFill) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
SNodeList* pFuncs = NULL;
|
||||
CHECK_CODE(nodesCollectFuncs(pSelect, fmIsAggFunc, &pFuncs), NULL);
|
||||
if (NULL != pFuncs) {
|
||||
pWindow->pFuncs = nodesCloneList(pFuncs);
|
||||
CHECK_ALLOC(pWindow->pFuncs, (SLogicNode*)pWindow);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesCollectFuncs(pSelect, fmIsAggFunc, &pWindow->pFuncs);
|
||||
}
|
||||
|
||||
CHECK_CODE(rewriteExpr(pWindow->node.id, 1, pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW), (SLogicNode*)pWindow);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExpr(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW);
|
||||
}
|
||||
|
||||
pWindow->node.pTargets = createColumnByRewriteExps(pCxt, pWindow->pFuncs);
|
||||
CHECK_ALLOC(pWindow->node.pTargets, (SLogicNode*)pWindow);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnByRewriteExps(pCxt, pWindow->pFuncs, &pWindow->node.pTargets);
|
||||
}
|
||||
|
||||
return (SLogicNode*)pWindow;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pWindow;
|
||||
} else {
|
||||
nodesDestroyNode(pWindow);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLogicNode* createWindowLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect) {
|
||||
static int32_t createWindowLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
if (NULL == pSelect->pWindow) {
|
||||
return NULL;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
switch (nodeType(pSelect->pWindow)) {
|
||||
case QUERY_NODE_INTERVAL_WINDOW:
|
||||
return createWindowLogicNodeByInterval(pCxt, (SIntervalWindowNode*)pSelect->pWindow, pSelect);
|
||||
return createWindowLogicNodeByInterval(pCxt, (SIntervalWindowNode*)pSelect->pWindow, pSelect, pLogicNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static SNodeList* createColumnByProjections(SLogicPlanContext* pCxt, SNodeList* pExprs) {
|
||||
static int32_t createColumnByProjections(SLogicPlanContext* pCxt, SNodeList* pExprs, SNodeList** pCols) {
|
||||
SNodeList* pList = nodesMakeList();
|
||||
CHECK_ALLOC(pList, NULL);
|
||||
if (NULL == pList) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pExprs) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
SColumnNode* pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == pCol) {
|
||||
goto error;
|
||||
}
|
||||
pCol->node.resType = pExpr->resType;
|
||||
strcpy(pCol->colName, pExpr->aliasName);
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, (SNode*)pCol)) {
|
||||
goto error;
|
||||
FOREACH(pNode, pExprs) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, createColumnByExpr((SExprNode*)pNode))) {
|
||||
nodesDestroyList(pList);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return pList;
|
||||
error:
|
||||
nodesDestroyList(pList);
|
||||
return NULL;
|
||||
|
||||
*pCols = pList;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SLogicNode* createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect) {
|
||||
static int32_t createProjectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SProjectLogicNode* pProject = (SProjectLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_PROJECT);
|
||||
CHECK_ALLOC(pProject, NULL);
|
||||
pProject->node.id = pCxt->planNodeId++;
|
||||
if (NULL == pProject) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
pProject->pProjections = nodesCloneList(pSelect->pProjectionList);
|
||||
if (NULL == pProject->pProjections) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pProject->node.pTargets = createColumnByProjections(pCxt,pSelect->pProjectionList);
|
||||
CHECK_ALLOC(pProject->node.pTargets, (SLogicNode*)pProject);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnByProjections(pCxt,pSelect->pProjectionList, &pProject->node.pTargets);
|
||||
}
|
||||
|
||||
return (SLogicNode*)pProject;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = (SLogicNode*)pProject;
|
||||
} else {
|
||||
nodesDestroyNode(pProject);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static SLogicNode* createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect) {
|
||||
SLogicNode* pRoot = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && NULL != pSelect->pWhere) {
|
||||
pRoot->pConditions = nodesCloneNode(pSelect->pWhere);
|
||||
CHECK_ALLOC(pRoot->pConditions, pRoot);
|
||||
static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
SLogicNode* pRoot = NULL;
|
||||
int32_t code = createLogicNodeByTable(pCxt, pSelect, pSelect->pFromTable, &pRoot);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createWindowLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pRoot = pushLogicNode(pCxt, pRoot, createWindowLogicNode(pCxt, pSelect));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createAggLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pRoot = pushLogicNode(pCxt, pRoot, createAggLogicNode(pCxt, pSelect));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createChildLogicNode(pCxt, pSelect, createProjectLogicNode, &pRoot);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
pRoot = pushLogicNode(pCxt, pRoot, createProjectLogicNode(pCxt, pSelect));
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pLogicNode = pRoot;
|
||||
} else {
|
||||
nodesDestroyNode(pRoot);
|
||||
}
|
||||
return pRoot;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t getMsgType(ENodeType sqlType) {
|
||||
return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) ? TDMT_VND_CREATE_TABLE : TDMT_VND_SUBMIT;
|
||||
}
|
||||
|
||||
static SLogicNode* createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt) {
|
||||
SVnodeModifLogicNode* pModif = (SVnodeModifLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_VNODE_MODIF);
|
||||
CHECK_ALLOC(pModif, NULL);
|
||||
static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) {
|
||||
SVnodeModifLogicNode* pModif = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_VNODE_MODIF);
|
||||
if (NULL == pModif) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pModif->pDataBlocks = pStmt->pDataBlocks;
|
||||
pModif->msgType = getMsgType(pStmt->sqlNodeType);
|
||||
return (SLogicNode*)pModif;
|
||||
*pLogicNode = (SLogicNode*)pModif;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SLogicNode* createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt) {
|
||||
static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode) {
|
||||
switch (nodeType(pStmt)) {
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return createSelectLogicNode(pCxt, (SSelectStmt*)pStmt);
|
||||
return createSelectLogicNode(pCxt, (SSelectStmt*)pStmt, pLogicNode);
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt);
|
||||
return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt, pLogicNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL; // to avoid compiler error
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int32_t createLogicPlan(SPlanContext* pCxt, SLogicNode** pLogicNode) {
|
||||
SLogicPlanContext cxt = { .errCode = TSDB_CODE_SUCCESS, .planNodeId = 1, .acctId = pCxt->acctId };
|
||||
SLogicNode* pRoot = createQueryLogicNode(&cxt, pCxt->pAstRoot);
|
||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||
nodesDestroyNode((SNode*)pRoot);
|
||||
return cxt.errCode;
|
||||
SLogicPlanContext cxt = { .pPlanCxt = pCxt };
|
||||
int32_t code = createQueryLogicNode(&cxt, pCxt->pAstRoot, pLogicNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
*pLogicNode = pRoot;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -259,15 +259,21 @@ static SPhysiNode* createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* p
|
|||
return (SPhysiNode*)pTableScan;
|
||||
}
|
||||
|
||||
static SPhysiNode* createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode) {
|
||||
SStreamScanPhysiNode* pTableScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
CHECK_ALLOC(pTableScan, NULL);
|
||||
CHECK_CODE(initScanPhysiNode(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan), (SPhysiNode*)pTableScan);
|
||||
return (SPhysiNode*)pTableScan;
|
||||
}
|
||||
|
||||
static SPhysiNode* createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode) {
|
||||
switch (pScanLogicNode->scanType) {
|
||||
case SCAN_TYPE_TAG:
|
||||
return createTagScanPhysiNode(pCxt, pScanLogicNode);
|
||||
case SCAN_TYPE_TABLE:
|
||||
return createTableScanPhysiNode(pCxt, pSubplan, pScanLogicNode);
|
||||
case SCAN_TYPE_STABLE:
|
||||
case SCAN_TYPE_STREAM:
|
||||
break;
|
||||
return createStreamScanPhysiNode(pCxt, pSubplan, pScanLogicNode);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1813,7 +1813,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
|
|||
if(type == TSDB_DATA_TYPE_NCHAR &&
|
||||
(unit->compare.optr == OP_TYPE_MATCH || unit->compare.optr == OP_TYPE_NMATCH)){
|
||||
char newValData[TSDB_REGEX_STRING_DEFAULT_LEN * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE] = {0};
|
||||
int32_t len = taosUcs4ToMbs(varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData));
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(fi->data), varDataLen(fi->data), varDataVal(newValData));
|
||||
if (len < 0){
|
||||
qError("filterInitValFieldData taosUcs4ToMbs error 1");
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
|
@ -2992,7 +2992,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa
|
|||
|
||||
if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){
|
||||
char *newColData = calloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
|
||||
int32_t len = taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), varDataVal(newColData));
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
|
||||
if (len < 0){
|
||||
qError("castConvert1 taosUcs4ToMbs error");
|
||||
}else{
|
||||
|
@ -3052,7 +3052,7 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDataAg
|
|||
} else {
|
||||
if(cunit->dataType == TSDB_DATA_TYPE_NCHAR && (cunit->optr == OP_TYPE_MATCH || cunit->optr == OP_TYPE_NMATCH)){
|
||||
char *newColData = calloc(cunit->dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
|
||||
int32_t len = taosUcs4ToMbs(varDataVal(colData), varDataLen(colData), varDataVal(newColData));
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
|
||||
if (len < 0){
|
||||
qError("castConvert1 taosUcs4ToMbs error");
|
||||
}else{
|
||||
|
@ -3433,7 +3433,7 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar
|
|||
varDataCopy(dst, src);
|
||||
continue;
|
||||
}
|
||||
bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), varDataVal(dst), bufSize, &len);
|
||||
bool ret = taosMbsToUcs4(varDataVal(src), varDataLen(src), (TdUcs4*)varDataVal(dst), bufSize, &len);
|
||||
if(!ret) {
|
||||
qError("filterConverNcharColumns taosMbsToUcs4 error");
|
||||
return TSDB_CODE_FAILED;
|
||||
|
|
|
@ -316,7 +316,7 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t
|
|||
tmp = realloc(tmp, bufSize);
|
||||
}
|
||||
|
||||
int len = taosUcs4ToMbs(varDataVal(pIn->data), varDataLen(pIn->data), tmp);
|
||||
int len = taosUcs4ToMbs((TdUcs4*)varDataVal(pIn->data), varDataLen(pIn->data), tmp);
|
||||
if (len < 0){
|
||||
sclError("castConvert taosUcs4ToMbs error 1");
|
||||
tfree(tmp);
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_LIBS_SYNC_COMMIT_H
|
||||
#define _TD_LIBS_SYNC_COMMIT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "syncInt.h"
|
||||
#include "taosdef.h"
|
||||
|
||||
// \* Leader i advances its commitIndex.
|
||||
// \* This is done as a separate step from handling AppendEntries responses,
|
||||
// \* in part to minimize atomic regions, and in part so that leaders of
|
||||
// \* single-server clusters are able to mark entries committed.
|
||||
// AdvanceCommitIndex(i) ==
|
||||
// /\ state[i] = Leader
|
||||
// /\ LET \* The set of servers that agree up through index.
|
||||
// Agree(index) == {i} \cup {k \in Server :
|
||||
// matchIndex[i][k] >= index}
|
||||
// \* The maximum indexes for which a quorum agrees
|
||||
// agreeIndexes == {index \in 1..Len(log[i]) :
|
||||
// Agree(index) \in Quorum}
|
||||
// \* New value for commitIndex'[i]
|
||||
// newCommitIndex ==
|
||||
// IF /\ agreeIndexes /= {}
|
||||
// /\ log[i][Max(agreeIndexes)].term = currentTerm[i]
|
||||
// THEN
|
||||
// Max(agreeIndexes)
|
||||
// ELSE
|
||||
// commitIndex[i]
|
||||
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
|
||||
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||
//
|
||||
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode);
|
||||
bool syncAgreeIndex(SSyncNode* pSyncNode, SRaftId* pRaftId, SyncIndex index);
|
||||
bool syncAgree(SSyncNode* pSyncNode, SyncIndex index);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_LIBS_SYNC_COMMIT_H*/
|
|
@ -236,7 +236,6 @@ void syncNodeCandidate2Follower(SSyncNode* pSyncNode);
|
|||
// raft vote --------------
|
||||
void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId);
|
||||
void syncNodeVoteForSelf(SSyncNode* pSyncNode);
|
||||
void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode);
|
||||
|
||||
// for debug --------------
|
||||
void syncNodePrint(SSyncNode* pObj);
|
||||
|
|
|
@ -25,6 +25,46 @@ extern "C" {
|
|||
#include <stdlib.h>
|
||||
#include "taosdef.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// Receive(m) ==
|
||||
// LET i == m.mdest
|
||||
// j == m.msource
|
||||
// IN \* Any RPC with a newer term causes the recipient to advance
|
||||
// \* its term first. Responses with stale terms are ignored.
|
||||
// \/ UpdateTerm(i, j, m)
|
||||
// \/ /\ m.mtype = RequestVoteRequest
|
||||
// /\ HandleRequestVoteRequest(i, j, m)
|
||||
// \/ /\ m.mtype = RequestVoteResponse
|
||||
// /\ \/ DropStaleResponse(i, j, m)
|
||||
// \/ HandleRequestVoteResponse(i, j, m)
|
||||
// \/ /\ m.mtype = AppendEntriesRequest
|
||||
// /\ HandleAppendEntriesRequest(i, j, m)
|
||||
// \/ /\ m.mtype = AppendEntriesResponse
|
||||
// /\ \/ DropStaleResponse(i, j, m)
|
||||
// \/ HandleAppendEntriesResponse(i, j, m)
|
||||
|
||||
// DuplicateMessage(m) ==
|
||||
// /\ Send(m)
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
// DropMessage(m) ==
|
||||
// /\ Discard(m)
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
// Next == /\ \/ \E i \in Server : Restart(i)
|
||||
// \/ \E i \in Server : Timeout(i)
|
||||
// \/ \E i,j \in Server : RequestVote(i, j)
|
||||
// \/ \E i \in Server : BecomeLeader(i)
|
||||
// \/ \E i \in Server, v \in Value : ClientRequest(i, v)
|
||||
// \/ \E i \in Server : AdvanceCommitIndex(i)
|
||||
// \/ \E i,j \in Server : AppendEntries(i, j)
|
||||
// \/ \E m \in DOMAIN messages : Receive(m)
|
||||
// \/ \E m \in DOMAIN messages : DuplicateMessage(m)
|
||||
// \/ \E m \in DOMAIN messages : DropMessage(m)
|
||||
// \* History variable that tracks every log ever:
|
||||
// /\ allLogs' = allLogs \cup {log[i] : i \in Server}
|
||||
//
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -94,6 +94,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
}
|
||||
assert(pMsg->term <= ths->pRaftStore->currentTerm);
|
||||
|
||||
// reset elect timer
|
||||
if (pMsg->term == ths->pRaftStore->currentTerm) {
|
||||
ths->leaderCache = pMsg->srcId;
|
||||
syncNodeResetElectTimer(ths);
|
||||
|
@ -135,38 +136,117 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
||||
syncNodeBecomeFollower(ths);
|
||||
|
||||
// need ret?
|
||||
// ret or reply?
|
||||
return ret;
|
||||
}
|
||||
|
||||
// accept request
|
||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) {
|
||||
bool matchSuccess = false;
|
||||
bool preMatch = false;
|
||||
if (pMsg->prevLogIndex == SYNC_INDEX_INVALID &&
|
||||
ths->pLogStore->getLastIndex(ths->pLogStore) == SYNC_INDEX_INVALID) {
|
||||
matchSuccess = true;
|
||||
preMatch = true;
|
||||
}
|
||||
if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||
SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore, pMsg->prevLogIndex);
|
||||
assert(pPreEntry != NULL);
|
||||
if (pMsg->prevLogTerm == pPreEntry->term) {
|
||||
matchSuccess = true;
|
||||
preMatch = true;
|
||||
}
|
||||
syncEntryDestory(pPreEntry);
|
||||
}
|
||||
|
||||
if (matchSuccess) {
|
||||
// delete conflict entries
|
||||
if (pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||
SyncIndex fromIndex = pMsg->prevLogIndex + 1;
|
||||
ths->pLogStore->truncate(ths->pLogStore, fromIndex);
|
||||
}
|
||||
if (preMatch) {
|
||||
// must has preIndex in local log
|
||||
assert(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore));
|
||||
|
||||
// append one entry
|
||||
if (pMsg->dataLen > 0) {
|
||||
SSyncRaftEntry* pEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
||||
ths->pLogStore->appendEntry(ths->pLogStore, pEntry);
|
||||
syncEntryDestory(pEntry);
|
||||
bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore);
|
||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
||||
|
||||
if (hasExtraEntries && hasAppendEntries) {
|
||||
// conflict
|
||||
bool conflict = false;
|
||||
|
||||
SyncIndex extraIndex = pMsg->prevLogIndex + 1;
|
||||
SSyncRaftEntry* pExtraEntry = logStoreGetEntry(ths->pLogStore, extraIndex);
|
||||
assert(pExtraEntry != NULL);
|
||||
|
||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
||||
assert(pAppendEntry != NULL);
|
||||
|
||||
assert(extraIndex == pAppendEntry->index);
|
||||
if (pExtraEntry->term == pAppendEntry->term) {
|
||||
conflict = true;
|
||||
}
|
||||
|
||||
if (conflict) {
|
||||
// roll back
|
||||
SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore);
|
||||
SyncIndex delEnd = extraIndex;
|
||||
|
||||
// notice! reverse roll back!
|
||||
for (SyncIndex index = delEnd; index >= delBegin; --index) {
|
||||
if (ths->pFsm->FpRollBackCb != NULL) {
|
||||
SSyncRaftEntry* pRollBackEntry = logStoreGetEntry(ths->pLogStore, index);
|
||||
assert(pRollBackEntry != NULL);
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg);
|
||||
ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, pRollBackEntry->index, pRollBackEntry->isWeak, 0);
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncEntryDestory(pRollBackEntry);
|
||||
}
|
||||
}
|
||||
|
||||
// delete confict entries
|
||||
ths->pLogStore->truncate(ths->pLogStore, extraIndex);
|
||||
|
||||
// append new entries
|
||||
ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry);
|
||||
|
||||
// pre commit
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pAppendEntry, &rpcMsg);
|
||||
if (ths->pFsm != NULL) {
|
||||
if (ths->pFsm->FpPreCommitCb != NULL) {
|
||||
ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 0);
|
||||
}
|
||||
}
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
}
|
||||
|
||||
// free memory
|
||||
syncEntryDestory(pExtraEntry);
|
||||
syncEntryDestory(pAppendEntry);
|
||||
|
||||
} else if (hasExtraEntries && !hasAppendEntries) {
|
||||
// do nothing
|
||||
|
||||
} else if (!hasExtraEntries && hasAppendEntries) {
|
||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
||||
assert(pAppendEntry != NULL);
|
||||
|
||||
// append new entries
|
||||
ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry);
|
||||
|
||||
// pre commit
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pAppendEntry, &rpcMsg);
|
||||
if (ths->pFsm != NULL) {
|
||||
if (ths->pFsm->FpPreCommitCb != NULL) {
|
||||
ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, pAppendEntry->index, pAppendEntry->isWeak, 0);
|
||||
}
|
||||
}
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
// free memory
|
||||
syncEntryDestory(pAppendEntry);
|
||||
|
||||
} else if (!hasExtraEntries && !hasAppendEntries) {
|
||||
// do nothing
|
||||
|
||||
} else {
|
||||
assert(0);
|
||||
}
|
||||
|
||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild();
|
||||
|
@ -175,7 +255,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
pReply->term = ths->pRaftStore->currentTerm;
|
||||
pReply->success = true;
|
||||
|
||||
if (pMsg->dataLen > 0) {
|
||||
if (hasAppendEntries) {
|
||||
pReply->matchIndex = pMsg->prevLogIndex + 1;
|
||||
} else {
|
||||
pReply->matchIndex = pMsg->prevLogIndex;
|
||||
|
@ -201,11 +281,38 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
syncAppendEntriesReplyDestroy(pReply);
|
||||
}
|
||||
|
||||
// maybe update commit index from leader
|
||||
if (pMsg->commitIndex > ths->commitIndex) {
|
||||
// has commit entry in local
|
||||
if (pMsg->commitIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
||||
// commit
|
||||
SyncIndex beginIndex = ths->commitIndex + 1;
|
||||
SyncIndex endIndex = pMsg->commitIndex;
|
||||
|
||||
// update commit index
|
||||
ths->commitIndex = pMsg->commitIndex;
|
||||
|
||||
// call back Wal
|
||||
ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex);
|
||||
|
||||
// execute fsm
|
||||
if (ths->pFsm != NULL) {
|
||||
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
||||
if (i != SYNC_INDEX_INVALID) {
|
||||
SSyncRaftEntry* pEntry = ths->pLogStore->getEntry(ths->pLogStore, i);
|
||||
assert(pEntry != NULL);
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||
|
||||
if (ths->pFsm->FpCommitCb != NULL) {
|
||||
ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "syncAppendEntriesReply.h"
|
||||
#include "syncCommit.h"
|
||||
#include "syncIndexMgr.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftLog.h"
|
||||
|
@ -59,7 +60,7 @@ int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* p
|
|||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
||||
|
||||
// maybe commit
|
||||
syncNodeMaybeAdvanceCommitIndex(ths);
|
||||
syncMaybeAdvanceCommitIndex(ths);
|
||||
|
||||
} else {
|
||||
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
||||
|
|
|
@ -13,9 +13,12 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "syncCommit.h"
|
||||
#include "syncIndexMgr.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
// \* Leader i advances its commitIndex.
|
||||
// \* This is done as a separate step from handling AppendEntries responses,
|
||||
|
@ -40,28 +43,86 @@
|
|||
// IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex]
|
||||
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||
//
|
||||
void syncNodeMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pNextIndex", pSyncNode->pNextIndex);
|
||||
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pMatchIndex", pSyncNode->pMatchIndex);
|
||||
|
||||
// update commit index
|
||||
|
||||
if (pSyncNode->pFsm != NULL) {
|
||||
SyncIndex beginIndex = SYNC_INDEX_INVALID;
|
||||
SyncIndex endIndex = SYNC_INDEX_INVALID;
|
||||
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
||||
SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, i);
|
||||
SyncIndex newCommitIndex = pSyncNode->commitIndex;
|
||||
for (SyncIndex index = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore); index > pSyncNode->commitIndex;
|
||||
++index) {
|
||||
bool agree = syncAgree(pSyncNode, index);
|
||||
if (agree) {
|
||||
// term
|
||||
SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index);
|
||||
assert(pEntry != NULL);
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||
|
||||
if (pSyncNode->pFsm->FpCommitCb != NULL) {
|
||||
pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0);
|
||||
// cannot commit, even if quorum agree. need check term!
|
||||
if (pEntry->term == pSyncNode->pRaftStore->currentTerm) {
|
||||
// update commit index
|
||||
newCommitIndex = index;
|
||||
break;
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
}
|
||||
|
||||
if (newCommitIndex > pSyncNode->commitIndex) {
|
||||
SyncIndex beginIndex = pSyncNode->commitIndex + 1;
|
||||
SyncIndex endIndex = newCommitIndex;
|
||||
|
||||
// update commit index
|
||||
pSyncNode->commitIndex = newCommitIndex;
|
||||
|
||||
// call back Wal
|
||||
pSyncNode->pLogStore->updateCommitIndex(pSyncNode->pLogStore, pSyncNode->commitIndex);
|
||||
|
||||
// execute fsm
|
||||
if (pSyncNode->pFsm != NULL) {
|
||||
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
||||
if (i != SYNC_INDEX_INVALID) {
|
||||
SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, i);
|
||||
assert(pEntry != NULL);
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||
|
||||
if (pSyncNode->pFsm->FpCommitCb != NULL) {
|
||||
pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &rpcMsg, pEntry->index, pEntry->isWeak, 0);
|
||||
}
|
||||
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
syncEntryDestory(pEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool syncAgreeIndex(SSyncNode* pSyncNode, SRaftId* pRaftId, SyncIndex index) {
|
||||
// I am leader, I agree
|
||||
if (syncUtilSameId(pRaftId, &(pSyncNode->myRaftId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// follower agree
|
||||
SyncIndex matchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, pRaftId);
|
||||
if (matchIndex >= index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// not agree
|
||||
return false;
|
||||
}
|
||||
|
||||
bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
||||
int agreeCount = 0;
|
||||
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||
if (syncAgreeIndex(pSyncNode, &(pSyncNode->replicasId[i]), index)) {
|
||||
++agreeCount;
|
||||
}
|
||||
if (agreeCount >= pSyncNode->quorum) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
#include "sync.h"
|
||||
#include "syncAppendEntries.h"
|
||||
#include "syncAppendEntriesReply.h"
|
||||
#include "syncCommit.h"
|
||||
#include "syncElection.h"
|
||||
#include "syncEnv.h"
|
||||
#include "syncIndexMgr.h"
|
||||
|
@ -59,11 +60,14 @@ int64_t syncStart(const SSyncInfo* pSyncInfo) {
|
|||
int32_t ret = 0;
|
||||
SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
// todo : return ref id
|
||||
return ret;
|
||||
}
|
||||
|
||||
void syncStop(int64_t rid) {
|
||||
SSyncNode* pSyncNode = NULL; // get pointer from rid
|
||||
// todo : get pointer from rid
|
||||
SSyncNode* pSyncNode = NULL;
|
||||
syncNodeClose(pSyncNode);
|
||||
}
|
||||
|
||||
|
@ -73,8 +77,10 @@ int32_t syncReconfig(int64_t rid, const SSyncCfg* pSyncCfg) {
|
|||
}
|
||||
|
||||
int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
||||
int32_t ret = 0;
|
||||
SSyncNode* pSyncNode = NULL; // get pointer from rid
|
||||
int32_t ret = 0;
|
||||
|
||||
// todo : get pointer from rid
|
||||
SSyncNode* pSyncNode = NULL;
|
||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||
SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, 0, isWeak);
|
||||
SRpcMsg rpcMsg;
|
||||
|
@ -85,13 +91,14 @@ int32_t syncForwardToPeer(int64_t rid, const SRpcMsg* pMsg, bool isWeak) {
|
|||
|
||||
} else {
|
||||
sTrace("syncForwardToPeer not leader, %s", syncUtilState2String(pSyncNode->state));
|
||||
ret = -1; // need define err code !!
|
||||
ret = -1; // todo : need define err code !!
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ESyncState syncGetMyRole(int64_t rid) {
|
||||
SSyncNode* pSyncNode = NULL; // get pointer from rid
|
||||
// todo : get pointer from rid
|
||||
SSyncNode* pSyncNode = NULL;
|
||||
return pSyncNode->state;
|
||||
}
|
||||
|
||||
|
@ -150,6 +157,30 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
|||
|
||||
// init life cycle
|
||||
|
||||
// TLA+ Spec
|
||||
// InitHistoryVars == /\ elections = {}
|
||||
// /\ allLogs = {}
|
||||
// /\ voterLog = [i \in Server |-> [j \in {} |-> <<>>]]
|
||||
// InitServerVars == /\ currentTerm = [i \in Server |-> 1]
|
||||
// /\ state = [i \in Server |-> Follower]
|
||||
// /\ votedFor = [i \in Server |-> Nil]
|
||||
// InitCandidateVars == /\ votesResponded = [i \in Server |-> {}]
|
||||
// /\ votesGranted = [i \in Server |-> {}]
|
||||
// \* The values nextIndex[i][i] and matchIndex[i][i] are never read, since the
|
||||
// \* leader does not send itself messages. It's still easier to include these
|
||||
// \* in the functions.
|
||||
// InitLeaderVars == /\ nextIndex = [i \in Server |-> [j \in Server |-> 1]]
|
||||
// /\ matchIndex = [i \in Server |-> [j \in Server |-> 0]]
|
||||
// InitLogVars == /\ log = [i \in Server |-> << >>]
|
||||
// /\ commitIndex = [i \in Server |-> 0]
|
||||
// Init == /\ messages = [m \in {} |-> 0]
|
||||
// /\ InitHistoryVars
|
||||
// /\ InitServerVars
|
||||
// /\ InitCandidateVars
|
||||
// /\ InitLeaderVars
|
||||
// /\ InitLogVars
|
||||
//
|
||||
|
||||
// init TLA+ server vars
|
||||
pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER;
|
||||
pSyncNode->pRaftStore = raftStoreOpen(pSyncNode->raftStorePath);
|
||||
|
@ -170,7 +201,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
|||
// init TLA+ log vars
|
||||
pSyncNode->pLogStore = logStoreCreate(pSyncNode);
|
||||
assert(pSyncNode->pLogStore != NULL);
|
||||
pSyncNode->commitIndex = 0;
|
||||
pSyncNode->commitIndex = SYNC_INDEX_INVALID;
|
||||
|
||||
// init ping timer
|
||||
pSyncNode->pPingTimer = NULL;
|
||||
|
@ -727,6 +758,16 @@ static int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
// TLA+ Spec
|
||||
// ClientRequest(i, v) ==
|
||||
// /\ state[i] = Leader
|
||||
// /\ LET entry == [term |-> currentTerm[i],
|
||||
// value |-> v]
|
||||
// newLog == Append(log[i], entry)
|
||||
// IN log' = [log EXCEPT ![i] = newLog]
|
||||
// /\ UNCHANGED <<messages, serverVars, candidateVars,
|
||||
// leaderVars, commitIndex>>
|
||||
//
|
||||
static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg) {
|
||||
int32_t ret = 0;
|
||||
syncClientRequestLog2("==syncNodeOnClientRequestCb==", pMsg);
|
||||
|
@ -739,9 +780,6 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
|
|||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||
ths->pLogStore->appendEntry(ths->pLogStore, pEntry);
|
||||
|
||||
// only myself, maybe commit
|
||||
syncNodeMaybeAdvanceCommitIndex(ths);
|
||||
|
||||
// start replicate right now!
|
||||
syncNodeReplicate(ths);
|
||||
|
||||
|
@ -756,6 +794,9 @@ static int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg
|
|||
}
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
|
||||
// only myself, maybe commit
|
||||
syncMaybeAdvanceCommitIndex(ths);
|
||||
|
||||
} else {
|
||||
// pre commit
|
||||
SRpcMsg rpcMsg;
|
||||
|
|
|
@ -14,3 +14,43 @@
|
|||
*/
|
||||
|
||||
#include "syncOnMessage.h"
|
||||
|
||||
// TLA+ Spec
|
||||
// Receive(m) ==
|
||||
// LET i == m.mdest
|
||||
// j == m.msource
|
||||
// IN \* Any RPC with a newer term causes the recipient to advance
|
||||
// \* its term first. Responses with stale terms are ignored.
|
||||
// \/ UpdateTerm(i, j, m)
|
||||
// \/ /\ m.mtype = RequestVoteRequest
|
||||
// /\ HandleRequestVoteRequest(i, j, m)
|
||||
// \/ /\ m.mtype = RequestVoteResponse
|
||||
// /\ \/ DropStaleResponse(i, j, m)
|
||||
// \/ HandleRequestVoteResponse(i, j, m)
|
||||
// \/ /\ m.mtype = AppendEntriesRequest
|
||||
// /\ HandleAppendEntriesRequest(i, j, m)
|
||||
// \/ /\ m.mtype = AppendEntriesResponse
|
||||
// /\ \/ DropStaleResponse(i, j, m)
|
||||
// \/ HandleAppendEntriesResponse(i, j, m)
|
||||
|
||||
// DuplicateMessage(m) ==
|
||||
// /\ Send(m)
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
// DropMessage(m) ==
|
||||
// /\ Discard(m)
|
||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||
|
||||
// Next == /\ \/ \E i \in Server : Restart(i)
|
||||
// \/ \E i \in Server : Timeout(i)
|
||||
// \/ \E i,j \in Server : RequestVote(i, j)
|
||||
// \/ \E i \in Server : BecomeLeader(i)
|
||||
// \/ \E i \in Server, v \in Value : ClientRequest(i, v)
|
||||
// \/ \E i \in Server : AdvanceCommitIndex(i)
|
||||
// \/ \E i,j \in Server : AppendEntries(i, j)
|
||||
// \/ \E m \in DOMAIN messages : Receive(m)
|
||||
// \/ \E m \in DOMAIN messages : DuplicateMessage(m)
|
||||
// \/ \E m \in DOMAIN messages : DropMessage(m)
|
||||
// \* History variable that tracks every log ever:
|
||||
// /\ allLogs' = allLogs \cup {log[i] : i \in Server}
|
||||
//
|
|
@ -29,6 +29,8 @@ add_executable(syncPingTimerTest2 "")
|
|||
add_executable(syncPingSelfTest "")
|
||||
add_executable(syncElectTest "")
|
||||
add_executable(syncEncodeTest "")
|
||||
add_executable(syncWriteTest "")
|
||||
add_executable(syncReplicateTest "")
|
||||
|
||||
|
||||
target_sources(syncTest
|
||||
|
@ -155,6 +157,14 @@ target_sources(syncEncodeTest
|
|||
PRIVATE
|
||||
"syncEncodeTest.cpp"
|
||||
)
|
||||
target_sources(syncWriteTest
|
||||
PRIVATE
|
||||
"syncWriteTest.cpp"
|
||||
)
|
||||
target_sources(syncReplicateTest
|
||||
PRIVATE
|
||||
"syncReplicateTest.cpp"
|
||||
)
|
||||
|
||||
|
||||
target_include_directories(syncTest
|
||||
|
@ -317,6 +327,16 @@ target_include_directories(syncEncodeTest
|
|||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncWriteTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
target_include_directories(syncReplicateTest
|
||||
PUBLIC
|
||||
"${CMAKE_SOURCE_DIR}/include/libs/sync"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
|
||||
target_link_libraries(syncTest
|
||||
|
@ -443,6 +463,14 @@ target_link_libraries(syncEncodeTest
|
|||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncWriteTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
target_link_libraries(syncReplicateTest
|
||||
sync
|
||||
gtest_main
|
||||
)
|
||||
|
||||
|
||||
enable_testing()
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
#include "syncRaftLog.h"
|
||||
|
||||
void logTest() {
|
||||
sTrace("--- sync log test: trace");
|
||||
|
@ -25,11 +24,11 @@ int32_t myIndex = 0;
|
|||
|
||||
SRaftId ids[TSDB_MAX_REPLICA];
|
||||
SSyncInfo syncInfo;
|
||||
SSyncFSM* pFsm;
|
||||
SWal* pWal;
|
||||
SSyncNode* pSyncNode;
|
||||
SSyncFSM * pFsm;
|
||||
SWal * pWal;
|
||||
SSyncNode *pSyncNode;
|
||||
|
||||
SSyncNode* syncNodeInit() {
|
||||
SSyncNode *syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
|
@ -54,7 +53,7 @@ SSyncNode* syncNodeInit() {
|
|||
|
||||
syncInfo.pWal = pWal;
|
||||
|
||||
SSyncCfg* pCfg = &syncInfo.syncCfg;
|
||||
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||
pCfg->myIndex = myIndex;
|
||||
pCfg->replicaNum = replicaNum;
|
||||
|
||||
|
@ -81,43 +80,12 @@ SSyncNode* syncNodeInit() {
|
|||
return pSyncNode;
|
||||
}
|
||||
|
||||
SSyncNode* syncInitTest() { return syncNodeInit(); }
|
||||
SSyncNode *syncInitTest() { return syncNodeInit(); }
|
||||
|
||||
void logStoreTest() {
|
||||
logStorePrint2((char*)"logStoreTest", pSyncNode->pLogStore);
|
||||
|
||||
assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_INVALID);
|
||||
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
int32_t dataLen = 10;
|
||||
SSyncRaftEntry* pEntry = syncEntryBuild(dataLen);
|
||||
assert(pEntry != NULL);
|
||||
pEntry->msgType = 1;
|
||||
pEntry->originalRpcType = 2;
|
||||
pEntry->seqNum = 3;
|
||||
pEntry->isWeak = true;
|
||||
pEntry->term = 100;
|
||||
pEntry->index = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) + 1;
|
||||
snprintf(pEntry->data, dataLen, "value%d", i);
|
||||
|
||||
// syncEntryPrint2((char*)"write entry:", pEntry);
|
||||
pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry);
|
||||
syncEntryDestory(pEntry);
|
||||
|
||||
if (i == 0) {
|
||||
assert(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore) == SYNC_INDEX_BEGIN);
|
||||
}
|
||||
}
|
||||
logStorePrint2((char*)"after appendEntry", pSyncNode->pLogStore);
|
||||
|
||||
pSyncNode->pLogStore->truncate(pSyncNode->pLogStore, 3);
|
||||
logStorePrint2((char*)"after truncate 3", pSyncNode->pLogStore);
|
||||
}
|
||||
|
||||
void initRaftId(SSyncNode* pSyncNode) {
|
||||
void initRaftId(SSyncNode *pSyncNode) {
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
ids[i] = pSyncNode->replicasId[i];
|
||||
char* s = syncUtilRaftId2Str(&ids[i]);
|
||||
char *s = syncUtilRaftId2Str(&ids[i]);
|
||||
printf("raftId[%d] : %s\n", i, s);
|
||||
free(s);
|
||||
}
|
||||
|
@ -181,7 +149,7 @@ int main(int argc, char **argv) {
|
|||
myIndex = atoi(argv[1]);
|
||||
}
|
||||
|
||||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
|
@ -210,7 +178,7 @@ int main(int argc, char **argv) {
|
|||
syncEntryPrint2((char *)"==step4==", pMsg4);
|
||||
|
||||
// log, relog
|
||||
SSyncNode* pSyncNode = syncNodeInit();
|
||||
SSyncNode *pSyncNode = syncNodeInit();
|
||||
assert(pSyncNode != NULL);
|
||||
SSyncRaftEntry *pEntry = pMsg4;
|
||||
pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry);
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncEnv.h"
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
void logTest() {
|
||||
sTrace("--- sync log test: trace");
|
||||
sDebug("--- sync log test: debug");
|
||||
sInfo("--- sync log test: info");
|
||||
sWarn("--- sync log test: warn");
|
||||
sError("--- sync log test: error");
|
||||
sFatal("--- sync log test: fatal");
|
||||
}
|
||||
|
||||
uint16_t ports[] = {7010, 7110, 7210, 7310, 7410};
|
||||
int32_t replicaNum = 3;
|
||||
int32_t myIndex = 0;
|
||||
|
||||
SRaftId ids[TSDB_MAX_REPLICA];
|
||||
SSyncInfo syncInfo;
|
||||
SSyncFSM* pFsm;
|
||||
SWal* pWal;
|
||||
SSyncNode* gSyncNode;
|
||||
|
||||
SSyncNode* syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "./elect_test_%d", myIndex);
|
||||
|
||||
int code = walInit();
|
||||
assert(code == 0);
|
||||
SWalCfg walCfg;
|
||||
memset(&walCfg, 0, sizeof(SWalCfg));
|
||||
walCfg.vgId = syncInfo.vgId;
|
||||
walCfg.fsyncPeriod = 1000;
|
||||
walCfg.retentionPeriod = 1000;
|
||||
walCfg.rollPeriod = 1000;
|
||||
walCfg.retentionSize = 1000;
|
||||
walCfg.segSize = 1000;
|
||||
walCfg.level = TAOS_WAL_FSYNC;
|
||||
|
||||
char tmpdir[128];
|
||||
snprintf(tmpdir, sizeof(tmpdir), "./elect_test_wal_%d", myIndex);
|
||||
pWal = walOpen(tmpdir, &walCfg);
|
||||
assert(pWal != NULL);
|
||||
|
||||
syncInfo.pWal = pWal;
|
||||
|
||||
SSyncCfg* pCfg = &syncInfo.syncCfg;
|
||||
pCfg->myIndex = myIndex;
|
||||
pCfg->replicaNum = replicaNum;
|
||||
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
pCfg->nodeInfo[i].nodePort = ports[i];
|
||||
snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1");
|
||||
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
|
||||
}
|
||||
|
||||
SSyncNode* pSyncNode = syncNodeOpen(&syncInfo);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
|
||||
return pSyncNode;
|
||||
}
|
||||
|
||||
SSyncNode* syncInitTest() { return syncNodeInit(); }
|
||||
|
||||
void initRaftId(SSyncNode* pSyncNode) {
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
ids[i] = pSyncNode->replicasId[i];
|
||||
char* s = syncUtilRaftId2Str(&ids[i]);
|
||||
printf("raftId[%d] : %s\n", i, s);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
|
||||
myIndex = 0;
|
||||
if (argc >= 2) {
|
||||
myIndex = atoi(argv[1]);
|
||||
}
|
||||
|
||||
int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
assert(ret == 0);
|
||||
|
||||
gSyncNode = syncInitTest();
|
||||
assert(gSyncNode != NULL);
|
||||
syncNodePrint2((char*)"", gSyncNode);
|
||||
|
||||
initRaftId(gSyncNode);
|
||||
|
||||
//---------------------------
|
||||
while (1) {
|
||||
sTrace("while 1 sleep, state: %d, %s, electTimerLogicClock:%lu, electTimerLogicClockUser:%lu, electTimerMS:%d",
|
||||
gSyncNode->state, syncUtilState2String(gSyncNode->state), gSyncNode->electTimerLogicClock,
|
||||
gSyncNode->electTimerLogicClockUser, gSyncNode->electTimerMS);
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <stdio.h>
|
||||
#include "syncEnv.h"
|
||||
#include "syncIO.h"
|
||||
#include "syncInt.h"
|
||||
#include "syncMessage.h"
|
||||
#include "syncRaftEntry.h"
|
||||
#include "syncRaftLog.h"
|
||||
#include "syncRaftStore.h"
|
||||
#include "syncUtil.h"
|
||||
|
||||
void logTest() {
|
||||
sTrace("--- sync log test: trace");
|
||||
sDebug("--- sync log test: debug");
|
||||
sInfo("--- sync log test: info");
|
||||
sWarn("--- sync log test: warn");
|
||||
sError("--- sync log test: error");
|
||||
sFatal("--- sync log test: fatal");
|
||||
}
|
||||
|
||||
uint16_t ports[] = {7010, 7110, 7210, 7310, 7410};
|
||||
int32_t replicaNum = 1;
|
||||
int32_t myIndex = 0;
|
||||
|
||||
SRaftId ids[TSDB_MAX_REPLICA];
|
||||
SSyncInfo syncInfo;
|
||||
SSyncFSM * pFsm;
|
||||
SWal * pWal;
|
||||
SSyncNode *gSyncNode;
|
||||
|
||||
void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) {
|
||||
printf("==CommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code);
|
||||
syncRpcMsgPrint2((char *)"==CommitCb==", (SRpcMsg *)pBuf);
|
||||
}
|
||||
|
||||
void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) {
|
||||
printf("==PreCommitCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code);
|
||||
syncRpcMsgPrint2((char *)"==PreCommitCb==", (SRpcMsg *)pBuf);
|
||||
}
|
||||
|
||||
void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pBuf, SyncIndex index, bool isWeak, int32_t code) {
|
||||
printf("==RollBackCb== pFsm:%p, index:%ld, isWeak:%d, code:%d \n", pFsm, index, isWeak, code);
|
||||
syncRpcMsgPrint2((char *)"==RollBackCb==", (SRpcMsg *)pBuf);
|
||||
}
|
||||
|
||||
void initFsm() {
|
||||
pFsm = (SSyncFSM *)malloc(sizeof(SSyncFSM));
|
||||
pFsm->FpCommitCb = CommitCb;
|
||||
pFsm->FpPreCommitCb = PreCommitCb;
|
||||
pFsm->FpRollBackCb = RollBackCb;
|
||||
}
|
||||
|
||||
SSyncNode *syncNodeInit() {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
syncInfo.queue = gSyncIO->pMsgQ;
|
||||
syncInfo.FpEqMsg = syncIOEqMsg;
|
||||
syncInfo.pFsm = pFsm;
|
||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./write_test");
|
||||
|
||||
int code = walInit();
|
||||
assert(code == 0);
|
||||
SWalCfg walCfg;
|
||||
memset(&walCfg, 0, sizeof(SWalCfg));
|
||||
walCfg.vgId = syncInfo.vgId;
|
||||
walCfg.fsyncPeriod = 1000;
|
||||
walCfg.retentionPeriod = 1000;
|
||||
walCfg.rollPeriod = 1000;
|
||||
walCfg.retentionSize = 1000;
|
||||
walCfg.segSize = 1000;
|
||||
walCfg.level = TAOS_WAL_FSYNC;
|
||||
pWal = walOpen("./write_test_wal", &walCfg);
|
||||
assert(pWal != NULL);
|
||||
|
||||
syncInfo.pWal = pWal;
|
||||
|
||||
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||
pCfg->myIndex = myIndex;
|
||||
pCfg->replicaNum = replicaNum;
|
||||
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
pCfg->nodeInfo[i].nodePort = ports[i];
|
||||
snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1");
|
||||
// taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn);
|
||||
}
|
||||
|
||||
SSyncNode *pSyncNode = syncNodeOpen(&syncInfo);
|
||||
assert(pSyncNode != NULL);
|
||||
|
||||
gSyncIO->FpOnSyncPing = pSyncNode->FpOnPing;
|
||||
gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||
gSyncIO->pSyncNode = pSyncNode;
|
||||
|
||||
return pSyncNode;
|
||||
}
|
||||
|
||||
SSyncNode *syncInitTest() { return syncNodeInit(); }
|
||||
|
||||
void initRaftId(SSyncNode *pSyncNode) {
|
||||
for (int i = 0; i < replicaNum; ++i) {
|
||||
ids[i] = pSyncNode->replicasId[i];
|
||||
char *s = syncUtilRaftId2Str(&ids[i]);
|
||||
printf("raftId[%d] : %s\n", i, s);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
SRpcMsg *step0() {
|
||||
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg));
|
||||
memset(pMsg, 0, sizeof(SRpcMsg));
|
||||
pMsg->msgType = 9999;
|
||||
pMsg->contLen = 32;
|
||||
pMsg->pCont = malloc(pMsg->contLen);
|
||||
snprintf((char *)(pMsg->pCont), pMsg->contLen, "hello, world");
|
||||
return pMsg;
|
||||
}
|
||||
|
||||
SyncClientRequest *step1(const SRpcMsg *pMsg) {
|
||||
SyncClientRequest *pRetMsg = syncClientRequestBuild2(pMsg, 123, true);
|
||||
return pRetMsg;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143 + 64;
|
||||
void logTest();
|
||||
|
||||
myIndex = 0;
|
||||
if (argc >= 2) {
|
||||
myIndex = atoi(argv[1]);
|
||||
}
|
||||
|
||||
int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]);
|
||||
assert(ret == 0);
|
||||
|
||||
ret = syncEnvStart();
|
||||
assert(ret == 0);
|
||||
|
||||
taosRemoveDir("./wal_test");
|
||||
|
||||
initFsm();
|
||||
|
||||
gSyncNode = syncInitTest();
|
||||
assert(gSyncNode != NULL);
|
||||
syncNodePrint2((char *)"", gSyncNode);
|
||||
|
||||
initRaftId(gSyncNode);
|
||||
|
||||
// step0
|
||||
SRpcMsg *pMsg0 = step0();
|
||||
syncRpcMsgPrint2((char *)"==step0==", pMsg0);
|
||||
|
||||
// step1
|
||||
SyncClientRequest *pMsg1 = step1(pMsg0);
|
||||
syncClientRequestPrint2((char *)"==step1==", pMsg1);
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
SyncClientRequest *pSyncClientRequest = pMsg1;
|
||||
SRpcMsg rpcMsg;
|
||||
syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
||||
gSyncNode->FpEqMsg(gSyncNode->queue, &rpcMsg);
|
||||
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
sTrace("while 1 sleep");
|
||||
taosMsleep(1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -204,7 +204,8 @@ void tfsDirname(const STfsFile *pFile, char *dest) {
|
|||
|
||||
void tfsAbsoluteName(STfs *pTfs, SDiskID diskId, const char *rname, char *aname) {
|
||||
STfsDisk *pDisk = TFS_DISK_AT(pTfs, diskId);
|
||||
snprintf(aname, TMPNAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, rname);
|
||||
|
||||
snprintf(aname, TSDB_FILENAME_LEN, "%s%s%s", pDisk->path, TD_DIRSEP, rname);
|
||||
}
|
||||
|
||||
int32_t tfsRemoveFile(const STfsFile *pFile) { return taosRemoveFile(pFile->aname); }
|
||||
|
|
|
@ -5,9 +5,14 @@ target_include_directories(
|
|||
PUBLIC "${CMAKE_SOURCE_DIR}/include/os"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/util"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/contrib/pthread-win32"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/contrib/pthread"
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/contrib/gnuregex"
|
||||
)
|
||||
# iconv
|
||||
find_path(IconvApiIncludes iconv.h PATHS)
|
||||
if(NOT IconvApiIncludes)
|
||||
add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV)
|
||||
endif ()
|
||||
target_link_libraries(
|
||||
os pthread dl rt m
|
||||
)
|
||||
|
|
|
@ -46,6 +46,23 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */
|
|||
#define O_TEXT LINUX_FILE_NO_TEXT_OPTION
|
||||
#endif
|
||||
|
||||
#if defined(WINDOWS)
|
||||
typedef int32_t FileFd;
|
||||
typedef int32_t SocketFd;
|
||||
#else
|
||||
typedef int32_t FileFd;
|
||||
typedef int32_t SocketFd;
|
||||
#endif
|
||||
|
||||
typedef int32_t FileFd;
|
||||
|
||||
typedef struct TdFile {
|
||||
pthread_rwlock_t rwlock;
|
||||
int refId;
|
||||
FileFd fd;
|
||||
FILE *fp;
|
||||
} * TdFilePtr, TdFile;
|
||||
|
||||
#define FILE_WITH_LOCK 1
|
||||
|
||||
void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, char *dstPath) {
|
||||
|
|
|
@ -81,7 +81,7 @@ void taosSetSystemLocale(const char *inLocale, const char *inCharSet) {
|
|||
}
|
||||
|
||||
if (!taosValidateEncodec(inCharSet)) {
|
||||
printf("Invalid charset:%s, please set the valid charset in config file", inCharSet);
|
||||
printf("Invalid charset:%s, please set the valid charset in config file\n", inCharSet);
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,287 +13,25 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define ALLOW_FORBID_FUNC
|
||||
#define _DEFAULT_SOURCE
|
||||
#include <malloc.h>
|
||||
#include "os.h"
|
||||
#include "tdef.h"
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
#ifndef DISALLOW_NCHAR_WITHOUT_ICONV
|
||||
#include "iconv.h"
|
||||
#endif
|
||||
|
||||
extern int wcwidth(wchar_t c);
|
||||
extern int wcswidth(const wchar_t *s, size_t n);
|
||||
|
||||
int64_t taosStr2int64(const char *str) {
|
||||
char *endptr = NULL;
|
||||
return strtoll(str, &endptr, 10);
|
||||
}
|
||||
|
||||
#ifdef USE_LIBICONV
|
||||
#include "iconv.h"
|
||||
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||
iconv_t cd = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
size_t ucs4_input_len = ucs4_max_len;
|
||||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(cd, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
iconv_close(cd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
size_t ucs4_input_len = mbsLength;
|
||||
size_t outLeft = ucs4_max_len;
|
||||
if (iconv(cd, &mbs, &ucs4_input_len, &ucs4, &outLeft) == -1) {
|
||||
iconv_close(cd);
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
if (len != NULL) {
|
||||
*len = (int32_t)(ucs4_max_len - outLeft);
|
||||
if (*len < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool taosValidateEncodec(const char *encodec) {
|
||||
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
return true;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||
mbstate_t state = {0};
|
||||
int32_t len = (int32_t)wcsnrtombs(NULL, (const wchar_t **)&ucs4, ucs4_max_len / 4, 0, &state);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&state, 0, sizeof(state));
|
||||
len = wcsnrtombs(mbs, (const wchar_t **)&ucs4, ucs4_max_len / 4, (size_t)len, &state);
|
||||
if (len < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbsLength, char *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
mbstate_t state = {0};
|
||||
int32_t retlen = mbsnrtowcs((wchar_t *)ucs4, (const char **)&mbs, mbsLength, ucs4_max_len / 4, &state);
|
||||
*len = retlen;
|
||||
|
||||
return retlen >= 0;
|
||||
}
|
||||
|
||||
bool taosValidateEncodec(const char *encodec) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
|
||||
/*
|
||||
* windows implementation
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if STDC_HEADERS
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
char *malloc(), *realloc();
|
||||
#endif
|
||||
|
||||
/* Always add at least this many bytes when extending the buffer. */
|
||||
#define MIN_CHUNK 64
|
||||
|
||||
/* Read up to (and including) a TERMINATOR from STREAM into *LINEPTR
|
||||
+ OFFSET (and null-terminate it). *LINEPTR is a pointer returned from
|
||||
malloc (or NULL), pointing to *N characters of space. It is realloc'd
|
||||
as necessary. Return the number of characters read (not including the
|
||||
null terminator), or -1 on error or EOF. On a -1 return, the caller
|
||||
should check feof(), if not then errno has been set to indicate
|
||||
the error. */
|
||||
|
||||
int32_t getstr(char **lineptr, size_t *n, FILE *stream, char terminator, int32_t offset) {
|
||||
int32_t nchars_avail; /* Allocated but unused chars in *LINEPTR. */
|
||||
char * read_pos; /* Where we're reading into *LINEPTR. */
|
||||
int32_t ret;
|
||||
|
||||
if (!lineptr || !n || !stream) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!*lineptr) {
|
||||
*n = MIN_CHUNK;
|
||||
*lineptr = malloc(*n);
|
||||
if (!*lineptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
nchars_avail = (int32_t)(*n - offset);
|
||||
read_pos = *lineptr + offset;
|
||||
|
||||
for (;;) {
|
||||
int32_t save_errno;
|
||||
register int32_t c = getc(stream);
|
||||
|
||||
save_errno = errno;
|
||||
|
||||
/* We always want at least one char left in the buffer, since we
|
||||
always (unless we get an error while reading the first char)
|
||||
NUL-terminate the line buffer. */
|
||||
|
||||
assert((*lineptr + *n) == (read_pos + nchars_avail));
|
||||
if (nchars_avail < 2) {
|
||||
if (*n > MIN_CHUNK)
|
||||
*n *= 2;
|
||||
else
|
||||
*n += MIN_CHUNK;
|
||||
|
||||
nchars_avail = (int32_t)(*n + *lineptr - read_pos);
|
||||
char* lineptr1 = realloc(*lineptr, *n);
|
||||
if (!lineptr1) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
*lineptr = lineptr1;
|
||||
|
||||
read_pos = *n - nchars_avail + *lineptr;
|
||||
assert((*lineptr + *n) == (read_pos + nchars_avail));
|
||||
}
|
||||
|
||||
if (ferror(stream)) {
|
||||
/* Might like to return partial line, but there is no
|
||||
place for us to store errno. And we don't want to just
|
||||
lose errno. */
|
||||
errno = save_errno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (c == EOF) {
|
||||
/* Return partial line, if any. */
|
||||
if (read_pos == *lineptr)
|
||||
return -1;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
*read_pos++ = c;
|
||||
nchars_avail--;
|
||||
|
||||
if (c == terminator) /* Return the line. */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Done - NUL terminate and return the number of chars read. */
|
||||
*read_pos = '\0';
|
||||
|
||||
ret = (int32_t)(read_pos - (*lineptr + offset));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t tgetline(char **lineptr, size_t *n, FILE *stream) { return getstr(lineptr, n, stream, '\n', 0); }
|
||||
|
||||
|
||||
/*
|
||||
* Get next token from string *stringp, where tokens are possibly-empty
|
||||
* strings separated by characters from delim.
|
||||
*
|
||||
* Writes NULs into the string at *stringp to end tokens.
|
||||
* delim need not remain constant from call to call.
|
||||
* On return, *stringp points past the last NUL written (if there might
|
||||
* be further tokens), or is NULL (if there are definitely no moretokens).
|
||||
*
|
||||
* If *stringp is NULL, strsep returns NULL.
|
||||
*/
|
||||
char *strsep(char **stringp, const char *delim) {
|
||||
char * s;
|
||||
const char *spanp;
|
||||
int32_t c, sc;
|
||||
char *tok;
|
||||
if ((s = *stringp) == NULL)
|
||||
return (NULL);
|
||||
for (tok = s;;) {
|
||||
c = *s++;
|
||||
spanp = delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
*stringp = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
char *getpass(const char *prefix) {
|
||||
static char passwd[TSDB_PASSWORD_LEN] = {0};
|
||||
memset(passwd, 0, TSDB_PASSWORD_LEN);
|
||||
//printf("%s", prefix);
|
||||
|
||||
int32_t index = 0;
|
||||
char ch;
|
||||
while (index < TSDB_PASSWORD_LEN) {
|
||||
ch = getch();
|
||||
if (ch == '\n' || ch == '\r') {
|
||||
break;
|
||||
} else {
|
||||
passwd[index++] = ch;
|
||||
}
|
||||
}
|
||||
|
||||
return passwd;
|
||||
}
|
||||
|
||||
int32_t twcslen(const wchar_t *wcs) {
|
||||
int32_t *wstr = (int32_t *)wcs;
|
||||
if (NULL == wstr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t n = 0;
|
||||
while (1) {
|
||||
if (0 == *wstr++) {
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
|
||||
for (int32_t i = 0; i < bytes; i += TSDB_NCHAR_SIZE) {
|
||||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes) {
|
||||
for (int32_t i = 0; i < bytes; i += sizeof(TdUcs4)) {
|
||||
int32_t f1 = *(int32_t *)((char *)f1_ucs4 + i);
|
||||
int32_t f2 = *(int32_t *)((char *)f2_ucs4 + i);
|
||||
|
||||
|
@ -327,38 +65,96 @@ int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes) {
|
|||
#endif
|
||||
}
|
||||
|
||||
/* Copy memory to memory until the specified number of bytes
|
||||
has been copied, return pointer to following byte.
|
||||
Overlap is NOT handled correctly. */
|
||||
void *mempcpy(void *dest, const void *src, size_t len) {
|
||||
return (char*)memcpy(dest, src, len) + len;
|
||||
}
|
||||
|
||||
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
|
||||
char *stpcpy (char *dest, const char *src) {
|
||||
size_t len = strlen (src);
|
||||
return (char*)memcpy(dest, src, len + 1) + len;
|
||||
}
|
||||
|
||||
/* Copy no more than N characters of SRC to DEST, returning the address of
|
||||
the terminating '\0' in DEST, if any, or else DEST + N. */
|
||||
char *stpncpy (char *dest, const char *src, size_t n) {
|
||||
size_t size = strnlen (src, n);
|
||||
memcpy (dest, src, size);
|
||||
dest += size;
|
||||
if (size == n)
|
||||
return dest;
|
||||
return memset (dest, '\0', n - size);
|
||||
|
||||
TdUcs4* tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4) {
|
||||
assert(malloc_usable_size(target_ucs4)>=len_ucs4*sizeof(TdUcs4));
|
||||
return memcpy(target_ucs4, source_ucs4, len_ucs4*sizeof(TdUcs4));
|
||||
}
|
||||
|
||||
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) {
|
||||
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
|
||||
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.\n");
|
||||
return -1;
|
||||
#else
|
||||
iconv_t cd = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||
size_t ucs4_input_len = ucs4_max_len;
|
||||
size_t outLen = ucs4_max_len;
|
||||
if (iconv(cd, (char **)&ucs4, &ucs4_input_len, &mbs, &outLen) == -1) {
|
||||
iconv_close(cd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* linux and darwin implementation
|
||||
*/
|
||||
|
||||
int32_t tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int32_t bytes, int8_t ncharSize) {
|
||||
return wcsncmp((wchar_t *)f1_ucs4, (wchar_t *)f2_ucs4, bytes / ncharSize);
|
||||
iconv_close(cd);
|
||||
return (int32_t)(ucs4_max_len - outLen);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4_max_len, int32_t *len) {
|
||||
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
|
||||
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.\n");
|
||||
return -1;
|
||||
#else
|
||||
memset(ucs4, 0, ucs4_max_len);
|
||||
iconv_t cd = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||
size_t ucs4_input_len = mbsLength;
|
||||
size_t outLeft = ucs4_max_len;
|
||||
if (iconv(cd, (char**)&mbs, &ucs4_input_len, (char**)&ucs4, &outLeft) == -1) {
|
||||
iconv_close(cd);
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
if (len != NULL) {
|
||||
*len = (int32_t)(ucs4_max_len - outLeft);
|
||||
if (*len < 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool taosValidateEncodec(const char *encodec) {
|
||||
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV
|
||||
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile TDengine.\n");
|
||||
return true;
|
||||
#else
|
||||
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
|
||||
if (cd == (iconv_t)(-1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
iconv_close(cd);
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t taosUcs4len(TdUcs4 *ucs4) {
|
||||
TdUcs4 *wstr = (TdUcs4 *)ucs4;
|
||||
if (NULL == wstr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t n = 0;
|
||||
while (1) {
|
||||
if (0 == *wstr++) {
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
int32_t taosWcharWidth(TdWchar wchar) { return wcwidth(wchar); }
|
||||
|
||||
int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size) { return wcswidth(pWchar, size); }
|
||||
|
||||
int32_t taosMbToWchar(TdWchar *pWchar, const char *pStr, int32_t size) { return mbtowc(pWchar, pStr, size); }
|
||||
|
||||
int32_t taosMbsToWchars(TdWchar *pWchars, const char *pStrs, int32_t size) { return mbstowcs(pWchars, pStrs, size); }
|
||||
|
||||
int32_t taosWcharToMb(char *pStr, TdWchar wchar) { return wctomb(pStr, wchar); }
|
||||
|
||||
int32_t taosWcharsToMbs(char *pStrs, TdWchar *pWchars, int32_t size) { return wcstombs(pStrs, pWchars, size); }
|
||||
|
|
|
@ -208,7 +208,7 @@ int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight) {
|
|||
if (len1 != len2) {
|
||||
return len1 > len2 ? 1 : -1;
|
||||
} else {
|
||||
int32_t ret = memcmp((wchar_t *)pLeft, (wchar_t *)pRight, len1);
|
||||
int32_t ret = memcmp((TdUcs4 *)pLeft, (TdUcs4 *)pRight, len1);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
|
@ -295,10 +295,10 @@ int32_t patternMatch(const char *patterStr, const char *str, size_t size, const
|
|||
return (str[j] == 0 || j >= size) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH;
|
||||
}
|
||||
|
||||
int32_t WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t size, const SPatternCompareInfo *pInfo) {
|
||||
wchar_t c, c1;
|
||||
wchar_t matchOne = L'_'; // "_"
|
||||
wchar_t matchAll = L'%'; // "%"
|
||||
int32_t WCSPatternMatch(const TdUcs4 *patterStr, const TdUcs4 *str, size_t size, const SPatternCompareInfo *pInfo) {
|
||||
TdUcs4 c, c1;
|
||||
TdUcs4 matchOne = L'_'; // "_"
|
||||
TdUcs4 matchAll = L'%'; // "%"
|
||||
|
||||
int32_t i = 0;
|
||||
int32_t j = 0;
|
||||
|
@ -315,7 +315,7 @@ int32_t WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t siz
|
|||
return TSDB_PATTERN_MATCH;
|
||||
}
|
||||
|
||||
wchar_t accept[3] = {towupper(c), towlower(c), 0};
|
||||
TdUcs4 accept[3] = {towupper(c), towlower(c), 0};
|
||||
while (1) {
|
||||
size_t n = wcscspn(str, accept);
|
||||
|
||||
|
@ -424,10 +424,10 @@ int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight) {
|
|||
|
||||
assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE);
|
||||
|
||||
wchar_t *pattern = calloc(varDataLen(pRight) + 1, sizeof(wchar_t));
|
||||
char *pattern = calloc(varDataLen(pRight) + TSDB_NCHAR_SIZE, 1);
|
||||
memcpy(pattern, varDataVal(pRight), varDataLen(pRight));
|
||||
|
||||
int32_t ret = WCSPatternMatch(pattern, (const wchar_t *)varDataVal(pLeft), varDataLen(pLeft) / TSDB_NCHAR_SIZE, &pInfo);
|
||||
int32_t ret = WCSPatternMatch((TdUcs4*)pattern, (TdUcs4*)varDataVal(pLeft), varDataLen(pLeft) / TSDB_NCHAR_SIZE, &pInfo);
|
||||
free(pattern);
|
||||
|
||||
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
|
||||
|
@ -647,7 +647,7 @@ int32_t doCompare(const char *f1, const char *f2, int32_t type, size_t size) {
|
|||
if (t1->len != t2->len) {
|
||||
return t1->len > t2->len ? 1 : -1;
|
||||
}
|
||||
int32_t ret = memcmp((wchar_t *)t1, (wchar_t *)t2, t2->len);
|
||||
int32_t ret = memcmp((TdUcs4 *)t1, (TdUcs4 *)t2, t2->len);
|
||||
if (ret == 0) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -202,9 +202,16 @@ int32_t tjsonGetUBigIntValue(const SJson* pJson, const char* pName, uint64_t* pV
|
|||
return (errno == ERANGE||errno == EINVAL) ? TSDB_CODE_FAILED:TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tjsonGetUIntValue(const SJson* pJson, const char* pName, uint32_t* pVal) {
|
||||
uint64_t val = 0;
|
||||
int32_t code = tjsonGetUBigIntValue(pJson, pName, &val);
|
||||
*pVal = val;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tjsonGetUTinyIntValue(const SJson* pJson, const char* pName, uint8_t* pVal) {
|
||||
uint64_t val = 0;
|
||||
int32_t code = tjsonGetUBigIntValue(pJson, pName, &val);
|
||||
int32_t code = tjsonGetUBigIntValue(pJson, pName, &val);
|
||||
*pVal = val;
|
||||
return code;
|
||||
}
|
||||
|
@ -239,6 +246,22 @@ int32_t tjsonToObject(const SJson* pJson, const char* pName, FToObject func, voi
|
|||
return func(pJsonObj, pObj);
|
||||
}
|
||||
|
||||
int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, void** pObj, int32_t objSize) {
|
||||
if (objSize <= 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SJson* pJsonObj = tjsonGetObjectItem(pJson, pName);
|
||||
if (NULL == pJsonObj) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
*pObj = calloc(1, objSize);
|
||||
if (NULL == *pObj) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
return func(pJsonObj, *pObj);
|
||||
}
|
||||
|
||||
int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void* pArray, int32_t itemSize) {
|
||||
const cJSON* jArray = tjsonGetObjectItem(pJson, pName);
|
||||
int32_t size = (NULL == jArray ? 0 : tjsonGetArraySize(jArray));
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
|
||||
# ---- insert
|
||||
./test.sh -f tsim/insert/basic0.sim
|
||||
|
||||
# ---- query
|
||||
./test.sh -f tsim/query/interval.sim
|
||||
#======================b1-end===============
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
sleep 50
|
||||
sql connect
|
||||
|
||||
print =============== create database
|
||||
sql create database d1
|
||||
sql show databases
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print $data00 $data01 $data02
|
||||
|
||||
sql use d1
|
||||
|
||||
print =============== create super table, include all type
|
||||
sql create table if not exists stb (ts timestamp, c1 bool, c2 tinyint, c3 smallint, c4 int, c5 bigint, c6 float, c7 double, c8 binary(16), c9 nchar(16), c10 timestamp, c11 tinyint unsigned, c12 smallint unsigned, c13 int unsigned, c14 bigint unsigned) tags (t1 bool, t2 tinyint, t3 smallint, t4 int, t5 bigint, t6 float, t7 double, t8 binary(16), t9 nchar(16), t10 timestamp, t11 tinyint unsigned, t12 smallint unsigned, t13 int unsigned, t14 bigint unsigned)
|
||||
|
||||
sql create stable if not exists stb_1 (ts timestamp, i int) tags (j int)
|
||||
sql create table stb_2 (ts timestamp, i int) tags (j int)
|
||||
sql create stable stb_3 (ts timestamp, i int) tags (j int)
|
||||
|
||||
sql show stables
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== create child table
|
||||
sql create table c1 using stb tags(true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
|
||||
sql create table c2 using stb tags(false, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 2', 'child tbl 2', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
|
||||
|
||||
sql show tables
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
print =============== insert data, mode1: one row one table in sql
|
||||
print =============== insert data, mode1: mulit rows one table in sql
|
||||
print =============== insert data, mode1: one rows mulit table in sql
|
||||
print =============== insert data, mode1: mulit rows mulit table in sql
|
||||
sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
|
||||
sql insert into c1 values(now+0s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+1s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40) (now+2s, true, -1, -2, -3, -4, -6.0, -7.0, 'child tbl 1', 'child tbl 1', '2022-02-25 18:00:00.000', 10, 20, 30, 40)
|
||||
|
||||
print =============== query data
|
||||
sql select * from c1
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != true then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != -1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data03 != -2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== query data from st
|
||||
sql select * from st
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== stop and restart taosd
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
|
||||
sleep 2000
|
||||
print =============== query data
|
||||
sql select * from c1
|
||||
if $rows != 4 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data01 != true then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != -1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data03 != -2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -0,0 +1,292 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
sleep 50
|
||||
sql connect
|
||||
|
||||
print =============== create database
|
||||
sql create database d0
|
||||
sql show databases
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print $data00 $data01 $data02
|
||||
|
||||
sql use d0
|
||||
|
||||
|
||||
sql create table vehicle (ts timestamp, s int) tags (t1 int)
|
||||
sql show stables
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql create table car using vehicle tags(1000)
|
||||
#sql create table ct1 using vehicle tags (1000)
|
||||
sql show tables;
|
||||
if $rows != 1 then
|
||||
print rows: $rows
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql insert into ct1 values('2019-01-01 00:00:00', 1)
|
||||
sql insert into car values('2019-05-13 12:00:00', 1)
|
||||
sql insert into car values('2019-12-31 23:59:59', 1)
|
||||
sql insert into car values('2020-01-01 12:00:00', 1)
|
||||
sql insert into car values('2020-01-02 12:00:00', 1)
|
||||
sql insert into car values('2020-01-03 12:00:00', 1)
|
||||
sql insert into car values('2020-01-04 12:00:00', 1)
|
||||
sql insert into car values('2020-01-05 12:00:00', 1)
|
||||
sql insert into car values('2020-01-31 12:00:00', 1)
|
||||
sql insert into car values('2020-02-01 12:00:00', 1)
|
||||
sql insert into car values('2020-02-02 12:00:00', 1)
|
||||
sql insert into car values('2020-02-29 12:00:00', 1)
|
||||
sql insert into car values('2020-03-01 12:00:00', 1)
|
||||
sql insert into car values('2020-03-02 12:00:00', 1)
|
||||
sql insert into car values('2020-03-15 12:00:00', 1)
|
||||
sql insert into car values('2020-03-31 12:00:00', 1)
|
||||
sql insert into car values('2020-05-01 12:00:00', 1)
|
||||
|
||||
sql select count(*) from car interval(1n, 10d)
|
||||
# tdSql.checkData(0, 1, 1)
|
||||
# tdSql.checkData(1, 1, 1)
|
||||
# tdSql.checkData(2, 1, 6)
|
||||
# tdSql.checkData(3, 1, 3)
|
||||
# tdSql.checkData(4, 1, 3)
|
||||
# tdSql.checkData(5, 1, 2)
|
||||
# tdSql.checkData(6, 1, 1)
|
||||
if $rows != 17 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data20 != 6 then
|
||||
return -1
|
||||
endi
|
||||
if $data30 != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data40 != 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data50 != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data60 != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
return
|
||||
|
||||
sql select count(*) from car interval(1n, 10d) order by ts desc
|
||||
# tdSql.checkData(0, 1, 1)
|
||||
# tdSql.checkData(1, 1, 2)
|
||||
# tdSql.checkData(2, 1, 3)
|
||||
# tdSql.checkData(3, 1, 3)
|
||||
# tdSql.checkData(4, 1, 6)
|
||||
# tdSql.checkData(5, 1, 1)
|
||||
# tdSql.checkData(6, 1, 1)
|
||||
#
|
||||
sql select count(*) from car interval(2n, 5d)
|
||||
# tdSql.checkData(0, 1, 1)
|
||||
# tdSql.checkData(1, 1, 1)
|
||||
# tdSql.checkData(2, 1, 6)
|
||||
# tdSql.checkData(3, 1, 6)
|
||||
# tdSql.checkData(4, 1, 3)
|
||||
|
||||
sql select count(*) from car interval(2n) order by ts desc
|
||||
# tdSql.checkData(0, 1, 3)
|
||||
# tdSql.checkData(1, 1, 6)
|
||||
# tdSql.checkData(2, 1, 6)
|
||||
# tdSql.checkData(3, 1, 1)
|
||||
# tdSql.checkData(4, 1, 1)
|
||||
#
|
||||
sql select count(*) from car interval(1y, 1n)
|
||||
# tdSql.checkData(0, 1, 1)
|
||||
# tdSql.checkData(1, 1, 8)
|
||||
# tdSql.checkData(2, 1, 8)
|
||||
#
|
||||
sql select count(*) from car interval(1y, 2n)
|
||||
# tdSql.checkData(0, 1, 1)
|
||||
# tdSql.checkData(1, 1, 11)
|
||||
# tdSql.checkData(2, 1, 5)
|
||||
|
||||
sql select count(*) from car where ts > '2019-05-14 00:00:00' interval(1y, 5d)
|
||||
# tdSql.checkData(0, 1, 6)
|
||||
# tdSql.checkData(1, 1, 9)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)
|
||||
|
||||
print ====== start create child tables and insert data
|
||||
$i = 0
|
||||
while $i < $tbNum
|
||||
$tb = $tbPrefix . $i
|
||||
sql create table $tb using $mt tags( $i )
|
||||
|
||||
$x = 0
|
||||
while $x < $rowNum
|
||||
$cc = $x * 60000
|
||||
$ms = 1601481600000 + $cc
|
||||
|
||||
sql insert into $tb values ($ms , $x )
|
||||
$x = $x + 1
|
||||
endw
|
||||
|
||||
$i = $i + 1
|
||||
endw
|
||||
|
||||
print =============== step2
|
||||
$i = 1
|
||||
$tb = $tbPrefix . $i
|
||||
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
|
||||
print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
|
||||
print ===> $rows $data01 $data05
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data04 != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
#print =============== step3
|
||||
#$cc = 4 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m)
|
||||
#print ===> $rows $data01 $data05
|
||||
#if $rows != 5 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data00 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data04 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
#print =============== step4
|
||||
#$cc = 40 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m)
|
||||
#print ===> $rows $data01 $data05
|
||||
#if $rows != 20 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data00 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data04 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
#print =============== step5
|
||||
#$cc = 40 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
|
||||
#print ===> $rows $data21 $data25
|
||||
#if $rows != 42 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data20 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data24 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
#print =============== step6
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 20 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
#print =============== step7
|
||||
#$cc = 4 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 5 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
#print =============== step8
|
||||
#$cc = 40 * 60000
|
||||
#$ms1 = 1601481600000 + $cc
|
||||
#
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
#
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 20 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
#
|
||||
#print =============== step9
|
||||
#$cc = 40 * 60000
|
||||
#$ms1 = 1601481600000 + $cc
|
||||
#
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
#
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 42 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== clear
|
||||
#sql drop database $db
|
||||
#sql show databases
|
||||
#if $rows != 0 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -47,161 +47,137 @@ $i = 1
|
|||
$tb = $tbPrefix . $i
|
||||
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
|
||||
print ===> $rows
|
||||
if $rows < $rowNum then
|
||||
print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb interval(1m)
|
||||
print ===> $rows $data01 $data05
|
||||
if $rows != $rowNum then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 1 then
|
||||
if $data00 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != 1 then
|
||||
if $data04 != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== step3
|
||||
$cc = 4 * 60000
|
||||
$ms = 1601481600000 + $cc
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m)
|
||||
print ===> $rows
|
||||
if $rows > 10 then
|
||||
return -1
|
||||
endi
|
||||
if $rows < 3 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != 1 then
|
||||
return -1
|
||||
endi
|
||||
#print =============== step3
|
||||
#$cc = 4 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms interval(1m)
|
||||
#print ===> $rows $data01 $data05
|
||||
#if $rows != 5 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data00 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data04 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== step4
|
||||
$cc = 40 * 60000
|
||||
$ms = 1601481600000 + $cc
|
||||
#print =============== step4
|
||||
#$cc = 40 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
|
||||
$cc = 1 * 60000
|
||||
$ms2 = 1601481600000 - $cc
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m)
|
||||
print ===> $rows
|
||||
if $rows < 18 then
|
||||
return -1
|
||||
endi
|
||||
if $rows > 22 then
|
||||
return -1
|
||||
endi
|
||||
if $data01 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data05 != 1 then
|
||||
return -1
|
||||
endi
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m)
|
||||
#print ===> $rows $data01 $data05
|
||||
#if $rows != 20 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data00 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data04 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== step5
|
||||
$cc = 40 * 60000
|
||||
$ms = 1601481600000 + $cc
|
||||
#print =============== step5
|
||||
#$cc = 40 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
|
||||
$cc = 1 * 60000
|
||||
$ms2 = 1601481600000 - $cc
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
|
||||
print ===> $rows
|
||||
if $rows < 30 then
|
||||
return -1
|
||||
endi
|
||||
if $rows > 50 then
|
||||
return -1
|
||||
endi
|
||||
if $data21 != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data25 != 1 then
|
||||
return -1
|
||||
endi
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $tb where ts <= $ms and ts > $ms2 interval(1m) fill(value,0)
|
||||
#print ===> $rows $data21 $data25
|
||||
#if $rows != 42 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data20 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data24 != 1 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== step6
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
|
||||
print ===> $rows
|
||||
if $rows < 18 then
|
||||
return -1
|
||||
endi
|
||||
if $rows > 22 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 > 15 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 < 5 then
|
||||
return -1
|
||||
endi
|
||||
#print =============== step6
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt interval(1m)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 20 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== step7
|
||||
$cc = 4 * 60000
|
||||
$ms = 1601481600000 + $cc
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m)
|
||||
print ===> $rows
|
||||
if $rows < 3 then
|
||||
return -1
|
||||
endi
|
||||
if $rows > 7 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 > 15 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 < 5 then
|
||||
return -1
|
||||
endi
|
||||
#print =============== step7
|
||||
#$cc = 4 * 60000
|
||||
#$ms = 1601481600000 + $cc
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms interval(1m)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 5 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== step8
|
||||
$cc = 40 * 60000
|
||||
$ms1 = 1601481600000 + $cc
|
||||
|
||||
$cc = 1 * 60000
|
||||
$ms2 = 1601481600000 - $cc
|
||||
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m)
|
||||
print ===> $rows
|
||||
if $rows < 18 then
|
||||
return -1
|
||||
endi
|
||||
if $rows > 22 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 > 15 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 < 5 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print =============== step9
|
||||
$cc = 40 * 60000
|
||||
$ms1 = 1601481600000 + $cc
|
||||
|
||||
$cc = 1 * 60000
|
||||
$ms2 = 1601481600000 - $cc
|
||||
|
||||
sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
|
||||
if $rows < 30 then
|
||||
return -1
|
||||
endi
|
||||
if $rows > 50 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 > 15 then
|
||||
return -1
|
||||
endi
|
||||
if $data11 < 5 then
|
||||
return -1
|
||||
endi
|
||||
#print =============== step8
|
||||
#$cc = 40 * 60000
|
||||
#$ms1 = 1601481600000 + $cc
|
||||
#
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
#
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 20 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
#
|
||||
#print =============== step9
|
||||
#$cc = 40 * 60000
|
||||
#$ms1 = 1601481600000 + $cc
|
||||
#
|
||||
#$cc = 1 * 60000
|
||||
#$ms2 = 1601481600000 - $cc
|
||||
#
|
||||
#sql select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
|
||||
#print ===> select count(tbcol), sum(tbcol), max(tbcol), min(tbcol), count(tbcol) from $mt where ts <= $ms1 and ts > $ms2 interval(1m) fill(value, 0)
|
||||
#print ===> $rows $data11
|
||||
#if $rows != 42 then
|
||||
# return -1
|
||||
#endi
|
||||
#if $data11 != 10 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
print =============== clear
|
||||
sql drop database $db
|
||||
sql show databases
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
#sql drop database $db
|
||||
#sql show databases
|
||||
#if $rows != 0 then
|
||||
# return -1
|
||||
#endi
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
#system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
int indicator = 1;
|
||||
struct termios oldtio;
|
||||
|
||||
extern int wcwidth(wchar_t c);
|
||||
void insertChar(Command *cmd, char *c, int size);
|
||||
|
||||
|
||||
|
@ -426,7 +425,7 @@ void showOnScreen(Command *cmd) {
|
|||
w.ws_row = 30;
|
||||
}
|
||||
|
||||
wchar_t wc;
|
||||
TdWchar wc;
|
||||
int size = 0;
|
||||
|
||||
// Print out the command.
|
||||
|
@ -441,11 +440,11 @@ void showOnScreen(Command *cmd) {
|
|||
int remain_column = w.ws_col;
|
||||
/* size = cmd->commandSize + prompt_size; */
|
||||
for (char *str = total_string; size < cmd->commandSize + prompt_size;) {
|
||||
int ret = mbtowc(&wc, str, MB_CUR_MAX);
|
||||
int ret = taosMbToWchar(&wc, str, MB_CUR_MAX);
|
||||
if (ret < 0) break;
|
||||
size += ret;
|
||||
/* assert(size >= 0); */
|
||||
int width = wcwidth(wc);
|
||||
int width = taosWcharWidth(wc);
|
||||
if (remain_column > width) {
|
||||
printf("%lc", wc);
|
||||
remain_column -= width;
|
||||
|
|
|
@ -21,8 +21,6 @@
|
|||
|
||||
#include <regex.h>
|
||||
|
||||
extern int wcwidth(wchar_t c);
|
||||
extern int wcswidth(const wchar_t *s, size_t n);
|
||||
typedef struct {
|
||||
char widthInString;
|
||||
char widthOnScreen;
|
||||
|
@ -43,7 +41,7 @@ int countPrefixOnes(unsigned char c) {
|
|||
void getPrevCharSize(const char *str, int pos, int *size, int *width) {
|
||||
assert(pos > 0);
|
||||
|
||||
wchar_t wc;
|
||||
TdWchar wc;
|
||||
*size = 0;
|
||||
*width = 0;
|
||||
|
||||
|
@ -53,25 +51,25 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
|
|||
if (str[pos] > 0 || countPrefixOnes((unsigned char )str[pos]) > 1) break;
|
||||
}
|
||||
|
||||
int rc = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
||||
int rc = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
|
||||
assert(rc == *size);
|
||||
|
||||
*width = wcwidth(wc);
|
||||
*width = taosWcharWidth(wc);
|
||||
}
|
||||
|
||||
void getNextCharSize(const char *str, int pos, int *size, int *width) {
|
||||
assert(pos >= 0);
|
||||
|
||||
wchar_t wc;
|
||||
*size = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
||||
*width = wcwidth(wc);
|
||||
TdWchar wc;
|
||||
*size = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
|
||||
*width = taosWcharWidth(wc);
|
||||
}
|
||||
|
||||
void insertChar(Command *cmd, char *c, int size) {
|
||||
assert(cmd->cursorOffset <= cmd->commandSize && cmd->endOffset >= cmd->screenOffset);
|
||||
|
||||
wchar_t wc;
|
||||
if (mbtowc(&wc, c, size) < 0) return;
|
||||
TdWchar wc;
|
||||
if (taosMbToWchar(&wc, c, size) < 0) return;
|
||||
|
||||
clearScreen(cmd->endOffset + prompt_size, cmd->screenOffset + prompt_size);
|
||||
/* update the buffer */
|
||||
|
@ -81,8 +79,8 @@ void insertChar(Command *cmd, char *c, int size) {
|
|||
/* update the values */
|
||||
cmd->commandSize += size;
|
||||
cmd->cursorOffset += size;
|
||||
cmd->screenOffset += wcwidth(wc);
|
||||
cmd->endOffset += wcwidth(wc);
|
||||
cmd->screenOffset += taosWcharWidth(wc);
|
||||
cmd->endOffset += taosWcharWidth(wc);
|
||||
showOnScreen(cmd);
|
||||
}
|
||||
|
||||
|
@ -249,10 +247,10 @@ int isReadyGo(Command *cmd) {
|
|||
}
|
||||
|
||||
void getMbSizeInfo(const char *str, int *size, int *width) {
|
||||
wchar_t *wc = (wchar_t *)calloc(sizeof(wchar_t), MAX_COMMAND_SIZE);
|
||||
TdWchar *wc = (TdWchar *)calloc(sizeof(TdWchar), MAX_COMMAND_SIZE);
|
||||
*size = strlen(str);
|
||||
mbstowcs(wc, str, MAX_COMMAND_SIZE);
|
||||
*width = wcswidth(wc, MAX_COMMAND_SIZE);
|
||||
taosMbsToWchars(wc, str, MAX_COMMAND_SIZE);
|
||||
*width = taosWcharsWidth(wc, MAX_COMMAND_SIZE);
|
||||
free(wc);
|
||||
}
|
||||
|
||||
|
|
|
@ -560,12 +560,12 @@ static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
|
|||
}
|
||||
|
||||
static void shellPrintNChar(const char *str, int length, int width) {
|
||||
wchar_t tail[3];
|
||||
TdWchar tail[3];
|
||||
int pos = 0, cols = 0, totalCols = 0, tailLen = 0;
|
||||
|
||||
while (pos < length) {
|
||||
wchar_t wc;
|
||||
int bytes = mbtowc(&wc, str + pos, MB_CUR_MAX);
|
||||
TdWchar wc;
|
||||
int bytes = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
|
||||
if (bytes == 0) {
|
||||
break;
|
||||
}
|
||||
|
@ -577,7 +577,7 @@ static void shellPrintNChar(const char *str, int length, int width) {
|
|||
#ifdef WINDOWS
|
||||
int w = bytes;
|
||||
#else
|
||||
int w = wcwidth(wc);
|
||||
int w = taosWcharWidth(wc);
|
||||
#endif
|
||||
if (w <= 0) {
|
||||
continue;
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
int indicator = 1;
|
||||
struct termios oldtio;
|
||||
|
||||
extern int wcwidth(wchar_t c);
|
||||
void insertChar(Command *cmd, char *c, int size);
|
||||
const char *argp_program_version = version;
|
||||
const char *argp_program_bug_address = "<support@taosdata.com>";
|
||||
|
@ -456,7 +455,7 @@ void showOnScreen(Command *cmd) {
|
|||
w.ws_row = 30;
|
||||
}
|
||||
|
||||
wchar_t wc;
|
||||
TdWchar wc;
|
||||
int size = 0;
|
||||
|
||||
// Print out the command.
|
||||
|
@ -471,11 +470,11 @@ void showOnScreen(Command *cmd) {
|
|||
int remain_column = w.ws_col;
|
||||
/* size = cmd->commandSize + prompt_size; */
|
||||
for (char *str = total_string; size < cmd->commandSize + prompt_size;) {
|
||||
int ret = mbtowc(&wc, str, MB_CUR_MAX);
|
||||
int ret = taosMbToWchar(&wc, str, MB_CUR_MAX);
|
||||
if (ret < 0) break;
|
||||
size += ret;
|
||||
/* assert(size >= 0); */
|
||||
int width = wcwidth(wc);
|
||||
int width = taosWcharWidth(wc);
|
||||
if (remain_column > width) {
|
||||
printf("%lc", wc);
|
||||
remain_column -= width;
|
||||
|
|
Loading…
Reference in New Issue