feat:[TS-5323] Support using 'level' as columnname.
This commit is contained in:
parent
16a95f577f
commit
4c9bfac39d
|
@ -59,6 +59,7 @@
|
|||
|
||||
#define TSDB_CL_COMMENT_LEN 1025
|
||||
#define TSDB_CL_COMPRESS_OPTION_LEN 12
|
||||
#define TSDB_CL_OPTION_LEN 9
|
||||
|
||||
extern const char* supportedEncode[5];
|
||||
extern const char* supportedCompress[6];
|
||||
|
|
|
@ -397,9 +397,6 @@
|
|||
#define TK_VALUES 379
|
||||
#define TK_VARIABLE 380
|
||||
#define TK_WAL 381
|
||||
#define TK_ENCODE 382
|
||||
#define TK_COMPRESS 383
|
||||
#define TK_LEVEL 384
|
||||
|
||||
#define TK_NK_SPACE 600
|
||||
#define TK_NK_COMMENT 601
|
||||
|
|
|
@ -200,7 +200,8 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
|
|||
SNode* createAlterTableOptions(SAstCreateContext* pCxt);
|
||||
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal);
|
||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, SNode* pOptions);
|
||||
SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, EColumnOptionType type, void* pVal);
|
||||
SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal1, void* pVal2);
|
||||
SNode* setColumnOptionsPK(SAstCreateContext* pCxt, SNode* pOptions);
|
||||
SNode* createDefaultColumnOptions(SAstCreateContext* pCxt);
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
|
||||
SNodeList* pTags, SNode* pOptions);
|
||||
|
|
|
@ -750,7 +750,7 @@ column_stream_def_list(A) ::= column_stream_def_list(B)
|
|||
|
||||
column_stream_def(A) ::= column_name(B) stream_col_options(C). { A = createColumnDefNode(pCxt, &B, createDataType(TSDB_DATA_TYPE_NULL), C); }
|
||||
stream_col_options(A) ::= . { A = createDefaultColumnOptions(pCxt); }
|
||||
stream_col_options(A) ::= stream_col_options(B) PRIMARY KEY. { A = setColumnOptions(pCxt, B, COLUMN_OPTION_PRIMARYKEY, NULL); }
|
||||
stream_col_options(A) ::= stream_col_options(B) PRIMARY KEY. { A = setColumnOptionsPK(pCxt, B); }
|
||||
//column_stream_def(A) ::= column_def(B). { A = B; }
|
||||
|
||||
%type tag_def_or_ref_opt { SNodeList* }
|
||||
|
@ -1611,7 +1611,5 @@ null_ordering_opt(A) ::= NULLS LAST.
|
|||
STRICT STRING TIMES VALUES VARIABLE VIEW WAL.
|
||||
|
||||
column_options(A) ::= . { A = createDefaultColumnOptions(pCxt); }
|
||||
column_options(A) ::= column_options(B) PRIMARY KEY. { A = setColumnOptions(pCxt, B, COLUMN_OPTION_PRIMARYKEY, NULL); }
|
||||
column_options(A) ::= column_options(B) ENCODE NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_ENCODE, &C); }
|
||||
column_options(A) ::= column_options(B) COMPRESS NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_COMPRESS, &C); }
|
||||
column_options(A) ::= column_options(B) LEVEL NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_LEVEL, &C); }
|
||||
column_options(A) ::= column_options(B) PRIMARY KEY. { A = setColumnOptionsPK(pCxt, B); }
|
||||
column_options(A) ::= column_options(B) NK_ID(C) NK_STRING(D). { A = setColumnOptions(pCxt, B, &C, &D); }
|
||||
|
|
|
@ -2160,34 +2160,60 @@ _err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, EColumnOptionType type, void* pVal) {
|
||||
EColumnOptionType getColumnOptionType(const char* optionType) {
|
||||
if (0 == strcasecmp(optionType, "ENCODE")) {
|
||||
return COLUMN_OPTION_ENCODE;
|
||||
} else if (0 == strcasecmp(optionType, "COMPRESS")) {
|
||||
return COLUMN_OPTION_COMPRESS;
|
||||
} else if (0 == strcasecmp(optionType, "LEVEL")) {
|
||||
return COLUMN_OPTION_LEVEL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
SNode* setColumnOptionsPK(SAstCreateContext* pCxt, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
((SColumnOptions*)pOptions)->bPrimaryKey = true;
|
||||
return pOptions;
|
||||
_err:
|
||||
nodesDestroyNode(pOptions);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SNode* setColumnOptions(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal1, void* pVal2) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
char optionType[TSDB_CL_OPTION_LEN];
|
||||
|
||||
memset(optionType, 0, TSDB_CL_OPTION_LEN);
|
||||
strncpy(optionType, pVal1->z, TMIN(pVal1->n, TSDB_CL_OPTION_LEN));
|
||||
if (0 == strlen(optionType)) {
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||
return pOptions;
|
||||
}
|
||||
EColumnOptionType type = getColumnOptionType(optionType);
|
||||
switch (type) {
|
||||
case COLUMN_OPTION_ENCODE:
|
||||
memset(((SColumnOptions*)pOptions)->encode, 0, TSDB_CL_COMPRESS_OPTION_LEN);
|
||||
COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->encode, (SToken*)pVal);
|
||||
COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->encode, (SToken*)pVal2);
|
||||
if (0 == strlen(((SColumnOptions*)pOptions)->encode)) {
|
||||
pCxt->errCode = TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
|
||||
}
|
||||
break;
|
||||
case COLUMN_OPTION_COMPRESS:
|
||||
memset(((SColumnOptions*)pOptions)->compress, 0, TSDB_CL_COMPRESS_OPTION_LEN);
|
||||
COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->compress, (SToken*)pVal);
|
||||
COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->compress, (SToken*)pVal2);
|
||||
if (0 == strlen(((SColumnOptions*)pOptions)->compress)) {
|
||||
pCxt->errCode = TSDB_CODE_TSC_COMPRESS_PARAM_ERROR;
|
||||
}
|
||||
break;
|
||||
case COLUMN_OPTION_LEVEL:
|
||||
memset(((SColumnOptions*)pOptions)->compressLevel, 0, TSDB_CL_COMPRESS_OPTION_LEN);
|
||||
COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->compressLevel, (SToken*)pVal);
|
||||
COPY_STRING_FORM_STR_TOKEN(((SColumnOptions*)pOptions)->compressLevel, (SToken*)pVal2);
|
||||
if (0 == strlen(((SColumnOptions*)pOptions)->compressLevel)) {
|
||||
pCxt->errCode = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
|
||||
}
|
||||
break;
|
||||
case COLUMN_OPTION_PRIMARYKEY:
|
||||
((SColumnOptions*)pOptions)->bPrimaryKey = true;
|
||||
break;
|
||||
default:
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||
break;
|
||||
}
|
||||
return pOptions;
|
||||
|
|
|
@ -338,9 +338,6 @@ static SKeyword keywordTable[] = {
|
|||
{"S3_COMPACT", TK_S3_COMPACT},
|
||||
{"S3MIGRATE", TK_S3MIGRATE},
|
||||
{"KEEP_TIME_OFFSET", TK_KEEP_TIME_OFFSET},
|
||||
{"ENCODE", TK_ENCODE},
|
||||
{"COMPRESS", TK_COMPRESS},
|
||||
{"LEVEL", TK_LEVEL},
|
||||
{"ARBGROUPS", TK_ARBGROUPS},
|
||||
{"IS_IMPORT", TK_IS_IMPORT},
|
||||
};
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -279,6 +279,12 @@ class TDTestCase(TBase):
|
|||
|
||||
# alter error
|
||||
sqls = [
|
||||
f"alter table {tbname} add column a1 int ONLYOPTION",
|
||||
f"alter table {tbname} add column a1 int 'simple8b';",
|
||||
f"alter table {tbname} add column a1 int WRONG 'simple8b';",
|
||||
f"alter table {tbname} add column a1 int 123456789 'simple8b';",
|
||||
f"alter table {tbname} add column a1 int WRONGANDVERYLONG 'simple8b';",
|
||||
f"alter table {tbname} add column a1 int ENCODE 'veryveryveryveryveryverylong';",
|
||||
f"alter table {tbname} add column a1 int ENCODE 'simple8bAA';",
|
||||
f"alter table {tbname} add column a2 int COMPRESS 'AABB';",
|
||||
f"alter table {tbname} add column a3 bigint LEVEL 'high1';",
|
||||
|
|
Loading…
Reference in New Issue