提交 6d449c82 编写于 作者: X Xiaoyu Wang

enh: refactor db and table options

上级 86d07776
...@@ -67,101 +67,101 @@ ...@@ -67,101 +67,101 @@
#define TK_IF 49 #define TK_IF 49
#define TK_NOT 50 #define TK_NOT 50
#define TK_EXISTS 51 #define TK_EXISTS 51
#define TK_BLOCKS 52 #define TK_BUFFER 52
#define TK_CACHE 53 #define TK_CACHELAST 53
#define TK_CACHELAST 54 #define TK_COMP 54
#define TK_COMP 55 #define TK_DAYS 55
#define TK_DAYS 56 #define TK_NK_VARIABLE 56
#define TK_NK_VARIABLE 57 #define TK_FSYNC 57
#define TK_FSYNC 58 #define TK_MAXROWS 58
#define TK_MAXROWS 59 #define TK_MINROWS 59
#define TK_MINROWS 60 #define TK_KEEP 60
#define TK_KEEP 61 #define TK_PAGES 61
#define TK_PRECISION 62 #define TK_PAGESIZE 62
#define TK_QUORUM 63 #define TK_PRECISION 63
#define TK_REPLICA 64 #define TK_REPLICA 64
#define TK_TTL 65 #define TK_STRICT 65
#define TK_WAL 66 #define TK_WAL 66
#define TK_VGROUPS 67 #define TK_VGROUPS 67
#define TK_SINGLE_STABLE 68 #define TK_SINGLE_STABLE 68
#define TK_STREAM_MODE 69 #define TK_RETENTIONS 69
#define TK_RETENTIONS 70 #define TK_NK_COMMA 70
#define TK_STRICT 71 #define TK_NK_COLON 71
#define TK_NK_COMMA 72 #define TK_TABLE 72
#define TK_NK_COLON 73 #define TK_NK_LP 73
#define TK_TABLE 74 #define TK_NK_RP 74
#define TK_NK_LP 75 #define TK_STABLE 75
#define TK_NK_RP 76 #define TK_ADD 76
#define TK_STABLE 77 #define TK_COLUMN 77
#define TK_ADD 78 #define TK_MODIFY 78
#define TK_COLUMN 79 #define TK_RENAME 79
#define TK_MODIFY 80 #define TK_TAG 80
#define TK_RENAME 81 #define TK_SET 81
#define TK_TAG 82 #define TK_NK_EQ 82
#define TK_SET 83 #define TK_USING 83
#define TK_NK_EQ 84 #define TK_TAGS 84
#define TK_USING 85 #define TK_NK_DOT 85
#define TK_TAGS 86 #define TK_COMMENT 86
#define TK_NK_DOT 87 #define TK_BOOL 87
#define TK_COMMENT 88 #define TK_TINYINT 88
#define TK_BOOL 89 #define TK_SMALLINT 89
#define TK_TINYINT 90 #define TK_INT 90
#define TK_SMALLINT 91 #define TK_INTEGER 91
#define TK_INT 92 #define TK_BIGINT 92
#define TK_INTEGER 93 #define TK_FLOAT 93
#define TK_BIGINT 94 #define TK_DOUBLE 94
#define TK_FLOAT 95 #define TK_BINARY 95
#define TK_DOUBLE 96 #define TK_TIMESTAMP 96
#define TK_BINARY 97 #define TK_NCHAR 97
#define TK_TIMESTAMP 98 #define TK_UNSIGNED 98
#define TK_NCHAR 99 #define TK_JSON 99
#define TK_UNSIGNED 100 #define TK_VARCHAR 100
#define TK_JSON 101 #define TK_MEDIUMBLOB 101
#define TK_VARCHAR 102 #define TK_BLOB 102
#define TK_MEDIUMBLOB 103 #define TK_VARBINARY 103
#define TK_BLOB 104 #define TK_DECIMAL 104
#define TK_VARBINARY 105 #define TK_DELAY 105
#define TK_DECIMAL 106 #define TK_FILE_FACTOR 106
#define TK_SMA 107 #define TK_NK_FLOAT 107
#define TK_ROLLUP 108 #define TK_ROLLUP 108
#define TK_FILE_FACTOR 109 #define TK_TTL 109
#define TK_NK_FLOAT 110 #define TK_SMA 110
#define TK_DELAY 111 #define TK_SHOW 111
#define TK_SHOW 112 #define TK_DATABASES 112
#define TK_DATABASES 113 #define TK_TABLES 113
#define TK_TABLES 114 #define TK_STABLES 114
#define TK_STABLES 115 #define TK_MNODES 115
#define TK_MNODES 116 #define TK_MODULES 116
#define TK_MODULES 117 #define TK_QNODES 117
#define TK_QNODES 118 #define TK_FUNCTIONS 118
#define TK_FUNCTIONS 119 #define TK_INDEXES 119
#define TK_INDEXES 120 #define TK_FROM 120
#define TK_FROM 121 #define TK_ACCOUNTS 121
#define TK_ACCOUNTS 122 #define TK_APPS 122
#define TK_APPS 123 #define TK_CONNECTIONS 123
#define TK_CONNECTIONS 124 #define TK_LICENCE 124
#define TK_LICENCE 125 #define TK_GRANTS 125
#define TK_GRANTS 126 #define TK_QUERIES 126
#define TK_QUERIES 127 #define TK_SCORES 127
#define TK_SCORES 128 #define TK_TOPICS 128
#define TK_TOPICS 129 #define TK_VARIABLES 129
#define TK_VARIABLES 130 #define TK_BNODES 130
#define TK_BNODES 131 #define TK_SNODES 131
#define TK_SNODES 132 #define TK_CLUSTER 132
#define TK_CLUSTER 133 #define TK_LIKE 133
#define TK_LIKE 134 #define TK_INDEX 134
#define TK_INDEX 135 #define TK_FULLTEXT 135
#define TK_FULLTEXT 136 #define TK_FUNCTION 136
#define TK_FUNCTION 137 #define TK_INTERVAL 137
#define TK_INTERVAL 138 #define TK_TOPIC 138
#define TK_TOPIC 139 #define TK_AS 139
#define TK_AS 140 #define TK_WITH 140
#define TK_WITH 141 #define TK_SCHEMA 141
#define TK_SCHEMA 142 #define TK_DESC 142
#define TK_DESC 143 #define TK_DESCRIBE 143
#define TK_DESCRIBE 144 #define TK_RESET 144
#define TK_RESET 145 #define TK_QUERY 145
#define TK_QUERY 146 #define TK_CACHE 146
#define TK_EXPLAIN 147 #define TK_EXPLAIN 147
#define TK_ANALYZE 148 #define TK_ANALYZE 148
#define TK_VERBOSE 149 #define TK_VERBOSE 149
......
...@@ -30,24 +30,25 @@ extern "C" { ...@@ -30,24 +30,25 @@ extern "C" {
typedef struct SDatabaseOptions { typedef struct SDatabaseOptions {
ENodeType type; ENodeType type;
SValueNode* pNumOfBlocks; int32_t buffer;
SValueNode* pCacheBlockSize; int8_t cachelast;
SValueNode* pCachelast; int8_t compressionLevel;
SValueNode* pCompressionLevel; int32_t daysPerFile;
SValueNode* pDaysPerFile; SValueNode* pDaysPerFile;
SValueNode* pFsyncPeriod; int32_t fsyncPeriod;
SValueNode* pMaxRowsPerBlock; int32_t maxRowsPerBlock;
SValueNode* pMinRowsPerBlock; int32_t minRowsPerBlock;
SNodeList* pKeep; SNodeList* pKeep;
SValueNode* pPrecision; int32_t keep[3];
SValueNode* pQuorum; int32_t pages;
SValueNode* pReplica; int32_t pagesize;
SValueNode* pTtl; char precisionStr[3];
SValueNode* pWalLevel; int8_t precision;
SValueNode* pNumOfVgroups; int8_t replica;
SValueNode* pSingleStable; int8_t strict;
SValueNode* pStreamMode; int8_t walLevel;
SValueNode* pStrict; int32_t numOfVgroups;
int8_t singleStable;
SNodeList* pRetentions; SNodeList* pRetentions;
} SDatabaseOptions; } SDatabaseOptions;
...@@ -77,13 +78,12 @@ typedef struct SAlterDatabaseStmt { ...@@ -77,13 +78,12 @@ typedef struct SAlterDatabaseStmt {
typedef struct STableOptions { typedef struct STableOptions {
ENodeType type; ENodeType type;
SNodeList* pKeep; char comment[TSDB_STB_COMMENT_LEN];
SValueNode* pTtl; int32_t delay;
SValueNode* pComments; float filesFactor;
SNodeList* pRollupFuncs;
int32_t ttl;
SNodeList* pSma; SNodeList* pSma;
SNodeList* pFuncs;
SValueNode* pFilesFactor;
SValueNode* pDelay;
} STableOptions; } STableOptions;
typedef struct SColumnDefNode { typedef struct SColumnDefNode {
...@@ -201,10 +201,7 @@ typedef struct SShowCreatStmt { ...@@ -201,10 +201,7 @@ typedef struct SShowCreatStmt {
char tableName[TSDB_TABLE_NAME_LEN]; char tableName[TSDB_TABLE_NAME_LEN];
} SShowCreatStmt; } SShowCreatStmt;
typedef enum EIndexType { typedef enum EIndexType { INDEX_TYPE_SMA = 1, INDEX_TYPE_FULLTEXT } EIndexType;
INDEX_TYPE_SMA = 1,
INDEX_TYPE_FULLTEXT
} EIndexType;
typedef struct SIndexOptions { typedef struct SIndexOptions {
ENodeType type; ENodeType type;
......
...@@ -586,7 +586,6 @@ int32_t* taosGetErrno(); ...@@ -586,7 +586,6 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_INVALID_RANGE_OPTION TAOS_DEF_ERROR_CODE(0, 0x2619) #define TSDB_CODE_PAR_INVALID_RANGE_OPTION TAOS_DEF_ERROR_CODE(0, 0x2619)
#define TSDB_CODE_PAR_INVALID_STR_OPTION TAOS_DEF_ERROR_CODE(0, 0x261A) #define TSDB_CODE_PAR_INVALID_STR_OPTION TAOS_DEF_ERROR_CODE(0, 0x261A)
#define TSDB_CODE_PAR_INVALID_ENUM_OPTION TAOS_DEF_ERROR_CODE(0, 0x261B) #define TSDB_CODE_PAR_INVALID_ENUM_OPTION TAOS_DEF_ERROR_CODE(0, 0x261B)
#define TSDB_CODE_PAR_INVALID_TTL_OPTION TAOS_DEF_ERROR_CODE(0, 0x261C)
#define TSDB_CODE_PAR_INVALID_KEEP_NUM TAOS_DEF_ERROR_CODE(0, 0x261D) #define TSDB_CODE_PAR_INVALID_KEEP_NUM TAOS_DEF_ERROR_CODE(0, 0x261D)
#define TSDB_CODE_PAR_INVALID_KEEP_ORDER TAOS_DEF_ERROR_CODE(0, 0x261E) #define TSDB_CODE_PAR_INVALID_KEEP_ORDER TAOS_DEF_ERROR_CODE(0, 0x261E)
#define TSDB_CODE_PAR_INVALID_KEEP_VALUE TAOS_DEF_ERROR_CODE(0, 0x261F) #define TSDB_CODE_PAR_INVALID_KEEP_VALUE TAOS_DEF_ERROR_CODE(0, 0x261F)
......
...@@ -349,8 +349,6 @@ typedef enum ELogicConditionType { ...@@ -349,8 +349,6 @@ typedef enum ELogicConditionType {
#define TSDB_MIN_FSYNC_PERIOD 0 #define TSDB_MIN_FSYNC_PERIOD 0
#define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond #define TSDB_MAX_FSYNC_PERIOD 180000 // millisecond
#define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second #define TSDB_DEFAULT_FSYNC_PERIOD 3000 // three second
#define TSDB_MIN_DB_TTL 1
#define TSDB_DEFAULT_DB_TTL 1
#define TSDB_MIN_WAL_LEVEL 1 #define TSDB_MIN_WAL_LEVEL 1
#define TSDB_MAX_WAL_LEVEL 2 #define TSDB_MAX_WAL_LEVEL 2
#define TSDB_DEFAULT_WAL_LEVEL 1 #define TSDB_DEFAULT_WAL_LEVEL 1
...@@ -378,13 +376,23 @@ typedef enum ELogicConditionType { ...@@ -378,13 +376,23 @@ typedef enum ELogicConditionType {
#define TSDB_DB_SINGLE_STABLE_ON 0 #define TSDB_DB_SINGLE_STABLE_ON 0
#define TSDB_DB_SINGLE_STABLE_OFF 1 #define TSDB_DB_SINGLE_STABLE_OFF 1
#define TSDB_DEFAULT_DB_SINGLE_STABLE 0 #define TSDB_DEFAULT_DB_SINGLE_STABLE 0
#define TSDB_MIN_BUFFER_PER_VNODE 3 // unit MB
#define TSDB_DEFAULT_BUFFER_PER_VNODE 96
#define TSDB_MIN_PAGES_PER_VNODE 64
#define TSDB_DEFAULT_PAGES_PER_VNODE 256
#define TSDB_MIN_PAGESIZE_PER_VNODE 1 // unit KB
#define TSDB_MAX_PAGESIZE_PER_VNODE 16384
#define TSDB_DEFAULT_PAGESIZE_PER_VNODE 4
#define TSDB_MIN_ROLLUP_FILE_FACTOR 0
#define TSDB_MAX_ROLLUP_FILE_FACTOR 1
#define TSDB_DEFAULT_ROLLUP_FILE_FACTOR 0.1
#define TSDB_MIN_ROLLUP_DELAY 1
#define TSDB_MAX_ROLLUP_DELAY 10
#define TSDB_DEFAULT_ROLLUP_DELAY 2
#define TSDB_MIN_TABLE_TTL 0
#define TSDB_DEFAULT_TABLE_TTL 0
#define TSDB_MIN_DB_FILE_FACTOR 0
#define TSDB_MAX_DB_FILE_FACTOR 1
#define TSDB_DEFAULT_DB_FILE_FACTOR 0.1
#define TSDB_MIN_DB_DELAY 1
#define TSDB_MAX_DB_DELAY 10
#define TSDB_DEFAULT_DB_DELAY 2
#define TSDB_MIN_EXPLAIN_RATIO 0 #define TSDB_MIN_EXPLAIN_RATIO 0
#define TSDB_MAX_EXPLAIN_RATIO 1 #define TSDB_MAX_EXPLAIN_RATIO 1
#define TSDB_DEFAULT_EXPLAIN_RATIO 0.001 #define TSDB_DEFAULT_EXPLAIN_RATIO 0.001
......
...@@ -268,8 +268,10 @@ static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) { ...@@ -268,8 +268,10 @@ static int32_t mndCheckDbName(const char *dbName, SUserObj *pUser) {
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1; if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1;
/*
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1; if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1;
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1; if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1;
*/
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1; if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1; if (pCfg->daysToKeep0 < TSDB_MIN_KEEP || pCfg->daysToKeep0 > TSDB_MAX_KEEP) return -1;
if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1; if (pCfg->daysToKeep1 < TSDB_MIN_KEEP || pCfg->daysToKeep1 > TSDB_MAX_KEEP) return -1;
...@@ -282,7 +284,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { ...@@ -282,7 +284,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if (pCfg->minRows > pCfg->maxRows) return -1; if (pCfg->minRows > pCfg->maxRows) return -1;
if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) return -1; if (pCfg->commitTime < TSDB_MIN_COMMIT_TIME || pCfg->commitTime > TSDB_MAX_COMMIT_TIME) return -1;
if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1; if (pCfg->fsyncPeriod < TSDB_MIN_FSYNC_PERIOD || pCfg->fsyncPeriod > TSDB_MAX_FSYNC_PERIOD) return -1;
if (pCfg->ttl < TSDB_MIN_DB_TTL) return -1; // if (pCfg->ttl < TSDB_MIN_TABLE_TTL) return -1;
if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1; if (pCfg->walLevel < TSDB_MIN_WAL_LEVEL || pCfg->walLevel > TSDB_MAX_WAL_LEVEL) return -1;
if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) return -1; if (pCfg->precision < TSDB_MIN_PRECISION && pCfg->precision > TSDB_MAX_PRECISION) return -1;
if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1; if (pCfg->compression < TSDB_MIN_COMP_LEVEL || pCfg->compression > TSDB_MAX_COMP_LEVEL) return -1;
...@@ -310,7 +312,7 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) { ...@@ -310,7 +312,7 @@ static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAXROWS_FBLOCK; if (pCfg->maxRows < 0) pCfg->maxRows = TSDB_DEFAULT_MAXROWS_FBLOCK;
if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME; if (pCfg->commitTime < 0) pCfg->commitTime = TSDB_DEFAULT_COMMIT_TIME;
if (pCfg->fsyncPeriod < 0) pCfg->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD; if (pCfg->fsyncPeriod < 0) pCfg->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
if (pCfg->ttl < 0) pCfg->ttl = TSDB_DEFAULT_DB_TTL; if (pCfg->ttl < 0) pCfg->ttl = TSDB_DEFAULT_TABLE_TTL;
if (pCfg->walLevel < 0) pCfg->walLevel = TSDB_DEFAULT_WAL_LEVEL; if (pCfg->walLevel < 0) pCfg->walLevel = TSDB_DEFAULT_WAL_LEVEL;
if (pCfg->precision < 0) pCfg->precision = TSDB_DEFAULT_PRECISION; if (pCfg->precision < 0) pCfg->precision = TSDB_DEFAULT_PRECISION;
if (pCfg->compression < 0) pCfg->compression = TSDB_DEFAULT_COMP_LEVEL; if (pCfg->compression < 0) pCfg->compression = TSDB_DEFAULT_COMP_LEVEL;
......
...@@ -389,21 +389,25 @@ void nodesDestroyNode(SNodeptr pNode) { ...@@ -389,21 +389,25 @@ void nodesDestroyNode(SNodeptr pNode) {
case QUERY_NODE_COLUMN_DEF: // no pointer field case QUERY_NODE_COLUMN_DEF: // no pointer field
case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field case QUERY_NODE_DOWNSTREAM_SOURCE: // no pointer field
break; break;
case QUERY_NODE_DATABASE_OPTIONS: case QUERY_NODE_DATABASE_OPTIONS: {
nodesDestroyList(((SDatabaseOptions*)pNode)->pRetentions); SDatabaseOptions* pOptions = (SDatabaseOptions*)pNode;
nodesDestroyNode(pOptions->pDaysPerFile);
nodesDestroyList(pOptions->pKeep);
nodesDestroyList(pOptions->pRetentions);
break; break;
}
case QUERY_NODE_TABLE_OPTIONS: { case QUERY_NODE_TABLE_OPTIONS: {
STableOptions* pStmt = (STableOptions*)pNode; STableOptions* pOptions = (STableOptions*)pNode;
nodesDestroyList(pStmt->pSma); nodesDestroyList(pOptions->pSma);
nodesDestroyList(pStmt->pFuncs); nodesDestroyList(pOptions->pRollupFuncs);
break; break;
} }
case QUERY_NODE_INDEX_OPTIONS: { case QUERY_NODE_INDEX_OPTIONS: {
SIndexOptions* pStmt = (SIndexOptions*)pNode; SIndexOptions* pOptions = (SIndexOptions*)pNode;
nodesDestroyList(pStmt->pFuncs); nodesDestroyList(pOptions->pFuncs);
nodesDestroyNode(pStmt->pInterval); nodesDestroyNode(pOptions->pInterval);
nodesDestroyNode(pStmt->pOffset); nodesDestroyNode(pOptions->pOffset);
nodesDestroyNode(pStmt->pSliding); nodesDestroyNode(pOptions->pSliding);
break; break;
} }
case QUERY_NODE_SET_OPERATOR: { case QUERY_NODE_SET_OPERATOR: {
......
...@@ -36,8 +36,7 @@ typedef struct SAstCreateContext { ...@@ -36,8 +36,7 @@ typedef struct SAstCreateContext {
} SAstCreateContext; } SAstCreateContext;
typedef enum EDatabaseOptionType { typedef enum EDatabaseOptionType {
DB_OPTION_BLOCKS = 1, DB_OPTION_BUFFER = 1,
DB_OPTION_CACHE,
DB_OPTION_CACHELAST, DB_OPTION_CACHELAST,
DB_OPTION_COMP, DB_OPTION_COMP,
DB_OPTION_DAYS, DB_OPTION_DAYS,
...@@ -45,30 +44,29 @@ typedef enum EDatabaseOptionType { ...@@ -45,30 +44,29 @@ typedef enum EDatabaseOptionType {
DB_OPTION_MAXROWS, DB_OPTION_MAXROWS,
DB_OPTION_MINROWS, DB_OPTION_MINROWS,
DB_OPTION_KEEP, DB_OPTION_KEEP,
DB_OPTION_PAGES,
DB_OPTION_PAGESIZE,
DB_OPTION_PRECISION, DB_OPTION_PRECISION,
DB_OPTION_QUORUM,
DB_OPTION_REPLICA, DB_OPTION_REPLICA,
DB_OPTION_TTL, DB_OPTION_STRICT,
DB_OPTION_WAL, DB_OPTION_WAL,
DB_OPTION_VGROUPS, DB_OPTION_VGROUPS,
DB_OPTION_SINGLE_STABLE, DB_OPTION_SINGLE_STABLE,
DB_OPTION_STREAM_MODE,
DB_OPTION_STRICT,
DB_OPTION_RETENTIONS DB_OPTION_RETENTIONS
} EDatabaseOptionType; } EDatabaseOptionType;
typedef enum ETableOptionType { typedef enum ETableOptionType {
TABLE_OPTION_KEEP = 1, TABLE_OPTION_COMMENT = 1,
TABLE_OPTION_TTL, TABLE_OPTION_DELAY,
TABLE_OPTION_COMMENT,
TABLE_OPTION_SMA,
TABLE_OPTION_FILE_FACTOR, TABLE_OPTION_FILE_FACTOR,
TABLE_OPTION_DELAY TABLE_OPTION_ROLLUP,
TABLE_OPTION_TTL,
TABLE_OPTION_SMA
} ETableOptionType; } ETableOptionType;
typedef struct SAlterOption { typedef struct SAlterOption {
int32_t type; int32_t type;
SValueNode* pVal; SToken val;
SNodeList* pList; SNodeList* pList;
} SAlterOption; } SAlterOption;
...@@ -121,25 +119,29 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit); ...@@ -121,25 +119,29 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight); SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
SNode* createDatabaseOptions(SAstCreateContext* pCxt); SDataType createDataType(uint8_t type);
SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt);
SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt);
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal);
SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption);
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions); SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions);
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName); SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName);
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions); SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions);
SNode* createTableOptions(SAstCreateContext* pCxt); SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption); SNode* createAlterTableOptions(SAstCreateContext* pCxt);
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal);
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment); SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment);
SDataType createDataType(uint8_t type);
SDataType createVarLenDataType(uint8_t type, const SToken* pLen);
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols, SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
SNodeList* pTags, SNode* pOptions); SNodeList* pTags, SNode* pOptions);
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
SNodeList* pSpecificTags, SNodeList* pValsOfTags); SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions);
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables); SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables); SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions); SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions);
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType,
const SToken* pColName, SDataType dataType); const SToken* pColName, SDataType dataType);
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName); SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, const SToken* pColName);
......
...@@ -137,43 +137,41 @@ not_exists_opt(A) ::= . ...@@ -137,43 +137,41 @@ not_exists_opt(A) ::= .
exists_opt(A) ::= IF EXISTS. { A = true; } exists_opt(A) ::= IF EXISTS. { A = true; }
exists_opt(A) ::= . { A = false; } exists_opt(A) ::= . { A = false; }
db_options(A) ::= . { A = createDatabaseOptions(pCxt); } db_options(A) ::= . { A = createDefaultDatabaseOptions(pCxt); }
db_options(A) ::= db_options(B) BLOCKS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) BUFFER NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_BUFFER, &C); }
db_options(A) ::= db_options(B) CACHE NK_INTEGER(C). { ((SDatabaseOptions*)B)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) CACHELAST NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_CACHELAST, &C); }
db_options(A) ::= db_options(B) CACHELAST NK_INTEGER(C). { ((SDatabaseOptions*)B)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) COMP NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMP, &C); }
db_options(A) ::= db_options(B) COMP NK_INTEGER(C). { ((SDatabaseOptions*)B)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DAYS, &C); }
db_options(A) ::= db_options(B) DAYS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) DAYS NK_VARIABLE(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DAYS, &C); }
db_options(A) ::= db_options(B) DAYS NK_VARIABLE(C). { ((SDatabaseOptions*)B)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &C); A = B; } db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_FSYNC, &C); }
db_options(A) ::= db_options(B) FSYNC NK_INTEGER(C). { ((SDatabaseOptions*)B)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MAXROWS, &C); }
db_options(A) ::= db_options(B) MAXROWS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_MINROWS, &C); }
db_options(A) ::= db_options(B) MINROWS NK_INTEGER(C). { ((SDatabaseOptions*)B)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) KEEP integer_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, C); }
db_options(A) ::= db_options(B) KEEP integer_list(C). { ((SDatabaseOptions*)B)->pKeep = C; A = B; } db_options(A) ::= db_options(B) KEEP variable_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP, C); }
db_options(A) ::= db_options(B) KEEP variable_list(C). { ((SDatabaseOptions*)B)->pKeep = C; A = B; } db_options(A) ::= db_options(B) PAGES NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PAGES, &C); }
db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { ((SDatabaseOptions*)B)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C); A = B; } db_options(A) ::= db_options(B) PAGESIZE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PAGESIZE, &C); }
db_options(A) ::= db_options(B) QUORUM NK_INTEGER(C). { ((SDatabaseOptions*)B)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) PRECISION NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_PRECISION, &C); }
db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { ((SDatabaseOptions*)B)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) REPLICA NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_REPLICA, &C); }
db_options(A) ::= db_options(B) TTL NK_INTEGER(C). { ((SDatabaseOptions*)B)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) STRICT NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_STRICT, &C); }
db_options(A) ::= db_options(B) WAL NK_INTEGER(C). { ((SDatabaseOptions*)B)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } 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). { ((SDatabaseOptions*)B)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } 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). { ((SDatabaseOptions*)B)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } 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). { ((SDatabaseOptions*)B)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } db_options(A) ::= db_options(B) RETENTIONS retention_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, C); }
db_options(A) ::= db_options(B) RETENTIONS retention_list(C). { ((SDatabaseOptions*)B)->pRetentions = C; A = B; }
db_options(A) ::= db_options(B) STRICT NK_INTEGER(C). { ((SDatabaseOptions*)B)->pStrict = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } alter_db_options(A) ::= alter_db_option(B). { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setAlterDatabaseOption(pCxt, B, &C); }
alter_db_options(A) ::= alter_db_option(B). { A = createDatabaseOptions(pCxt); A = setDatabaseAlterOption(pCxt, A, &B); }
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setDatabaseAlterOption(pCxt, B, &C); }
%type alter_db_option { SAlterOption } %type alter_db_option { SAlterOption }
%destructor alter_db_option { } %destructor alter_db_option { }
alter_db_option(A) ::= BLOCKS NK_INTEGER(B). { A.type = DB_OPTION_BLOCKS; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } alter_db_option(A) ::= BUFFER NK_INTEGER(B). { A.type = DB_OPTION_BUFFER; A.val = B; }
alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.val = B; }
alter_db_option(A) ::= FSYNC NK_INTEGER(B). { A.type = DB_OPTION_FSYNC; A.val = B; }
alter_db_option(A) ::= KEEP integer_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; } alter_db_option(A) ::= KEEP integer_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; }
alter_db_option(A) ::= KEEP variable_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; } alter_db_option(A) ::= KEEP variable_list(B). { A.type = DB_OPTION_KEEP; A.pList = B; }
alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } alter_db_option(A) ::= PAGES NK_INTEGER(B). { A.type = DB_OPTION_PAGES; A.val = B; }
alter_db_option(A) ::= QUORUM NK_INTEGER(B). { A.type = DB_OPTION_QUORUM; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.val = B; }
alter_db_option(A) ::= CACHELAST NK_INTEGER(B). { A.type = DB_OPTION_CACHELAST; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } alter_db_option(A) ::= STRICT NK_INTEGER(B). { A.type = DB_OPTION_STRICT; A.val = B; }
alter_db_option(A) ::= REPLICA NK_INTEGER(B). { A.type = DB_OPTION_REPLICA; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); } alter_db_option(A) ::= WAL NK_INTEGER(B). { A.type = DB_OPTION_WAL; A.val = B; }
alter_db_option(A) ::= STRICT NK_INTEGER(B). { A.type = DB_OPTION_STRICT; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); }
%type integer_list { SNodeList* } %type integer_list { SNodeList* }
%destructor integer_list { nodesDestroyList($$); } %destructor integer_list { nodesDestroyList($$); }
...@@ -204,7 +202,7 @@ cmd ::= DROP STABLE exists_opt(A) full_table_name(B). ...@@ -204,7 +202,7 @@ cmd ::= DROP STABLE exists_opt(A) full_table_name(B).
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; } cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
cmd ::= ALTER STABLE 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) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
alter_table_clause(A) ::= 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); } 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) DROP COLUMN column_name(C). { A = createAlterTableDropCol(pCxt, B, TSDB_ALTER_TABLE_DROP_COLUMN, &C); }
...@@ -229,7 +227,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C). ...@@ -229,7 +227,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C).
create_subtable_clause(A) ::= create_subtable_clause(A) ::=
not_exists_opt(B) full_table_name(C) USING full_table_name(D) not_exists_opt(B) full_table_name(C) USING full_table_name(D)
specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP. { A = createCreateSubTableClause(pCxt, B, C, D, E, F); } specific_tags_opt(E) TAGS NK_LP literal_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
%type multi_drop_clause { SNodeList* } %type multi_drop_clause { SNodeList* }
%destructor multi_drop_clause { nodesDestroyList($$); } %destructor multi_drop_clause { nodesDestroyList($$); }
...@@ -289,25 +287,21 @@ tags_def_opt(A) ::= tags_def(B). ...@@ -289,25 +287,21 @@ tags_def_opt(A) ::= tags_def(B).
%destructor tags_def { nodesDestroyList($$); } %destructor tags_def { nodesDestroyList($$); }
tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; } tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP. { A = B; }
table_options(A) ::= . { A = createTableOptions(pCxt); } table_options(A) ::= . { A = createDefaultTableOptions(pCxt); }
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { ((STableOptions*)B)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C); A = B; } 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 integer_list(C). { ((STableOptions*)B)->pKeep = C; A = B; } table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_DELAY, &C); }
table_options(A) ::= table_options(B) KEEP variable_list(C). { ((STableOptions*)B)->pKeep = C; A = B; } table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { A = setTableOption(pCxt, B, TABLE_OPTION_FILE_FACTOR, &C); }
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { ((STableOptions*)B)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; } table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { A = setTableOption(pCxt, B, TABLE_OPTION_ROLLUP, C); }
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { ((STableOptions*)B)->pSma = C; A = B; } table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { A = setTableOption(pCxt, B, TABLE_OPTION_TTL, &C); }
table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { ((STableOptions*)B)->pFuncs = C; A = B; } table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { A = setTableOption(pCxt, B, TABLE_OPTION_SMA, C); }
table_options(A) ::= table_options(B) FILE_FACTOR NK_FLOAT(C). { ((STableOptions*)B)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &C); A = B; }
table_options(A) ::= table_options(B) DELAY NK_INTEGER(C). { ((STableOptions*)B)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; }
alter_table_options(A) ::= alter_table_option(B). { A = createTableOptions(pCxt); A = setTableAlterOption(pCxt, A, &B); } alter_table_options(A) ::= alter_table_option(B). { A = createAlterTableOptions(pCxt); A = setTableOption(pCxt, A, B.type, &B.val); }
alter_table_options(A) ::= alter_table_options(B) alter_table_option(C). { A = setTableAlterOption(pCxt, B, &C); } 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 } %type alter_table_option { SAlterOption }
%destructor alter_table_option { } %destructor alter_table_option { }
alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.val = B; }
alter_table_option(A) ::= KEEP integer_list(B). { A.type = TABLE_OPTION_KEEP; A.pList = B; } alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.val = B; }
alter_table_option(A) ::= KEEP variable_list(B). { A.type = TABLE_OPTION_KEEP; A.pList = B; }
alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); }
%type col_name_list { SNodeList* } %type col_name_list { SNodeList* }
%destructor col_name_list { nodesDestroyList($$); } %destructor col_name_list { nodesDestroyList($$); }
......
...@@ -47,6 +47,12 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { ...@@ -47,6 +47,12 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
pCxt->placeholderNo = 1; pCxt->placeholderNo = 1;
} }
static void copyStringFormStringToken(SToken* pToken, char* pBuf, int32_t len) {
if (pToken->n > 2) {
strncpy(pBuf, pToken->z + 1, TMIN(pToken->n - 2, len - 1));
}
}
static void trimEscape(SToken* pName) { static void trimEscape(SToken* pName) {
// todo need to deal with `ioo``ii` -> ioo`ii // todo need to deal with `ioo``ii` -> ioo`ii
if (NULL != pName && pName->n > 1 && '`' == pName->z[0]) { if (NULL != pName && pName->n > 1 && '`' == pName->z[0]) {
...@@ -604,64 +610,113 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* ...@@ -604,64 +610,113 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
return (SNode*)setOp; return (SNode*)setOp;
} }
SNode* createDatabaseOptions(SAstCreateContext* pCxt) { SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS); SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS);
CHECK_OUT_OF_MEM(pOptions); CHECK_OUT_OF_MEM(pOptions);
pOptions->buffer = TSDB_DEFAULT_BUFFER_PER_VNODE;
pOptions->cachelast = TSDB_DEFAULT_CACHE_LAST_ROW;
pOptions->compressionLevel = TSDB_DEFAULT_COMP_LEVEL;
pOptions->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
pOptions->fsyncPeriod = TSDB_DEFAULT_FSYNC_PERIOD;
pOptions->maxRowsPerBlock = TSDB_DEFAULT_MAXROWS_FBLOCK;
pOptions->minRowsPerBlock = TSDB_DEFAULT_MINROWS_FBLOCK;
pOptions->keep[0] = TSDB_DEFAULT_KEEP;
pOptions->keep[1] = TSDB_DEFAULT_KEEP;
pOptions->keep[2] = TSDB_DEFAULT_KEEP;
pOptions->pages = TSDB_DEFAULT_PAGES_PER_VNODE;
pOptions->pagesize = TSDB_DEFAULT_PAGESIZE_PER_VNODE;
pOptions->precision = TSDB_DEFAULT_PRECISION;
pOptions->replica = TSDB_DEFAULT_DB_REPLICA;
pOptions->strict = TSDB_DEFAULT_DB_STRICT;
pOptions->walLevel = TSDB_DEFAULT_WAL_LEVEL;
pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE;
return (SNode*)pOptions; return (SNode*)pOptions;
} }
SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) {
switch (pAlterOption->type) { SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS);
case DB_OPTION_BLOCKS: CHECK_OUT_OF_MEM(pOptions);
((SDatabaseOptions*)pOptions)->pNumOfBlocks = pAlterOption->pVal; pOptions->buffer = -1;
break; pOptions->cachelast = -1;
case DB_OPTION_CACHE: pOptions->compressionLevel = -1;
((SDatabaseOptions*)pOptions)->pCacheBlockSize = pAlterOption->pVal; pOptions->daysPerFile = -1;
pOptions->fsyncPeriod = -1;
pOptions->maxRowsPerBlock = -1;
pOptions->minRowsPerBlock = -1;
pOptions->keep[0] = -1;
pOptions->keep[1] = -1;
pOptions->keep[2] = -1;
pOptions->pages = -1;
pOptions->pagesize = -1;
pOptions->precision = -1;
pOptions->replica = -1;
pOptions->strict = -1;
pOptions->walLevel = -1;
pOptions->numOfVgroups = -1;
pOptions->singleStable = -1;
return (SNode*)pOptions;
}
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal) {
switch (type) {
case DB_OPTION_BUFFER:
((SDatabaseOptions*)pOptions)->buffer = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_CACHELAST: case DB_OPTION_CACHELAST:
((SDatabaseOptions*)pOptions)->pCachelast = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->cachelast = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_COMP: case DB_OPTION_COMP:
((SDatabaseOptions*)pOptions)->pCompressionLevel = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->compressionLevel = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_DAYS: case DB_OPTION_DAYS: {
((SDatabaseOptions*)pOptions)->pDaysPerFile = pAlterOption->pVal; SToken* pToken = pVal;
if (TK_NK_INTEGER == pToken->type) {
((SDatabaseOptions*)pOptions)->daysPerFile = strtol(pToken->z, NULL, 10);
} else {
((SDatabaseOptions*)pOptions)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, pToken);
}
break; break;
}
case DB_OPTION_FSYNC: case DB_OPTION_FSYNC:
((SDatabaseOptions*)pOptions)->pFsyncPeriod = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->fsyncPeriod = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_MAXROWS: case DB_OPTION_MAXROWS:
((SDatabaseOptions*)pOptions)->pMaxRowsPerBlock = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->maxRowsPerBlock = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_MINROWS: case DB_OPTION_MINROWS:
((SDatabaseOptions*)pOptions)->pMinRowsPerBlock = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->minRowsPerBlock = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_KEEP: case DB_OPTION_KEEP:
((SDatabaseOptions*)pOptions)->pKeep = pAlterOption->pList; ((SDatabaseOptions*)pOptions)->pKeep = pVal;
break;
case DB_OPTION_PAGES:
((SDatabaseOptions*)pOptions)->pages = strtol(((SToken*)pVal)->z, NULL, 10);
break;
case DB_OPTION_PAGESIZE:
((SDatabaseOptions*)pOptions)->pagesize = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_PRECISION: case DB_OPTION_PRECISION:
((SDatabaseOptions*)pOptions)->pPrecision = pAlterOption->pVal; copyStringFormStringToken((SToken*)pVal, ((SDatabaseOptions*)pOptions)->precisionStr,
sizeof(((SDatabaseOptions*)pOptions)->precisionStr));
break; break;
case DB_OPTION_REPLICA: case DB_OPTION_REPLICA:
((SDatabaseOptions*)pOptions)->pReplica = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->replica = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_TTL: case DB_OPTION_STRICT:
((SDatabaseOptions*)pOptions)->pTtl = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->strict = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_WAL: case DB_OPTION_WAL:
((SDatabaseOptions*)pOptions)->pWalLevel = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->walLevel = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_VGROUPS: case DB_OPTION_VGROUPS:
((SDatabaseOptions*)pOptions)->pNumOfVgroups = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->numOfVgroups = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case DB_OPTION_SINGLE_STABLE: case DB_OPTION_SINGLE_STABLE:
((SDatabaseOptions*)pOptions)->pSingleStable = pAlterOption->pVal; ((SDatabaseOptions*)pOptions)->singleStable = strtol(((SToken*)pVal)->z, NULL, 10);
break;
case DB_OPTION_STREAM_MODE:
((SDatabaseOptions*)pOptions)->pStreamMode = pAlterOption->pVal;
break; break;
case DB_OPTION_RETENTIONS: case DB_OPTION_RETENTIONS:
((SDatabaseOptions*)pOptions)->pRetentions = pAlterOption->pList; ((SDatabaseOptions*)pOptions)->pRetentions = pVal;
break; break;
default: default:
break; break;
...@@ -669,6 +724,17 @@ SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOp ...@@ -669,6 +724,17 @@ SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOp
return pOptions; return pOptions;
} }
SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) {
switch (pAlterOption->type) {
case DB_OPTION_KEEP:
case DB_OPTION_RETENTIONS:
return setDatabaseOption(pCxt, pOptions, pAlterOption->type, pAlterOption->pList);
default:
break;
}
return setDatabaseOption(pCxt, pOptions, pAlterOption->type, &pAlterOption->val);
}
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) { SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) {
if (!checkDbName(pCxt, pDbName, false)) { if (!checkDbName(pCxt, pDbName, false)) {
return NULL; return NULL;
...@@ -703,31 +769,44 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* ...@@ -703,31 +769,44 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode*
return (SNode*)pStmt; return (SNode*)pStmt;
} }
SNode* createTableOptions(SAstCreateContext* pCxt) { SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS); STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
CHECK_OUT_OF_MEM(pOptions); CHECK_OUT_OF_MEM(pOptions);
pOptions->delay = TSDB_DEFAULT_ROLLUP_DELAY;
pOptions->filesFactor = TSDB_DEFAULT_ROLLUP_FILE_FACTOR;
pOptions->ttl = TSDB_DEFAULT_TABLE_TTL;
return (SNode*)pOptions; return (SNode*)pOptions;
} }
SNode* setTableAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) { SNode* createAlterTableOptions(SAstCreateContext* pCxt) {
switch (pAlterOption->type) { STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
case TABLE_OPTION_KEEP: CHECK_OUT_OF_MEM(pOptions);
((STableOptions*)pOptions)->pKeep = pAlterOption->pList; pOptions->delay = -1;
break; pOptions->filesFactor = -1;
case TABLE_OPTION_TTL: pOptions->ttl = -1;
((STableOptions*)pOptions)->pTtl = pAlterOption->pVal; return (SNode*)pOptions;
break; }
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal) {
switch (type) {
case TABLE_OPTION_COMMENT: case TABLE_OPTION_COMMENT:
((STableOptions*)pOptions)->pComments = pAlterOption->pVal; copyStringFormStringToken((SToken*)pVal, ((STableOptions*)pOptions)->comment,
sizeof(((STableOptions*)pOptions)->comment));
break; break;
case TABLE_OPTION_SMA: case TABLE_OPTION_DELAY:
((STableOptions*)pOptions)->pSma = pAlterOption->pList; ((STableOptions*)pOptions)->delay = strtol(((SToken*)pVal)->z, NULL, 10);
break; break;
case TABLE_OPTION_FILE_FACTOR: case TABLE_OPTION_FILE_FACTOR:
((STableOptions*)pOptions)->pFilesFactor = pAlterOption->pVal; ((STableOptions*)pOptions)->filesFactor = strtod(((SToken*)pVal)->z, NULL);
break; break;
case TABLE_OPTION_DELAY: case TABLE_OPTION_ROLLUP:
((STableOptions*)pOptions)->pDelay = pAlterOption->pVal; ((STableOptions*)pOptions)->pRollupFuncs = pVal;
break;
case TABLE_OPTION_TTL:
((STableOptions*)pOptions)->ttl = strtol(((SToken*)pVal)->z, NULL, 10);
break;
case TABLE_OPTION_SMA:
((STableOptions*)pOptions)->pSma = pVal;
break; break;
default: default:
break; break;
...@@ -778,7 +857,7 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* ...@@ -778,7 +857,7 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode*
} }
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable, SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
SNodeList* pSpecificTags, SNodeList* pValsOfTags) { SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions) {
if (NULL == pRealTable) { if (NULL == pRealTable) {
return NULL; return NULL;
} }
...@@ -833,7 +912,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S ...@@ -833,7 +912,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S
return (SNode*)pStmt; return (SNode*)pStmt;
} }
SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) { SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) {
if (NULL == pRealTable) { if (NULL == pRealTable) {
return NULL; return NULL;
} }
......
...@@ -43,7 +43,7 @@ static SKeyword keywordTable[] = { ...@@ -43,7 +43,7 @@ static SKeyword keywordTable[] = {
{"BETWEEN", TK_BETWEEN}, {"BETWEEN", TK_BETWEEN},
{"BINARY", TK_BINARY}, {"BINARY", TK_BINARY},
{"BIGINT", TK_BIGINT}, {"BIGINT", TK_BIGINT},
{"BLOCKS", TK_BLOCKS}, // {"BLOCKS", TK_BLOCKS},
{"BNODE", TK_BNODE}, {"BNODE", TK_BNODE},
{"BNODES", TK_BNODES}, {"BNODES", TK_BNODES},
{"BOOL", TK_BOOL}, {"BOOL", TK_BOOL},
...@@ -142,7 +142,7 @@ static SKeyword keywordTable[] = { ...@@ -142,7 +142,7 @@ static SKeyword keywordTable[] = {
{"QTIME", TK_QTIME}, {"QTIME", TK_QTIME},
{"QUERIES", TK_QUERIES}, {"QUERIES", TK_QUERIES},
{"QUERY", TK_QUERY}, {"QUERY", TK_QUERY},
{"QUORUM", TK_QUORUM}, // {"QUORUM", TK_QUORUM},
{"RATIO", TK_RATIO}, {"RATIO", TK_RATIO},
{"REPLICA", TK_REPLICA}, {"REPLICA", TK_REPLICA},
{"RESET", TK_RESET}, {"RESET", TK_RESET},
...@@ -169,7 +169,7 @@ static SKeyword keywordTable[] = { ...@@ -169,7 +169,7 @@ static SKeyword keywordTable[] = {
{"STORAGE", TK_STORAGE}, {"STORAGE", TK_STORAGE},
{"STREAM", TK_STREAM}, {"STREAM", TK_STREAM},
{"STREAMS", TK_STREAMS}, {"STREAMS", TK_STREAMS},
{"STREAM_MODE", TK_STREAM_MODE}, // {"STREAM_MODE", TK_STREAM_MODE},
{"STRICT", TK_STRICT}, {"STRICT", TK_STRICT},
{"SYNCDB", TK_SYNCDB}, {"SYNCDB", TK_SYNCDB},
{"TABLE", TK_TABLE}, {"TABLE", TK_TABLE},
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
#include "tglobal.h" #include "tglobal.h"
#include "ttime.h" #include "ttime.h"
#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : getBigintFromValueNode((SValueNode*)(pVal))) #define generateDealNodeErrMsg(pCxt, code, ...) \
(pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__) ? DEAL_RES_ERROR : DEAL_RES_ERROR)
typedef struct STranslateContext { typedef struct STranslateContext {
SParseContext* pParseCxt; SParseContext* pParseCxt;
...@@ -50,15 +51,6 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B ...@@ -50,15 +51,6 @@ static bool afterGroupBy(ESqlClause clause) { return clause > SQL_CLAUSE_GROUP_B
static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; } static bool beforeHaving(ESqlClause clause) { return clause < SQL_CLAUSE_HAVING; }
enum EDealRes generateDealNodeErrMsg(STranslateContext* pCxt, int32_t code, ...) {
va_list ap;
va_start(ap, code);
generateSyntaxErrMsg(&pCxt->msgBuf, code, ap);
va_end(ap);
pCxt->errCode = code;
return DEAL_RES_ERROR;
}
static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { static int32_t addNamespace(STranslateContext* pCxt, void* pTable) {
size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel); size_t currTotalLevel = taosArrayGetSize(pCxt->pNsLevel);
if (currTotalLevel > pCxt->currLevel) { if (currTotalLevel > pCxt->currLevel) {
...@@ -1546,157 +1538,120 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS ...@@ -1546,157 +1538,120 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
SName name = {0}; SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
tNameGetFullDbName(&name, pReq->db); tNameGetFullDbName(&name, pReq->db);
pReq->numOfVgroups = GET_OPTION_VAL(pStmt->pOptions->pNumOfVgroups, TSDB_DEFAULT_VN_PER_DB); pReq->numOfVgroups = pStmt->pOptions->numOfVgroups;
pReq->cacheBlockSize = GET_OPTION_VAL(pStmt->pOptions->pCacheBlockSize, TSDB_DEFAULT_CACHE_BLOCK_SIZE); pReq->daysPerFile = pStmt->pOptions->daysPerFile;
pReq->totalBlocks = GET_OPTION_VAL(pStmt->pOptions->pNumOfBlocks, TSDB_DEFAULT_TOTAL_BLOCKS); pReq->daysToKeep0 = pStmt->pOptions->keep[0];
pReq->daysPerFile = GET_OPTION_VAL(pStmt->pOptions->pDaysPerFile, TSDB_DEFAULT_DAYS_PER_FILE); pReq->daysToKeep1 = pStmt->pOptions->keep[1];
pReq->daysToKeep0 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 0), TSDB_DEFAULT_KEEP); pReq->daysToKeep2 = pStmt->pOptions->keep[2];
pReq->daysToKeep1 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 1), TSDB_DEFAULT_KEEP); pReq->minRows = pStmt->pOptions->minRowsPerBlock;
pReq->daysToKeep2 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 2), TSDB_DEFAULT_KEEP); pReq->maxRows = pStmt->pOptions->maxRowsPerBlock;
pReq->minRows = GET_OPTION_VAL(pStmt->pOptions->pMinRowsPerBlock, TSDB_DEFAULT_MINROWS_FBLOCK);
pReq->maxRows = GET_OPTION_VAL(pStmt->pOptions->pMaxRowsPerBlock, TSDB_DEFAULT_MAXROWS_FBLOCK);
pReq->commitTime = -1; pReq->commitTime = -1;
pReq->fsyncPeriod = GET_OPTION_VAL(pStmt->pOptions->pFsyncPeriod, TSDB_DEFAULT_FSYNC_PERIOD); pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod;
pReq->walLevel = GET_OPTION_VAL(pStmt->pOptions->pWalLevel, TSDB_DEFAULT_WAL_LEVEL); pReq->walLevel = pStmt->pOptions->walLevel;
pReq->precision = GET_OPTION_VAL(pStmt->pOptions->pPrecision, TSDB_TIME_PRECISION_MILLI); pReq->precision = pStmt->pOptions->precision;
pReq->compression = GET_OPTION_VAL(pStmt->pOptions->pCompressionLevel, TSDB_DEFAULT_COMP_LEVEL); pReq->compression = pStmt->pOptions->compressionLevel;
pReq->replications = GET_OPTION_VAL(pStmt->pOptions->pReplica, TSDB_DEFAULT_DB_REPLICA); pReq->replications = pStmt->pOptions->replica;
pReq->update = -1; pReq->update = -1;
pReq->cacheLastRow = GET_OPTION_VAL(pStmt->pOptions->pCachelast, TSDB_DEFAULT_CACHE_LAST_ROW); pReq->cacheLastRow = pStmt->pOptions->cachelast;
pReq->ignoreExist = pStmt->ignoreExists; pReq->ignoreExist = pStmt->ignoreExists;
pReq->streamMode = GET_OPTION_VAL(pStmt->pOptions->pStreamMode, TSDB_DEFAULT_DB_STREAM_MODE); pReq->singleSTable = pStmt->pOptions->singleStable;
pReq->ttl = GET_OPTION_VAL(pStmt->pOptions->pTtl, TSDB_DEFAULT_DB_TTL); pReq->strict = pStmt->pOptions->strict;
pReq->singleSTable = GET_OPTION_VAL(pStmt->pOptions->pSingleStable, TSDB_DEFAULT_DB_SINGLE_STABLE); // pStmt->pOptions->buffer;
pReq->strict = GET_OPTION_VAL(pStmt->pOptions->pStrict, TSDB_DEFAULT_DB_STRICT); // pStmt->pOptions->pages;
// pStmt->pOptions->pagesize;
return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq); return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq);
} }
static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, SValueNode* pVal, int32_t minVal, static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t minVal,
int32_t maxVal) { int32_t maxVal) {
if (NULL != pVal) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode;
}
if (pVal->isDuration &&
(TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit && TIME_UNIT_DAY != pVal->unit)) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_OPTION_UNIT, pName, pVal->unit);
}
int64_t val = getBigintFromValueNode(pVal);
if (val < minVal || val > maxVal) { if (val < minVal || val > maxVal) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal);
} }
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void convertValueFromStrToInt(SValueNode* pVal, int64_t val) { static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
taosMemoryFreeClear(pVal->datum.p); if (NULL != pOptions->pDaysPerFile) {
pVal->datum.i = val; if (DEAL_RES_ERROR == translateValue(pCxt, pOptions->pDaysPerFile)) {
pVal->node.resType.type = TSDB_DATA_TYPE_BIGINT;
pVal->node.resType.bytes = tDataTypes[pVal->node.resType.type].bytes;
}
static int32_t checkDbPrecisionOption(STranslateContext* pCxt, SValueNode* pVal) {
if (NULL != pVal) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode; return pCxt->errCode;
} }
char* pRrecision = varDataVal(pVal->datum.p); if (TIME_UNIT_MINUTE != pOptions->pDaysPerFile->unit && TIME_UNIT_HOUR != pOptions->pDaysPerFile->unit &&
if (0 == strcmp(pRrecision, TSDB_TIME_PRECISION_MILLI_STR)) { TIME_UNIT_DAY != pOptions->pDaysPerFile->unit) {
convertValueFromStrToInt(pVal, TSDB_TIME_PRECISION_MILLI); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_OPTION_UNIT, "daysPerFile",
} else if (0 == strcmp(pRrecision, TSDB_TIME_PRECISION_MICRO_STR)) { pOptions->pDaysPerFile->unit);
convertValueFromStrToInt(pVal, TSDB_TIME_PRECISION_MICRO);
} else if (0 == strcmp(pRrecision, TSDB_TIME_PRECISION_NANO_STR)) {
convertValueFromStrToInt(pVal, TSDB_TIME_PRECISION_NANO);
} else {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STR_OPTION, "precision", pVal->datum.p);
} }
pOptions->daysPerFile = getBigintFromValueNode(pOptions->pDaysPerFile);
} }
return TSDB_CODE_SUCCESS; return checkRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
} }
static int32_t checkDbEnumOption(STranslateContext* pCxt, const char* pName, SValueNode* pVal, int32_t v1, int32_t v2) { static int32_t checkDbKeepOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
if (NULL != pVal) { if (NULL == pOptions->pKeep) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode;
}
int64_t val = pVal->datum.i;
if (val != v1 && val != v2) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENUM_OPTION, pName, val, v1, v2);
}
}
return TSDB_CODE_SUCCESS;
}
static int32_t checkTtlOption(STranslateContext* pCxt, SValueNode* pVal) {
if (NULL != pVal) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode;
}
int64_t val = pVal->datum.i;
if (val < TSDB_MIN_DB_TTL) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TTL_OPTION, val, TSDB_MIN_DB_TTL);
}
}
return TSDB_CODE_SUCCESS;
}
static int32_t checkKeepOption(STranslateContext* pCxt, SNodeList* pKeep) {
if (NULL == pKeep) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t numOfKeep = LIST_LENGTH(pKeep); int32_t numOfKeep = LIST_LENGTH(pOptions->pKeep);
if (numOfKeep > 3 || numOfKeep < 1) { if (numOfKeep > 3 || numOfKeep < 1) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_NUM); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_NUM);
} }
SNode* pNode = NULL; SNode* pNode = NULL;
FOREACH(pNode, pKeep) { FOREACH(pNode, pOptions->pKeep) {
if (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pNode)) { SValueNode* pVal = (SValueNode*)pNode;
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode; return pCxt->errCode;
} }
if (pVal->isDuration && TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit &&
TIME_UNIT_DAY != pVal->unit) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pVal->unit);
} }
if (1 == numOfKeep) {
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pKeep, nodesCloneNode(nodesListGetNode(pKeep, 0)))) {
return TSDB_CODE_OUT_OF_MEMORY;
} }
++numOfKeep;
} pOptions->keep[0] = getBigintFromValueNode((SValueNode*)nodesListGetNode(pOptions->pKeep, 0));
if (2 == numOfKeep) {
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pKeep, nodesCloneNode(nodesListGetNode(pKeep, 1)))) { if (numOfKeep < 2) {
return TSDB_CODE_OUT_OF_MEMORY; pOptions->keep[1] = pOptions->keep[0];
} else {
pOptions->keep[1] = getBigintFromValueNode((SValueNode*)nodesListGetNode(pOptions->pKeep, 1));
} }
if (numOfKeep < 3) {
pOptions->keep[2] = pOptions->keep[1];
} else {
pOptions->keep[2] = getBigintFromValueNode((SValueNode*)nodesListGetNode(pOptions->pKeep, 2));
} }
SValueNode* pKeep0 = (SValueNode*)nodesListGetNode(pKeep, 0); if (pOptions->keep[0] < TSDB_MIN_KEEP || pOptions->keep[1] < TSDB_MIN_KEEP || pOptions->keep[2] < TSDB_MIN_KEEP ||
SValueNode* pKeep1 = (SValueNode*)nodesListGetNode(pKeep, 1); pOptions->keep[0] > TSDB_MAX_KEEP || pOptions->keep[1] > TSDB_MAX_KEEP || pOptions->keep[2] > TSDB_MAX_KEEP) {
SValueNode* pKeep2 = (SValueNode*)nodesListGetNode(pKeep, 2); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_VALUE, pOptions->keep[0], pOptions->keep[1],
if ((pKeep0->isDuration && pOptions->keep[2], TSDB_MIN_KEEP, TSDB_MAX_KEEP);
(TIME_UNIT_MINUTE != pKeep0->unit && TIME_UNIT_HOUR != pKeep0->unit && TIME_UNIT_DAY != pKeep0->unit)) ||
(pKeep1->isDuration &&
(TIME_UNIT_MINUTE != pKeep1->unit && TIME_UNIT_HOUR != pKeep1->unit && TIME_UNIT_DAY != pKeep1->unit)) ||
(pKeep2->isDuration &&
(TIME_UNIT_MINUTE != pKeep2->unit && TIME_UNIT_HOUR != pKeep2->unit && TIME_UNIT_DAY != pKeep2->unit))) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pKeep0->unit, pKeep1->unit,
pKeep2->unit);
} }
int32_t daysToKeep0 = getBigintFromValueNode(pKeep0); if (!((pOptions->keep[0] <= pOptions->keep[1]) && (pOptions->keep[1] <= pOptions->keep[2]))) {
int32_t daysToKeep1 = getBigintFromValueNode(pKeep1); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_ORDER);
int32_t daysToKeep2 = getBigintFromValueNode(pKeep2);
if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP ||
daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_VALUE, daysToKeep0, daysToKeep1, daysToKeep2,
TSDB_MIN_KEEP, TSDB_MAX_KEEP);
} }
if (!((daysToKeep0 <= daysToKeep1) && (daysToKeep1 <= daysToKeep2))) { return TSDB_CODE_SUCCESS;
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_KEEP_ORDER); }
static int32_t checkDbPrecisionOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
if ('\0' != pOptions->precisionStr[0]) {
if (0 == strcmp(pOptions->precisionStr, TSDB_TIME_PRECISION_MILLI_STR)) {
pOptions->precision = TSDB_TIME_PRECISION_MILLI;
} else if (0 == strcmp(pOptions->precisionStr, TSDB_TIME_PRECISION_MICRO_STR)) {
pOptions->precision = TSDB_TIME_PRECISION_MICRO;
} else if (0 == strcmp(pOptions->precisionStr, TSDB_TIME_PRECISION_NANO_STR)) {
pOptions->precision = TSDB_TIME_PRECISION_NANO;
} else {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STR_OPTION, "precision", pOptions->precisionStr);
}
} }
return TSDB_CODE_SUCCESS;
}
static int32_t checkDbEnumOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t v1, int32_t v2) {
if (val != v1 && val != v2) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENUM_OPTION, pName, val, v1, v2);
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -1724,11 +1679,8 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete ...@@ -1724,11 +1679,8 @@ static int32_t checkDbRetentionsOption(STranslateContext* pCxt, SNodeList* pRete
static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions, static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions,
bool alter) { bool alter) {
if (NULL == pOptions->pDaysPerFile && NULL == pOptions->pKeep) { int32_t daysPerFile = pOptions->daysPerFile;
return TSDB_CODE_SUCCESS; int32_t daysToKeep0 = pOptions->keep[0];
}
int64_t daysPerFile = GET_OPTION_VAL(pOptions->pDaysPerFile, alter ? -1 : TSDB_DEFAULT_DAYS_PER_FILE);
int64_t daysToKeep0 = GET_OPTION_VAL(nodesListGetNode(pOptions->pKeep, 0), alter ? -1 : TSDB_DEFAULT_KEEP);
if (alter && (-1 == daysPerFile || -1 == daysToKeep0)) { if (alter && (-1 == daysPerFile || -1 == daysToKeep0)) {
SDbCfgInfo dbCfg; SDbCfgInfo dbCfg;
int32_t code = getDBCfg(pCxt, pDbName, &dbCfg); int32_t code = getDBCfg(pCxt, pDbName, &dbCfg);
...@@ -1746,65 +1698,59 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa ...@@ -1746,65 +1698,59 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa
static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions, static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions,
bool alter) { bool alter) {
int32_t code = int32_t code = checkRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, INT32_MAX);
checkRangeOption(pCxt, "totalBlocks", pOptions->pNumOfBlocks, TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "cacheBlockSize", pOptions->pCacheBlockSize, TSDB_MIN_CACHE_BLOCK_SIZE, code = checkRangeOption(pCxt, "cacheLast", pOptions->cachelast, TSDB_MIN_DB_CACHE_LAST_ROW,
TSDB_MAX_CACHE_BLOCK_SIZE);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "cacheLast", pOptions->pCachelast, TSDB_MIN_DB_CACHE_LAST_ROW,
TSDB_MAX_DB_CACHE_LAST_ROW); TSDB_MAX_DB_CACHE_LAST_ROW);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "compression", pOptions->pCompressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); code = checkRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = code = checkDbDaysOption(pCxt, pOptions);
checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->pFsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "maxRowsPerBlock", pOptions->pMaxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK, code = checkRangeOption(pCxt, "maxRowsPerBlock", pOptions->maxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK,
TSDB_MAX_MAXROWS_FBLOCK); TSDB_MAX_MAXROWS_FBLOCK);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "minRowsPerBlock", pOptions->pMinRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK, code = checkRangeOption(pCxt, "minRowsPerBlock", pOptions->minRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK,
TSDB_MAX_MINROWS_FBLOCK); TSDB_MAX_MINROWS_FBLOCK);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkKeepOption(pCxt, pOptions->pKeep); code = checkDbKeepOption(pCxt, pOptions);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkDbPrecisionOption(pCxt, pOptions->pPrecision); code = checkRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, INT32_MAX);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "replications", pOptions->pReplica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA); code = checkRangeOption(pCxt, "pagesize", pOptions->pagesize, TSDB_MIN_PAGESIZE_PER_VNODE,
TSDB_MAX_PAGESIZE_PER_VNODE);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkTtlOption(pCxt, pOptions->pTtl); code = checkDbPrecisionOption(pCxt, pOptions);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "walLevel", pOptions->pWalLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL); code = checkDbEnumOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "vgroups", pOptions->pNumOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); code = checkDbEnumOption(pCxt, "strict", pOptions->strict, TSDB_DB_STRICT_OFF, TSDB_DB_STRICT_ON);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "singleStable", pOptions->pSingleStable, TSDB_DB_SINGLE_STABLE_ON, code = checkDbEnumOption(pCxt, "walLevel", pOptions->walLevel, TSDB_MIN_WAL_LEVEL, TSDB_MAX_WAL_LEVEL);
TSDB_DB_SINGLE_STABLE_OFF);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = code = checkRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB);
checkDbEnumOption(pCxt, "streamMode", pOptions->pStreamMode, TSDB_DB_STREAM_MODE_OFF, TSDB_DB_STREAM_MODE_ON);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkDbRetentionsOption(pCxt, pOptions->pRetentions); code = checkDbEnumOption(pCxt, "singleStable", pOptions->singleStable, TSDB_DB_SINGLE_STABLE_ON,
TSDB_DB_SINGLE_STABLE_OFF);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkDbEnumOption(pCxt, "strict", pOptions->pStrict, TSDB_DB_STRICT_OFF, TSDB_DB_STRICT_ON); code = checkDbRetentionsOption(pCxt, pOptions->pRetentions);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkOptionsDependency(pCxt, pDbName, pOptions, alter); code = checkOptionsDependency(pCxt, pDbName, pOptions, alter);
...@@ -1864,15 +1810,16 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt, ...@@ -1864,15 +1810,16 @@ static void buildAlterDbReq(STranslateContext* pCxt, SAlterDatabaseStmt* pStmt,
SName name = {0}; SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
tNameGetFullDbName(&name, pReq->db); tNameGetFullDbName(&name, pReq->db);
pReq->totalBlocks = GET_OPTION_VAL(pStmt->pOptions->pNumOfBlocks, -1); // pStmt->pOptions->buffer
pReq->daysToKeep0 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 0), -1); pReq->cacheLastRow = pStmt->pOptions->cachelast;
pReq->daysToKeep1 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 1), -1); pReq->fsyncPeriod = pStmt->pOptions->fsyncPeriod;
pReq->daysToKeep2 = GET_OPTION_VAL(nodesListGetNode(pStmt->pOptions->pKeep, 2), -1); pReq->daysToKeep0 = pStmt->pOptions->keep[0];
pReq->fsyncPeriod = GET_OPTION_VAL(pStmt->pOptions->pFsyncPeriod, -1); pReq->daysToKeep1 = pStmt->pOptions->keep[1];
pReq->walLevel = GET_OPTION_VAL(pStmt->pOptions->pWalLevel, -1); pReq->daysToKeep2 = pStmt->pOptions->keep[2];
pReq->strict = GET_OPTION_VAL(pStmt->pOptions->pQuorum, -1); // pStmt->pOptions->pages
pReq->cacheLastRow = GET_OPTION_VAL(pStmt->pOptions->pCachelast, -1); pReq->replications = pStmt->pOptions->replica;
pReq->replications = GET_OPTION_VAL(pStmt->pOptions->pReplica, -1); pReq->strict = pStmt->pOptions->strict;
pReq->walLevel = pStmt->pOptions->walLevel;
return; return;
} }
...@@ -1923,27 +1870,10 @@ static SColumnDefNode* findColDef(SNodeList* pCols, const SColumnNode* pCol) { ...@@ -1923,27 +1870,10 @@ static SColumnDefNode* findColDef(SNodeList* pCols, const SColumnNode* pCol) {
return NULL; return NULL;
} }
static int32_t checkTableCommentOption(STranslateContext* pCxt, SValueNode* pVal) { static int32_t checTableFactorOption(STranslateContext* pCxt, float val) {
if (NULL != pVal) { if (val < TSDB_MIN_ROLLUP_FILE_FACTOR || val > TSDB_MAX_ROLLUP_FILE_FACTOR) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_F_RANGE_OPTION, "file_factor", val,
return pCxt->errCode; TSDB_MIN_ROLLUP_FILE_FACTOR, TSDB_MAX_ROLLUP_FILE_FACTOR);
}
if (pVal->node.resType.bytes >= TSDB_STB_COMMENT_LEN) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COMMENT_OPTION, TSDB_STB_COMMENT_LEN - 1);
}
}
return TSDB_CODE_SUCCESS;
}
static int32_t checTableFactorOption(STranslateContext* pCxt, SValueNode* pVal) {
if (NULL != pVal) {
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
return pCxt->errCode;
}
if (pVal->datum.d < TSDB_MIN_DB_FILE_FACTOR || pVal->datum.d > TSDB_MAX_DB_FILE_FACTOR) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_F_RANGE_OPTION, "file_factor", pVal->datum.d,
TSDB_MIN_DB_FILE_FACTOR, TSDB_MAX_DB_FILE_FACTOR);
}
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -1988,24 +1918,18 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs ...@@ -1988,24 +1918,18 @@ static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs
} }
static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) { static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt) {
int32_t code = checkKeepOption(pCxt, pStmt->pOptions->pKeep); int32_t code = checkRangeOption(pCxt, "delay", pStmt->pOptions->delay, TSDB_MIN_ROLLUP_DELAY, TSDB_MAX_ROLLUP_DELAY);
if (TSDB_CODE_SUCCESS == code) {
code = checkTtlOption(pCxt, pStmt->pOptions->pTtl);
}
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkTableCommentOption(pCxt, pStmt->pOptions->pComments); code = checTableFactorOption(pCxt, pStmt->pOptions->filesFactor);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkTableSmaOption(pCxt, pStmt); code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs);
}
if (TSDB_CODE_SUCCESS == code) {
code = checkTableRollupOption(pCxt, pStmt->pOptions->pFuncs);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checTableFactorOption(pCxt, pStmt->pOptions->pFilesFactor); code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkRangeOption(pCxt, "delay", pStmt->pOptions->pDelay, TSDB_MIN_DB_DELAY, TSDB_MAX_DB_DELAY); code = checkTableSmaOption(pCxt, pStmt);
} }
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = checkTableTags(pCxt, pStmt); code = checkTableTags(pCxt, pStmt);
...@@ -2143,7 +2067,7 @@ static SNodeList* createRollupFuncs(SCreateTableStmt* pStmt) { ...@@ -2143,7 +2067,7 @@ static SNodeList* createRollupFuncs(SCreateTableStmt* pStmt) {
} }
SNode* pFunc = NULL; SNode* pFunc = NULL;
FOREACH(pFunc, pStmt->pOptions->pFuncs) { FOREACH(pFunc, pStmt->pOptions->pRollupFuncs) {
SNode* pCol = NULL; SNode* pCol = NULL;
bool primaryKey = true; bool primaryKey = true;
FOREACH(pCol, pStmt->pCols) { FOREACH(pCol, pStmt->pCols) {
...@@ -2234,8 +2158,8 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt, ...@@ -2234,8 +2158,8 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) { static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) {
pReq->igExists = pStmt->ignoreExists; pReq->igExists = pStmt->ignoreExists;
pReq->xFilesFactor = GET_OPTION_VAL(pStmt->pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR); pReq->xFilesFactor = pStmt->pOptions->filesFactor;
pReq->delay = GET_OPTION_VAL(pStmt->pOptions->pDelay, TSDB_DEFAULT_DB_DELAY); pReq->delay = pStmt->pOptions->delay;
columnDefNodeToField(pStmt->pCols, &pReq->pColumns); columnDefNodeToField(pStmt->pCols, &pReq->pColumns);
columnDefNodeToField(pStmt->pTags, &pReq->pTags); columnDefNodeToField(pStmt->pTags, &pReq->pTags);
pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); pReq->numOfColumns = LIST_LENGTH(pStmt->pCols);
...@@ -3221,23 +3145,6 @@ static void destroyCreateTbReq(SVCreateTbReq* pReq) { ...@@ -3221,23 +3145,6 @@ static void destroyCreateTbReq(SVCreateTbReq* pReq) {
taosMemoryFreeClear(pReq->ntb.schema.pSchema); taosMemoryFreeClear(pReq->ntb.schema.pSchema);
} }
static int32_t buildSmaParam(STableOptions* pOptions, SVCreateTbReq* pReq) {
if (0 == LIST_LENGTH(pOptions->pFuncs)) {
return TSDB_CODE_SUCCESS;
}
#if 0
pReq->ntbCfg.pRSmaParam = taosMemoryCalloc(1, sizeof(SRSmaParam));
if (NULL == pReq->ntbCfg.pRSmaParam) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pReq->ntbCfg.pRSmaParam->delay = GET_OPTION_VAL(pOptions->pDelay, TSDB_DEFAULT_DB_DELAY);
pReq->ntbCfg.pRSmaParam->xFilesFactor = GET_OPTION_VAL(pOptions->pFilesFactor, TSDB_DEFAULT_DB_FILE_FACTOR);
#endif
return TSDB_CODE_SUCCESS;
}
static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pVgroupInfo, static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pVgroupInfo,
SVgroupTablesBatch* pBatch) { SVgroupTablesBatch* pBatch) {
char dbFName[TSDB_DB_FNAME_LEN] = {0}; char dbFName[TSDB_DB_FNAME_LEN] = {0};
...@@ -3261,11 +3168,6 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* ...@@ -3261,11 +3168,6 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
toSchema((SColumnDefNode*)pCol, index + 1, req.ntb.schema.pSchema + index); toSchema((SColumnDefNode*)pCol, index + 1, req.ntb.schema.pSchema + index);
++index; ++index;
} }
if (TSDB_CODE_SUCCESS != buildSmaParam(pStmt->pOptions, &req)) {
destroyCreateTbReq(&req);
return TSDB_CODE_OUT_OF_MEMORY;
}
pBatch->info = *pVgroupInfo; pBatch->info = *pVgroupInfo;
strcpy(pBatch->dbName, pStmt->dbName); strcpy(pBatch->dbName, pStmt->dbName);
pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq));
......
...@@ -68,8 +68,6 @@ static char* getSyntaxErrFormat(int32_t errCode) { ...@@ -68,8 +68,6 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return "Invalid option %s: %s"; return "Invalid option %s: %s";
case TSDB_CODE_PAR_INVALID_ENUM_OPTION: case TSDB_CODE_PAR_INVALID_ENUM_OPTION:
return "Invalid option %s: %" PRId64 ", only %d, %d allowed"; return "Invalid option %s: %" PRId64 ", only %d, %d allowed";
case TSDB_CODE_PAR_INVALID_TTL_OPTION:
return "Invalid option ttl: %" PRId64 ", should be greater than or equal to %d";
case TSDB_CODE_PAR_INVALID_KEEP_NUM: case TSDB_CODE_PAR_INVALID_KEEP_NUM:
return "Invalid number of keep options"; return "Invalid number of keep options";
case TSDB_CODE_PAR_INVALID_KEEP_ORDER: case TSDB_CODE_PAR_INVALID_KEEP_ORDER:
...@@ -89,7 +87,7 @@ static char* getSyntaxErrFormat(int32_t errCode) { ...@@ -89,7 +87,7 @@ static char* getSyntaxErrFormat(int32_t errCode) {
case TSDB_CODE_PAR_INVALID_OPTION_UNIT: case TSDB_CODE_PAR_INVALID_OPTION_UNIT:
return "Invalid option %s unit: %c, only m, h, d allowed"; return "Invalid option %s unit: %c, only m, h, d allowed";
case TSDB_CODE_PAR_INVALID_KEEP_UNIT: case TSDB_CODE_PAR_INVALID_KEEP_UNIT:
return "Invalid option keep unit: %c, %c, %c, only m, h, d allowed"; return "Invalid option keep unit: %c, only m, h, d allowed";
case TSDB_CODE_PAR_AGG_FUNC_NESTING: case TSDB_CODE_PAR_AGG_FUNC_NESTING:
return "Aggregate functions do not support nesting"; return "Aggregate functions do not support nesting";
case TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE: case TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE:
......
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -13,9 +13,14 @@ ...@@ -13,9 +13,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PARSER_TEST_UTIL_H #include "parTestUtil.h"
#define PARSER_TEST_UTIL_H
extern bool g_isDump; using namespace std;
#endif // PARSER_TEST_UTIL_H class ParserAlterTest : public ParserTestBase {};
TEST_F(ParserAlterTest, stmt) {
useDb("root", "test");
run("create database db1");
}
...@@ -13,23 +13,22 @@ ...@@ -13,23 +13,22 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <getopt.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <getopt.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#ifdef WINDOWS #ifdef WINDOWS
#define TD_USE_WINSOCK #define TD_USE_WINSOCK
#endif #endif
#include "functionMgt.h" #include "functionMgt.h"
#include "mockCatalog.h" #include "mockCatalog.h"
#include "os.h" #include "os.h"
#include "parTestUtil.h"
#include "parToken.h" #include "parToken.h"
#include "parserTestUtil.h"
bool g_isDump = false;
class ParserEnv : public testing::Environment { class ParserEnv : public testing::Environment {
public: public:
......
/*
* 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/>.
*/
#include "parTestUtil.h"
#include <algorithm>
#include <array>
#include "parInt.h"
using namespace std;
using namespace testing;
#define DO_WITH_THROW(func, ...) \
do { \
int32_t code__ = func(__VA_ARGS__); \
if (TSDB_CODE_SUCCESS != code__) { \
throw runtime_error("sql:[" + stmtEnv_.sql_ + "] " #func " code:" + to_string(code__) + \
", strerror:" + string(tstrerror(code__)) + ", msg:" + string(stmtEnv_.msgBuf_.data())); \
} \
} while (0);
bool g_isDump = false;
class ParserTestBaseImpl {
public:
void useDb(const string& acctId, const string& db) {
caseEnv_.acctId_ = acctId;
caseEnv_.db_ = db;
}
void run(const string& sql) {
reset();
try {
SParseContext cxt = {0};
setParseContext(sql, &cxt);
SQuery* pQuery = nullptr;
doParse(&cxt, &pQuery);
doTranslate(&cxt, pQuery);
doCalculateConstant(&cxt, pQuery);
if (g_isDump) {
dump();
}
} catch (...) {
dump();
throw;
}
}
private:
struct caseEnv {
string acctId_;
string db_;
};
struct stmtEnv {
string sql_;
array<char, 1024> msgBuf_;
};
struct stmtRes {
string parsedAst_;
string translatedAst_;
string calcConstAst_;
};
void reset() {
stmtEnv_.sql_.clear();
stmtEnv_.msgBuf_.fill(0);
res_.parsedAst_.clear();
res_.translatedAst_.clear();
res_.calcConstAst_.clear();
}
void dump() {
cout << "==========================================sql : [" << stmtEnv_.sql_ << "]" << endl;
cout << "raw syntax tree : " << endl;
cout << res_.parsedAst_ << endl;
cout << "translated syntax tree : " << endl;
cout << res_.translatedAst_ << endl;
cout << "optimized syntax tree : " << endl;
cout << res_.calcConstAst_ << endl;
}
void setParseContext(const string& sql, SParseContext* pCxt) {
stmtEnv_.sql_ = sql;
transform(stmtEnv_.sql_.begin(), stmtEnv_.sql_.end(), stmtEnv_.sql_.begin(), ::tolower);
pCxt->acctId = atoi(caseEnv_.acctId_.c_str());
pCxt->db = caseEnv_.db_.c_str();
pCxt->pSql = stmtEnv_.sql_.c_str();
pCxt->sqlLen = stmtEnv_.sql_.length();
pCxt->pMsg = stmtEnv_.msgBuf_.data();
pCxt->msgLen = stmtEnv_.msgBuf_.max_size();
}
void doParse(SParseContext* pCxt, SQuery** pQuery) {
DO_WITH_THROW(parse, pCxt, pQuery);
res_.parsedAst_ = toString((*pQuery)->pRoot);
}
void doTranslate(SParseContext* pCxt, SQuery* pQuery) {
DO_WITH_THROW(translate, pCxt, pQuery);
res_.translatedAst_ = toString(pQuery->pRoot);
}
void doCalculateConstant(SParseContext* pCxt, SQuery* pQuery) {
DO_WITH_THROW(calculateConstant, pCxt, pQuery);
res_.calcConstAst_ = toString(pQuery->pRoot);
}
string toString(const SNode* pRoot) {
char* pStr = NULL;
int32_t len = 0;
DO_WITH_THROW(nodesNodeToString, pRoot, false, &pStr, &len)
string str(pStr);
taosMemoryFreeClear(pStr);
return str;
}
caseEnv caseEnv_;
stmtEnv stmtEnv_;
stmtRes res_;
};
ParserTestBase::ParserTestBase() : impl_(new ParserTestBaseImpl()) {}
ParserTestBase::~ParserTestBase() {}
void ParserTestBase::useDb(const std::string& acctId, const std::string& db) { impl_->useDb(acctId, db); }
void ParserTestBase::run(const std::string& sql) { return impl_->run(sql); }
/*
* 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 PARSER_TEST_UTIL_H
#define PARSER_TEST_UTIL_H
#include <gtest/gtest.h>
class ParserTestBaseImpl;
class ParserTestBase : public testing::Test {
public:
ParserTestBase();
virtual ~ParserTestBase();
void useDb(const std::string& acctId, const std::string& db);
void run(const std::string& sql);
private:
std::unique_ptr<ParserTestBaseImpl> impl_;
};
extern bool g_isDump;
#endif // PARSER_TEST_UTIL_H
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "parInt.h" #include "parInt.h"
#include "parserTestUtil.h" #include "parTestUtil.h"
using namespace std; using namespace std;
using namespace testing; using namespace testing;
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
*/ */
#include "planTestUtil.h" #include "planTestUtil.h"
#include <array>
#include <algorithm> #include <algorithm>
#include <array>
#include "cmdnodes.h" #include "cmdnodes.h"
#include "parser.h" #include "parser.h"
......
...@@ -15,7 +15,8 @@ $tb = $tbPrefix . $i ...@@ -15,7 +15,8 @@ $tb = $tbPrefix . $i
print =============== step1 print =============== step1
# quorum presicion # quorum presicion
sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us' #sql create database $db vgroups 8 replica 1 days 2880 keep 3650 cache 32 blocks 12 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us'
sql create database $db vgroups 8 replica 1 days 2880 keep 3650 minrows 80 maxrows 10000 wal 2 fsync 1000 comp 0 cachelast 2 precision 'us'
sql show databases sql show databases
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
...@@ -40,12 +41,12 @@ endi ...@@ -40,12 +41,12 @@ endi
if $data27 != 3650,3650,3650 then if $data27 != 3650,3650,3650 then
return -1 return -1
endi endi
if $data28 != 32 then #if $data28 != 32 then
return -1 # return -1
endi #endi
if $data29 != 12 then #if $data29 != 12 then
return -1 # return -1
endi #endi
print =============== step2 print =============== step2
sql_error create database $db sql_error create database $db
......
...@@ -124,12 +124,12 @@ endi ...@@ -124,12 +124,12 @@ endi
if $data7_db != 5256000,5256000,5256000 then # keep if $data7_db != 5256000,5256000,5256000 then # keep
return -1 return -1
endi endi
if $data8_db != 16 then # cache #if $data8_db != 16 then # cache
return -1 # return -1
endi #endi
if $data9_db != 6 then # blocks #if $data9_db != 6 then # blocks
return -1 # return -1
endi #endi
if $data10_db != 100 then # minrows if $data10_db != 100 then # minrows
return -1 return -1
endi endi
...@@ -153,42 +153,42 @@ if $data16_db != ms then # precision ...@@ -153,42 +153,42 @@ if $data16_db != ms then # precision
endi endi
sql drop database db sql drop database db
print ====> BLOCKS value [3~1000, default: 6] #print ====> BLOCKS value [3~1000, default: 6]
sql create database db BLOCKS 3 #sql create database db BLOCKS 3
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
if $data9_db != 3 then #if $data9_db != 3 then
return -1 # return -1
endi #endi
sql drop database db #sql drop database db
sql create database db BLOCKS 1000 #sql create database db BLOCKS 1000
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
if $data9_db != 1000 then #if $data9_db != 1000 then
return -1 # return -1
endi #endi
sql drop database db #sql drop database db
sql_error create database db BLOCKS 2 #sql_error create database db BLOCKS 2
sql_error create database db BLOCKS 0 #sql_error create database db BLOCKS 0
sql_error create database db BLOCKS -1 #sql_error create database db BLOCKS -1
print ====> CACHE value [default: 16] #print ====> CACHE value [default: 16]
sql create database db CACHE 1 #sql create database db CACHE 1
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
if $data8_db != 1 then #if $data8_db != 1 then
return -1 # return -1
endi #endi
sql drop database db #sql drop database db
sql create database db CACHE 128 #sql create database db CACHE 128
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
if $data8_db != 128 then #if $data8_db != 128 then
return -1 # return -1
endi #endi
sql drop database db #sql drop database db
print ====> CACHELAST value [0, 1, 2, 3, default: 0] print ====> CACHELAST value [0, 1, 2, 3, default: 0]
sql create database db CACHELAST 1 sql create database db CACHELAST 1
...@@ -387,24 +387,24 @@ sql_error create database db REPLICA 0 ...@@ -387,24 +387,24 @@ sql_error create database db REPLICA 0
sql_error create database db REPLICA -1 sql_error create database db REPLICA -1
sql_error create database db REPLICA 4 sql_error create database db REPLICA 4
print ====> TTL value [1d ~ , default: 1] #print ====> TTL value [1d ~ , default: 1]
sql create database db TTL 1 #sql create database db TTL 1
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
#if $dataXX_db != 1 then #if $dataXX_db != 1 then
# return -1 # return -1
#endi #endi
sql drop database db #sql drop database db
sql create database db TTL 10 #sql create database db TTL 10
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
#if $dataXX_db != 10 then #if $dataXX_db != 10 then
# return -1 # return -1
#endi #endi
sql drop database db #sql drop database db
sql_error create database db TTL 0 #sql_error create database db TTL 0
sql_error create database db TTL -1 #sql_error create database db TTL -1
print ====> WAL value [1 | 2, default: 1] print ====> WAL value [1 | 2, default: 1]
sql create database db WAL 2 sql create database db WAL 2
...@@ -465,24 +465,24 @@ sql drop database db ...@@ -465,24 +465,24 @@ sql drop database db
sql_error create database db SINGLE_STABLE 2 sql_error create database db SINGLE_STABLE 2
sql_error create database db SINGLE_STABLE -1 sql_error create database db SINGLE_STABLE -1
print ====> STREAM_MODE [0 | 1, default: ] #print ====> STREAM_MODE [0 | 1, default: ]
sql create database db STREAM_MODE 1 #sql create database db STREAM_MODE 1
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
#if $dataXXX_db != 1 then #if $dataXXX_db != 1 then
# return -1 # return -1
#endi #endi
sql drop database db #sql drop database db
sql create database db STREAM_MODE 0 #sql create database db STREAM_MODE 0
sql show databases #sql show databases
print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db #print $data0_db $data1_db $data2_db $data3_db $data4_db $data5_db $data6_db $data7_db $data8_db $data9_db $data10_db $data11_db $data12_db $data13_db $data14_db $data15_db $data16_db $data17_db
#if $dataXXX_db != 0 then #if $dataXXX_db != 0 then
# return -1 # return -1
#endi #endi
sql drop database db #sql drop database db
sql_error create database db STREAM_MODE 2 #sql_error create database db STREAM_MODE 2
sql_error create database db STREAM_MODE -1 #sql_error create database db STREAM_MODE -1
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册