Merge pull request #27583 from taosdata/feat/TS-5323

feat:[TS-5323] Support using 'level' as columnname.
This commit is contained in:
Pan Wei 2024-09-02 18:58:59 +08:00 committed by GitHub
commit 944c4bf5d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 3006 additions and 2974 deletions

View File

@ -59,6 +59,7 @@
#define TSDB_CL_COMMENT_LEN 1025 #define TSDB_CL_COMMENT_LEN 1025
#define TSDB_CL_COMPRESS_OPTION_LEN 12 #define TSDB_CL_COMPRESS_OPTION_LEN 12
#define TSDB_CL_OPTION_LEN 9
extern const char* supportedEncode[5]; extern const char* supportedEncode[5];
extern const char* supportedCompress[6]; extern const char* supportedCompress[6];

View File

@ -397,9 +397,6 @@
#define TK_VALUES 379 #define TK_VALUES 379
#define TK_VARIABLE 380 #define TK_VARIABLE 380
#define TK_WAL 381 #define TK_WAL 381
#define TK_ENCODE 382
#define TK_COMPRESS 383
#define TK_LEVEL 384
#define TK_NK_SPACE 600 #define TK_NK_SPACE 600
#define TK_NK_COMMENT 601 #define TK_NK_COMMENT 601

View File

@ -200,7 +200,8 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt);
SNode* createAlterTableOptions(SAstCreateContext* pCxt); SNode* createAlterTableOptions(SAstCreateContext* pCxt);
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal); SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal);
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, SNode* pOptions); 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* createDefaultColumnOptions(SAstCreateContext* pCxt);
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);

View File

@ -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); } 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) ::= . { 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; } //column_stream_def(A) ::= column_def(B). { A = B; }
%type tag_def_or_ref_opt { SNodeList* } %type tag_def_or_ref_opt { SNodeList* }
@ -1611,7 +1611,5 @@ null_ordering_opt(A) ::= NULLS LAST.
STRICT STRING TIMES VALUES VARIABLE VIEW WAL. STRICT STRING TIMES VALUES VARIABLE VIEW WAL.
column_options(A) ::= . { A = createDefaultColumnOptions(pCxt); } 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) PRIMARY KEY. { A = setColumnOptionsPK(pCxt, B); }
column_options(A) ::= column_options(B) ENCODE NK_STRING(C). { A = setColumnOptions(pCxt, B, COLUMN_OPTION_ENCODE, &C); } column_options(A) ::= column_options(B) NK_ID(C) NK_STRING(D). { A = setColumnOptions(pCxt, B, &C, &D); }
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); }

View File

@ -2160,34 +2160,60 @@ _err:
return NULL; 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); 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) { switch (type) {
case COLUMN_OPTION_ENCODE: case COLUMN_OPTION_ENCODE:
memset(((SColumnOptions*)pOptions)->encode, 0, TSDB_CL_COMPRESS_OPTION_LEN); 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)) { if (0 == strlen(((SColumnOptions*)pOptions)->encode)) {
pCxt->errCode = TSDB_CODE_TSC_ENCODE_PARAM_ERROR; pCxt->errCode = TSDB_CODE_TSC_ENCODE_PARAM_ERROR;
} }
break; break;
case COLUMN_OPTION_COMPRESS: case COLUMN_OPTION_COMPRESS:
memset(((SColumnOptions*)pOptions)->compress, 0, TSDB_CL_COMPRESS_OPTION_LEN); 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)) { if (0 == strlen(((SColumnOptions*)pOptions)->compress)) {
pCxt->errCode = TSDB_CODE_TSC_COMPRESS_PARAM_ERROR; pCxt->errCode = TSDB_CODE_TSC_COMPRESS_PARAM_ERROR;
} }
break; break;
case COLUMN_OPTION_LEVEL: case COLUMN_OPTION_LEVEL:
memset(((SColumnOptions*)pOptions)->compressLevel, 0, TSDB_CL_COMPRESS_OPTION_LEN); 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)) { if (0 == strlen(((SColumnOptions*)pOptions)->compressLevel)) {
pCxt->errCode = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR; pCxt->errCode = TSDB_CODE_TSC_COMPRESS_LEVEL_ERROR;
} }
break; break;
case COLUMN_OPTION_PRIMARYKEY:
((SColumnOptions*)pOptions)->bPrimaryKey = true;
break;
default: default:
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
break; break;
} }
return pOptions; return pOptions;

View File

@ -338,9 +338,6 @@ static SKeyword keywordTable[] = {
{"S3_COMPACT", TK_S3_COMPACT}, {"S3_COMPACT", TK_S3_COMPACT},
{"S3MIGRATE", TK_S3MIGRATE}, {"S3MIGRATE", TK_S3MIGRATE},
{"KEEP_TIME_OFFSET", TK_KEEP_TIME_OFFSET}, {"KEEP_TIME_OFFSET", TK_KEEP_TIME_OFFSET},
{"ENCODE", TK_ENCODE},
{"COMPRESS", TK_COMPRESS},
{"LEVEL", TK_LEVEL},
{"ARBGROUPS", TK_ARBGROUPS}, {"ARBGROUPS", TK_ARBGROUPS},
{"IS_IMPORT", TK_IS_IMPORT}, {"IS_IMPORT", TK_IS_IMPORT},
}; };

File diff suppressed because it is too large Load Diff

View File

@ -279,6 +279,12 @@ class TDTestCase(TBase):
# alter error # alter error
sqls = [ 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 a1 int ENCODE 'simple8bAA';",
f"alter table {tbname} add column a2 int COMPRESS 'AABB';", f"alter table {tbname} add column a2 int COMPRESS 'AABB';",
f"alter table {tbname} add column a3 bigint LEVEL 'high1';", f"alter table {tbname} add column a3 bigint LEVEL 'high1';",