support update multi tag
This commit is contained in:
parent
868a1ce80c
commit
3027e377fa
|
@ -178,6 +178,7 @@ typedef enum _mgmt_table {
|
|||
#define TSDB_ALTER_TABLE_DROP_TAG_INDEX 12
|
||||
#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS 13
|
||||
#define TSDB_ALTER_TABLE_ADD_COLUMN_WITH_COMPRESS_OPTION 14
|
||||
#define TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL 15
|
||||
|
||||
#define TSDB_FILL_NONE 0
|
||||
#define TSDB_FILL_NULL 1
|
||||
|
@ -351,6 +352,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_CREATE_ANODE_STMT,
|
||||
QUERY_NODE_DROP_ANODE_STMT,
|
||||
QUERY_NODE_UPDATE_ANODE_STMT,
|
||||
QUERY_NODE_ALTER_TABLE_MULTI_STMT,
|
||||
|
||||
// show statement nodes
|
||||
// see 'sysTableShowAdapter', 'SYSTABLE_SHOW_TYPE_OFFSET'
|
||||
|
@ -421,7 +423,7 @@ typedef enum ENodeType {
|
|||
// physical plan node
|
||||
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN = 1100,
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, // INACTIVE
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, // INACTIVE
|
||||
QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN,
|
||||
|
@ -435,7 +437,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_PHYSICAL_PLAN_SORT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, // INACTIVE
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, // INACTIVE
|
||||
QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL,
|
||||
|
@ -985,7 +987,6 @@ typedef struct SEpSet {
|
|||
SEp eps[TSDB_MAX_REPLICA];
|
||||
} SEpSet;
|
||||
|
||||
|
||||
int32_t tEncodeSEpSet(SEncoder* pEncoder, const SEpSet* pEp);
|
||||
int32_t tDecodeSEpSet(SDecoder* pDecoder, SEpSet* pEp);
|
||||
int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp);
|
||||
|
@ -3259,6 +3260,16 @@ int32_t tEncodeSVDropTbBatchRsp(SEncoder* pCoder, const SVDropTbBatchRsp* pRsp);
|
|||
int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
|
||||
|
||||
// TDMT_VND_ALTER_TABLE =====================
|
||||
typedef struct SMultiTagUpateVal {
|
||||
char* tagName;
|
||||
int32_t colId;
|
||||
int8_t tagType;
|
||||
int8_t tagFree;
|
||||
uint32_t nTagVal;
|
||||
uint8_t* pTagVal;
|
||||
int8_t isNull;
|
||||
SArray* pTagArray;
|
||||
} SMultiTagUpateVal;
|
||||
typedef struct {
|
||||
char* tbName;
|
||||
int8_t action;
|
||||
|
@ -3285,9 +3296,10 @@ typedef struct {
|
|||
int32_t newTTL;
|
||||
int32_t newCommentLen;
|
||||
char* newComment;
|
||||
int64_t ctimeMs; // fill by vnode
|
||||
int8_t source; // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
|
||||
uint32_t compress; // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
|
||||
int64_t ctimeMs; // fill by vnode
|
||||
int8_t source; // TD_REQ_FROM_TAOX-taosX or TD_REQ_FROM_APP-taosClient
|
||||
uint32_t compress; // TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS
|
||||
SArray* pMultiTag; // TSDB_ALTER_TABLE_ADD_MULTI_TAGS
|
||||
} SVAlterTbReq;
|
||||
|
||||
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
|
||||
|
@ -4143,20 +4155,20 @@ typedef struct {
|
|||
SArray* blockTbName;
|
||||
SArray* blockSchema;
|
||||
|
||||
union{
|
||||
struct{
|
||||
int64_t sleepTime;
|
||||
union {
|
||||
struct {
|
||||
int64_t sleepTime;
|
||||
};
|
||||
struct{
|
||||
int32_t createTableNum;
|
||||
SArray* createTableLen;
|
||||
SArray* createTableReq;
|
||||
struct {
|
||||
int32_t createTableNum;
|
||||
SArray* createTableLen;
|
||||
SArray* createTableReq;
|
||||
};
|
||||
};
|
||||
|
||||
} SMqDataRsp;
|
||||
|
||||
int32_t tEncodeMqDataRsp(SEncoder *pEncoder, const SMqDataRsp *pObj);
|
||||
int32_t tEncodeMqDataRsp(SEncoder* pEncoder, const SMqDataRsp* pObj);
|
||||
int32_t tDecodeMqDataRsp(SDecoder* pDecoder, SMqDataRsp* pRsp);
|
||||
void tDeleteMqDataRsp(SMqDataRsp* pRsp);
|
||||
|
||||
|
|
|
@ -264,8 +264,30 @@ typedef struct SAlterTableStmt {
|
|||
SDataType dataType;
|
||||
SValueNode* pVal;
|
||||
SColumnOptions* pColOptions;
|
||||
SNodeList* pNodeListTagValue;
|
||||
} SAlterTableStmt;
|
||||
|
||||
|
||||
typedef struct SAlterTableStmt2 {
|
||||
ENodeType type;
|
||||
int8_t alterType;
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
STableOptions* pOptions;
|
||||
SDataType dataType;
|
||||
SValueNode* pVal;
|
||||
SColumnOptions* pColOptions;
|
||||
|
||||
} SAlterTableStmt2;
|
||||
|
||||
typedef struct SAlterTableMultiStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
int8_t alterType;
|
||||
|
||||
SNodeList* pNodeListTagValue;
|
||||
} SAlterTableMultiStmt;
|
||||
|
||||
typedef struct SCreateUserStmt {
|
||||
ENodeType type;
|
||||
char userName[TSDB_USER_LEN];
|
||||
|
@ -341,7 +363,7 @@ typedef struct SShowStmt {
|
|||
SNode* pTbName; // SValueNode
|
||||
EOperatorType tableCondType;
|
||||
EShowKind showKind; // show databases: user/system, show tables: normal/child, others NULL
|
||||
bool withFull; // for show users full;
|
||||
bool withFull; // for show users full;
|
||||
} SShowStmt;
|
||||
|
||||
typedef struct SShowCreateDatabaseStmt {
|
||||
|
@ -651,7 +673,7 @@ typedef struct SCreateTSMAStmt {
|
|||
bool ignoreExists;
|
||||
char tsmaName[TSDB_TABLE_NAME_LEN];
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN]; // base tb name or base tsma name
|
||||
char tableName[TSDB_TABLE_NAME_LEN]; // base tb name or base tsma name
|
||||
char originalTbName[TSDB_TABLE_NAME_LEN];
|
||||
STSMAOptions* pOptions;
|
||||
SNode* pPrevQuery;
|
||||
|
@ -660,10 +682,10 @@ typedef struct SCreateTSMAStmt {
|
|||
} SCreateTSMAStmt;
|
||||
|
||||
typedef struct SDropTSMAStmt {
|
||||
ENodeType type;
|
||||
bool ignoreNotExists;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tsmaName[TSDB_TABLE_NAME_LEN];
|
||||
ENodeType type;
|
||||
bool ignoreNotExists;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tsmaName[TSDB_TABLE_NAME_LEN];
|
||||
} SDropTSMAStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -2166,9 +2166,9 @@ int32_t tSerializeRetrieveAnalAlgoRsp(void *buf, int32_t bufLen, SRetrieveAnalAl
|
|||
int32_t numOfAlgos = 0;
|
||||
void *pIter = taosHashIterate(pRsp->hash, NULL);
|
||||
while (pIter != NULL) {
|
||||
SAnalyticsUrl *pUrl = pIter;
|
||||
size_t nameLen = 0;
|
||||
const char *name = taosHashGetKey(pIter, &nameLen);
|
||||
SAnalyticsUrl *pUrl = pIter;
|
||||
size_t nameLen = 0;
|
||||
const char *name = taosHashGetKey(pIter, &nameLen);
|
||||
if (nameLen > 0 && nameLen <= TSDB_ANALYTIC_ALGO_KEY_LEN && pUrl->urlLen > 0) {
|
||||
numOfAlgos++;
|
||||
}
|
||||
|
@ -2181,9 +2181,9 @@ int32_t tSerializeRetrieveAnalAlgoRsp(void *buf, int32_t bufLen, SRetrieveAnalAl
|
|||
|
||||
pIter = taosHashIterate(pRsp->hash, NULL);
|
||||
while (pIter != NULL) {
|
||||
SAnalyticsUrl *pUrl = pIter;
|
||||
size_t nameLen = 0;
|
||||
const char *name = taosHashGetKey(pIter, &nameLen);
|
||||
SAnalyticsUrl *pUrl = pIter;
|
||||
size_t nameLen = 0;
|
||||
const char *name = taosHashGetKey(pIter, &nameLen);
|
||||
if (nameLen > 0 && pUrl->urlLen > 0) {
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, nameLen));
|
||||
TAOS_CHECK_EXIT(tEncodeBinary(&encoder, (const uint8_t *)name, nameLen));
|
||||
|
@ -2221,10 +2221,10 @@ int32_t tDeserializeRetrieveAnalAlgoRsp(void *buf, int32_t bufLen, SRetrieveAnal
|
|||
int32_t lino;
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
int32_t numOfAlgos = 0;
|
||||
int32_t nameLen;
|
||||
int32_t type;
|
||||
char name[TSDB_ANALYTIC_ALGO_KEY_LEN];
|
||||
int32_t numOfAlgos = 0;
|
||||
int32_t nameLen;
|
||||
int32_t type;
|
||||
char name[TSDB_ANALYTIC_ALGO_KEY_LEN];
|
||||
SAnalyticsUrl url = {0};
|
||||
|
||||
TAOS_CHECK_EXIT(tStartDecode(&decoder));
|
||||
|
@ -10511,6 +10511,20 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) {
|
|||
TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pReq->pTagVal, pReq->nTagVal));
|
||||
}
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL:
|
||||
int32_t nTags = taosArrayGetSize(pReq->pMultiTag);
|
||||
TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, nTags));
|
||||
for (int32_t i = 0; i < nTags; i++) {
|
||||
SMultiTagUpateVal *pTag = taosArrayGet(pReq->pMultiTag, i);
|
||||
TAOS_CHECK_EXIT(tEncodeI32v(pEncoder, pTag->colId));
|
||||
TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTag->tagName));
|
||||
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->isNull));
|
||||
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTag->tagType));
|
||||
if (!pTag->isNull) {
|
||||
TAOS_CHECK_EXIT(tEncodeBinary(pEncoder, pTag->pTagVal, pReq->nTagVal));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
|
||||
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->updateTTL));
|
||||
if (pReq->updateTTL) {
|
||||
|
@ -10577,6 +10591,27 @@ static int32_t tDecodeSVAlterTbReqCommon(SDecoder *pDecoder, SVAlterTbReq *pReq)
|
|||
TAOS_CHECK_EXIT(tDecodeBinary(pDecoder, &pReq->pTagVal, &pReq->nTagVal));
|
||||
}
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL:
|
||||
int32_t nTags;
|
||||
TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &nTags));
|
||||
pReq->pMultiTag = taosArrayInit(nTags, sizeof(SMultiTagUpateVal));
|
||||
if (pReq->pMultiTag == NULL) {
|
||||
TAOS_CHECK_EXIT(terrno);
|
||||
}
|
||||
for (int32_t i = 0; i < nTags; i++) {
|
||||
SMultiTagUpateVal tag;
|
||||
TAOS_CHECK_EXIT(tDecodeI32v(pDecoder, &tag.colId));
|
||||
TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &tag.tagName));
|
||||
TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &tag.isNull));
|
||||
TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &tag.tagType));
|
||||
if (!tag.isNull) {
|
||||
TAOS_CHECK_EXIT(tDecodeBinary(pDecoder, &tag.pTagVal, &tag.nTagVal));
|
||||
}
|
||||
if (taosArrayPush(pReq->pMultiTag, &tag) == NULL) {
|
||||
TAOS_CHECK_EXIT(terrno);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
|
||||
TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pReq->updateTTL));
|
||||
if (pReq->updateTTL) {
|
||||
|
|
|
@ -2011,6 +2011,7 @@ _err:
|
|||
return terrno != 0 ? terrno : TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { return 0; }
|
||||
static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||
SMetaEntry ctbEntry = {0};
|
||||
SMetaEntry stbEntry = {0};
|
||||
|
@ -2736,6 +2737,9 @@ int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMeta
|
|||
return metaAlterTableColumn(pMeta, version, pReq, pMetaRsp);
|
||||
case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:
|
||||
return metaUpdateTableTagVal(pMeta, version, pReq);
|
||||
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL:
|
||||
return metaUpdateTableMultiTagVal(pMeta, version, pReq);
|
||||
return terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION;
|
||||
case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
|
||||
return metaUpdateTableOptions(pMeta, version, pReq);
|
||||
case TSDB_ALTER_TABLE_ADD_TAG_INDEX:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -165,6 +165,7 @@ SNode* createInterpTimeRange(SAstCreateContext* pCxt, SNode* pStart, SNode*
|
|||
SNode* createInterpTimePoint(SAstCreateContext* pCxt, SNode* pPoint);
|
||||
SNode* createWhenThenNode(SAstCreateContext* pCxt, SNode* pWhen, SNode* pThen);
|
||||
SNode* createCaseWhenNode(SAstCreateContext* pCxt, SNode* pCase, SNodeList* pWhenThenList, SNode* pElse);
|
||||
SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* token, SNode* pVal);
|
||||
|
||||
SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere);
|
||||
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList);
|
||||
|
@ -228,6 +229,7 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
|
|||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
|
||||
SToken* pNewColName);
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal);
|
||||
SNode* createAlterTableSetMultiTagValue(SAstCreateContext* pCxt, SNode* pRealTable, SNodeList* singleNode);
|
||||
SNode* setAlterSuperTableType(SNode* pStmt);
|
||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName);
|
||||
SNode* setShowKind(SAstCreateContext* pCxt, SNode* pStmt, EShowKind showKind);
|
||||
|
|
|
@ -370,6 +370,7 @@ cmd ::= DROP STABLE with_opt(A) exists_opt(B) full_table_name(C).
|
|||
cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; }
|
||||
cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = setAlterSuperTableType(A); }
|
||||
|
||||
|
||||
alter_table_clause(A) ::= full_table_name(B) alter_table_options(C). { A = createAlterTableModifyOptions(pCxt, B, C); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) ADD COLUMN column_name(C) type_name(D) column_options(E). { A = createAlterTableAddModifyColOptions2(pCxt, B, TSDB_ALTER_TABLE_ADD_COLUMN, &C, D, E); }
|
||||
|
@ -387,8 +388,16 @@ alter_table_clause(A) ::=
|
|||
full_table_name(B) MODIFY TAG column_name(C) type_name(D). { A = createAlterTableAddModifyCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &C, D); }
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) RENAME TAG column_name(C) column_name(D). { A = createAlterTableRenameCol(pCxt, B, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &C, &D); }
|
||||
|
||||
|
||||
%type column_eq_value_list { SNodeList* }
|
||||
%destructor column_eq_value_list { nodesDestroyList($$); }
|
||||
column_eq_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); }
|
||||
column_eq_value_list(A) ::= column_eq_value(B). { A = createNodeList(pCxt, B); }
|
||||
column_eq_value_list(A) ::= column_eq_value_list(B) NK_COMMA column_eq_value(C). { A = addNodeToList(pCxt, B, C);}
|
||||
|
||||
alter_table_clause(A) ::=
|
||||
full_table_name(B) SET TAG column_name(C) NK_EQ tags_literal(D). { A = createAlterTableSetTag(pCxt, B, &C, D); }
|
||||
full_table_name(B) SET TAG column_eq_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); }
|
||||
|
||||
%type multi_create_clause { SNodeList* }
|
||||
%destructor multi_create_clause { nodesDestroyList($$); }
|
||||
|
|
|
@ -1976,7 +1976,7 @@ static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, ED
|
|||
case DB_OPTION_S3_COMPACT:
|
||||
pDbOptions->s3Compact = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
|
||||
break;
|
||||
case DB_OPTION_KEEP_TIME_OFFSET:
|
||||
case DB_OPTION_KEEP_TIME_OFFSET:
|
||||
pDbOptions->keepTimeOffset = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
|
||||
break;
|
||||
case DB_OPTION_ENCRYPT_ALGORITHM:
|
||||
|
@ -2427,6 +2427,12 @@ static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* p
|
|||
nodesDestroyNode(pRealTable);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
static SNode* createAlterTableMultiStmtFinalize(SNode* pRealTable, SAlterTableMultiStmt* pStmt) {
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
|
||||
nodesDestroyNode(pRealTable);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
|
@ -2541,6 +2547,19 @@ _err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SNode* createAlterSingleTagColumnNode(SAstCreateContext* pCtx, SToken* pTagName, SNode* pVal) {
|
||||
CHECK_PARSER_STATUS(pCtx);
|
||||
SAlterTableStmt* pStmt = NULL;
|
||||
pCtx->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
|
||||
CHECK_MAKE_NODE(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
|
||||
COPY_STRING_FORM_ID_TOKEN(pStmt->colName, pTagName);
|
||||
pStmt->pVal = (SValueNode*)pVal;
|
||||
return (SNode*)pStmt;
|
||||
_err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
CHECK_NAME(checkColumnName(pCxt, pTagName));
|
||||
|
@ -2557,6 +2576,19 @@ _err:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SNode* createAlterTableSetMultiTagValue(SAstCreateContext* pCxt, SNode* pRealTable, SNodeList* pList) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SAlterTableStmt* pStmt = NULL;
|
||||
pCxt->errCode = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT, (SNode**)&pStmt);
|
||||
|
||||
CHECK_MAKE_NODE(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL;
|
||||
pStmt->pNodeListTagValue = pList;
|
||||
return createAlterTableStmtFinalize(pRealTable, pStmt);
|
||||
_err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SNode* setAlterSuperTableType(SNode* pStmt) {
|
||||
if (!pStmt) return NULL;
|
||||
setNodeType(pStmt, QUERY_NODE_ALTER_SUPER_TABLE_STMT);
|
||||
|
|
|
@ -46,7 +46,7 @@ int32_t buildQueryAfterParse(SQuery** pQuery, SNode* pRootNode, int16_t placehol
|
|||
int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
|
||||
SAstCreateContext cxt;
|
||||
initAstCreateContext(pParseCxt, &cxt);
|
||||
void* pParser = ParseAlloc((FMalloc)taosMemoryMalloc);
|
||||
void* pParser = ParseAlloc((FMalloc)taosMemoryMalloc);
|
||||
if (!pParser) return terrno;
|
||||
int32_t i = 0;
|
||||
while (1) {
|
||||
|
@ -210,15 +210,15 @@ static int32_t isTbnameEqCondOperator(SOperatorNode* pOperator, char** ppTableNa
|
|||
if (pOperator->opType != OP_TYPE_EQUAL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SValueNode* pValueNode = NULL;
|
||||
|
||||
SValueNode* pValueNode = NULL;
|
||||
if (nodeType(pOperator->pLeft) == QUERY_NODE_FUNCTION &&
|
||||
0 == strcasecmp(((SFunctionNode*)(pOperator->pLeft))->functionName, "tbname") &&
|
||||
nodeType(pOperator->pRight) == QUERY_NODE_VALUE) {
|
||||
pValueNode = (SValueNode*)pOperator->pRight;
|
||||
} else if (nodeType(pOperator->pRight) == QUERY_NODE_FUNCTION &&
|
||||
0 == strcasecmp(((SFunctionNode*)(pOperator->pRight))->functionName, "tbname") &&
|
||||
nodeType(pOperator->pLeft) == QUERY_NODE_VALUE) {
|
||||
0 == strcasecmp(((SFunctionNode*)(pOperator->pRight))->functionName, "tbname") &&
|
||||
nodeType(pOperator->pLeft) == QUERY_NODE_VALUE) {
|
||||
pValueNode = (SValueNode*)pOperator->pLeft;
|
||||
} else {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -233,13 +233,14 @@ static EDealRes collectMetaKeyFromOperator(SCollectMetaKeyFromExprCxt* pCxt, SOp
|
|||
if (!pCxt->tbnameCollect) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
char* pTableName = NULL;
|
||||
int32_t code = isTbnameEqCondOperator((SOperatorNode*)pOpNode, &pTableName);
|
||||
if (TSDB_CODE_SUCCESS != code) return DEAL_RES_CONTINUE;
|
||||
if (pTableName) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pComCxt->pStmt;
|
||||
pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, ((SRealTableNode*)pSelect->pFromTable)->table.dbName, pTableName, AUTH_TYPE_READ);
|
||||
pCxt->errCode = collectMetaKeyFromRealTableImpl(pCxt->pComCxt, ((SRealTableNode*)pSelect->pFromTable)->table.dbName,
|
||||
pTableName, AUTH_TYPE_READ);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
|
@ -500,7 +501,7 @@ static int32_t collectMetaKeyFromCreateStream(SCollectMetaKeyCxt* pCxt, SCreateS
|
|||
reserveTableMetaInCache(pCxt->pParseCxt->acctId, pStmt->targetDbName, pStmt->targetTabName, pCxt->pMetaCache);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pSubtable && NULL != pStmt->pQuery) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pStmt->pQuery;
|
||||
int32_t code = nodesCloneNode(pStmt->pSubtable, &pSelect->pSubtable);
|
||||
int32_t code = nodesCloneNode(pStmt->pSubtable, &pSelect->pSubtable);
|
||||
if (NULL == pSelect->pSubtable) {
|
||||
return code;
|
||||
}
|
||||
|
@ -969,6 +970,7 @@ static int32_t collectMetaKeyFromQuery(SCollectMetaKeyCxt* pCxt, SNode* pStmt) {
|
|||
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||
return collectMetaKeyFromDropStable(pCxt, (SDropSuperTableStmt*)pStmt);
|
||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||
case QUERY_NODE_ALTER_TABLE_MULTI_STMT:
|
||||
return collectMetaKeyFromAlterTable(pCxt, (SAlterTableStmt*)pStmt);
|
||||
case QUERY_NODE_ALTER_SUPER_TABLE_STMT:
|
||||
return collectMetaKeyFromAlterStable(pCxt, (SAlterTableStmt*)pStmt);
|
||||
|
|
|
@ -97,6 +97,7 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
|||
.showType = QUERY_NODE_SHOW_DNODES_STMT,
|
||||
.pDbName = TSDB_INFORMATION_SCHEMA_DB,
|
||||
.pTableName = TSDB_INS_TABLE_DNODES,
|
||||
|
||||
.numOfShowCols = 1,
|
||||
.pShowCols = {"*"}
|
||||
},
|
||||
|
@ -1853,7 +1854,7 @@ static bool clauseSupportAlias(ESqlClause clause) {
|
|||
return SQL_CLAUSE_GROUP_BY == clause || SQL_CLAUSE_PARTITION_BY == clause || SQL_CLAUSE_ORDER_BY == clause;
|
||||
}
|
||||
|
||||
static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnNode** pCol, bool *translateAsAlias) {
|
||||
static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnNode** pCol, bool* translateAsAlias) {
|
||||
*translateAsAlias = false;
|
||||
// count(*)/first(*)/last(*) and so on
|
||||
if (0 == strcmp((*pCol)->colName, "*")) {
|
||||
|
@ -1862,7 +1863,7 @@ static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnN
|
|||
|
||||
if (pCxt->pParseCxt->biMode) {
|
||||
SNode** ppNode = (SNode**)pCol;
|
||||
bool ret;
|
||||
bool ret;
|
||||
pCxt->errCode = biRewriteToTbnameFunc(pCxt, ppNode, &ret);
|
||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) return DEAL_RES_ERROR;
|
||||
if (ret) {
|
||||
|
@ -1876,9 +1877,8 @@ static EDealRes translateColumnInGroupByClause(STranslateContext* pCxt, SColumnN
|
|||
} else {
|
||||
bool found = false;
|
||||
res = translateColumnWithoutPrefix(pCxt, pCol);
|
||||
if (!(*pCol)->node.asParam &&
|
||||
res != DEAL_RES_CONTINUE &&
|
||||
res != DEAL_RES_END && pCxt->errCode != TSDB_CODE_PAR_AMBIGUOUS_COLUMN) {
|
||||
if (!(*pCol)->node.asParam && res != DEAL_RES_CONTINUE && res != DEAL_RES_END &&
|
||||
pCxt->errCode != TSDB_CODE_PAR_AMBIGUOUS_COLUMN) {
|
||||
res = translateColumnUseAlias(pCxt, pCol, &found);
|
||||
*translateAsAlias = true;
|
||||
}
|
||||
|
@ -3321,9 +3321,11 @@ static int32_t selectCommonType(SDataType* commonType, const SDataType* newType)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if ((resultType == TSDB_DATA_TYPE_VARCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
|
||||
if ((resultType == TSDB_DATA_TYPE_VARCHAR) &&
|
||||
(IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN);
|
||||
} else if ((resultType == TSDB_DATA_TYPE_NCHAR) && (IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
|
||||
} else if ((resultType == TSDB_DATA_TYPE_NCHAR) &&
|
||||
(IS_MATHABLE_TYPE(commonType->type) || IS_MATHABLE_TYPE(newType->type))) {
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), QUERY_NUMBER_MAX_DISPLAY_LEN * TSDB_NCHAR_SIZE);
|
||||
} else {
|
||||
commonType->bytes = TMAX(TMAX(commonType->bytes, newType->bytes), TYPE_BYTES[resultType]);
|
||||
|
@ -5480,7 +5482,7 @@ static EDealRes translateGroupPartitionByImpl(SNode** pNode, void* pContext) {
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
STranslateContext* pTransCxt = pCxt->pTranslateCxt;
|
||||
if (QUERY_NODE_VALUE == nodeType(*pNode)) {
|
||||
SValueNode* pVal = (SValueNode*) *pNode;
|
||||
SValueNode* pVal = (SValueNode*)*pNode;
|
||||
if (DEAL_RES_ERROR == translateValue(pTransCxt, pVal)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -5528,8 +5530,7 @@ static int32_t translateGroupByList(STranslateContext* pCxt, SSelectStmt* pSelec
|
|||
if (NULL == pSelect->pGroupByList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SReplaceGroupByAliasCxt cxt = {
|
||||
.pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList};
|
||||
SReplaceGroupByAliasCxt cxt = {.pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList};
|
||||
nodesRewriteExprsPostOrder(pSelect->pGroupByList, translateGroupPartitionByImpl, &cxt);
|
||||
|
||||
return pCxt->errCode;
|
||||
|
@ -5540,8 +5541,7 @@ static int32_t translatePartitionByList(STranslateContext* pCxt, SSelectStmt* pS
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SReplaceGroupByAliasCxt cxt = {
|
||||
.pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList};
|
||||
SReplaceGroupByAliasCxt cxt = {.pTranslateCxt = pCxt, .pProjectionList = pSelect->pProjectionList};
|
||||
nodesRewriteExprsPostOrder(pSelect->pPartitionByList, translateGroupPartitionByImpl, &cxt);
|
||||
|
||||
return pCxt->errCode;
|
||||
|
@ -9495,7 +9495,8 @@ static int32_t checkAlterSuperTableBySchema(STranslateContext* pCxt, SAlterTable
|
|||
}
|
||||
|
||||
static int32_t checkAlterSuperTable(STranslateContext* pCxt, SAlterTableStmt* pStmt) {
|
||||
if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == pStmt->alterType) {
|
||||
if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == pStmt->alterType ||
|
||||
TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL == pStmt->alterType) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE,
|
||||
"Set tag value only available for child table");
|
||||
}
|
||||
|
@ -10521,7 +10522,8 @@ static void getSourceDatabase(SNode* pStmt, int32_t acctId, char* pDbFName) {
|
|||
(void)tNameGetFullDbName(&name, pDbFName);
|
||||
}
|
||||
|
||||
static void getStreamQueryFirstProjectAliasName(SHashObj* pUserAliasSet, char* aliasName, int32_t len, char* defaultName[]) {
|
||||
static void getStreamQueryFirstProjectAliasName(SHashObj* pUserAliasSet, char* aliasName, int32_t len,
|
||||
char* defaultName[]) {
|
||||
for (int32_t i = 0; defaultName[i] != NULL; i++) {
|
||||
if (NULL == taosHashGet(pUserAliasSet, defaultName[i], strlen(defaultName[i]))) {
|
||||
snprintf(aliasName, len, "%s", defaultName[i]);
|
||||
|
@ -10547,8 +10549,8 @@ static int32_t setColumnDefNodePrimaryKey(SColumnDefNode* pNode, bool isPk) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t addIrowTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSelectStmt* pSelect,
|
||||
SHashObj* pUserAliasSet, SNodeList* pCols, SCMCreateStreamReq* pReq) {
|
||||
static int32_t addIrowTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSelectStmt* pSelect, SHashObj* pUserAliasSet,
|
||||
SNodeList* pCols, SCMCreateStreamReq* pReq) {
|
||||
SNode* pProj = nodesListGetNode(pSelect->pProjectionList, 0);
|
||||
if (!pSelect->hasInterpFunc ||
|
||||
(QUERY_NODE_FUNCTION == nodeType(pProj) && 0 == strcmp("_irowts", ((SFunctionNode*)pProj)->functionName))) {
|
||||
|
@ -10595,7 +10597,7 @@ static int32_t addWstartTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSele
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
SFunctionNode* pFunc = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
|
||||
if (NULL == pFunc) {
|
||||
return code;
|
||||
}
|
||||
|
@ -10627,7 +10629,7 @@ static int32_t addWstartTsToCreateStreamQueryImpl(STranslateContext* pCxt, SSele
|
|||
}
|
||||
|
||||
static int32_t addTsKeyToCreateStreamQuery(STranslateContext* pCxt, SNode* pStmt, SNodeList* pCols,
|
||||
SCMCreateStreamReq* pReq) {
|
||||
SCMCreateStreamReq* pReq) {
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pStmt;
|
||||
SHashObj* pUserAliasSet = NULL;
|
||||
int32_t code = checkProjectAlias(pCxt, pSelect->pProjectionList, &pUserAliasSet);
|
||||
|
@ -10990,21 +10992,18 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm
|
|||
|
||||
if (pStmt->pOptions->triggerType == STREAM_TRIGGER_FORCE_WINDOW_CLOSE) {
|
||||
if (pStmt->pOptions->fillHistory) {
|
||||
return generateSyntaxErrMsgExt(
|
||||
&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"When trigger was force window close, Stream unsupported Fill history");
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"When trigger was force window close, Stream unsupported Fill history");
|
||||
}
|
||||
|
||||
if (pStmt->pOptions->ignoreExpired != 1) {
|
||||
return generateSyntaxErrMsgExt(
|
||||
&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"When trigger was force window close, Stream must not set ignore expired 0");
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"When trigger was force window close, Stream must not set ignore expired 0");
|
||||
}
|
||||
|
||||
if (pStmt->pOptions->ignoreUpdate != 1) {
|
||||
return generateSyntaxErrMsgExt(
|
||||
&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"When trigger was force window close, Stream must not set ignore update 0");
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||
"When trigger was force window close, Stream must not set ignore update 0");
|
||||
}
|
||||
|
||||
if (pSelect->pWindow != NULL && QUERY_NODE_INTERVAL_WINDOW == nodeType(pSelect->pWindow)) {
|
||||
|
@ -13127,7 +13126,7 @@ static int32_t extractShowCreateViewResultSchema(int32_t* numOfCols, SSchema** p
|
|||
}
|
||||
|
||||
static int32_t extractShowVariablesResultSchema(int32_t* numOfCols, SSchema** pSchema) {
|
||||
*numOfCols = SHOW_LOCAL_VARIABLES_RESULT_COLS; // SHOW_VARIABLES_RESULT_COLS
|
||||
*numOfCols = SHOW_LOCAL_VARIABLES_RESULT_COLS; // SHOW_VARIABLES_RESULT_COLS
|
||||
*pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema));
|
||||
if (NULL == (*pSchema)) {
|
||||
return terrno;
|
||||
|
@ -15183,24 +15182,90 @@ static int32_t rewriteDropSuperTable(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
TAOS_RETURN(0);
|
||||
}
|
||||
|
||||
static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
SVAlterTbReq* pReq) {
|
||||
SName tbName = {0};
|
||||
SArray* pTsmas = NULL;
|
||||
static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
char* colName, SMultiTagUpateVal* pReq) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (pCxt->pMetaCache) {
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName);
|
||||
code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
if (pTsmas && pTsmas->size > 0) return TSDB_CODE_TSMA_MUST_BE_DROPPED;
|
||||
if (NULL == pReq->tagName) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SSchema* pSchema = getTagSchema(pTableMeta, pStmt->colName);
|
||||
SSchema* pSchema = getTagSchema(pTableMeta, colName);
|
||||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s",
|
||||
pStmt->colName);
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName);
|
||||
}
|
||||
pReq->tagName = taosStrdup(pStmt->colName);
|
||||
|
||||
pReq->tagName = taosStrdup(colName);
|
||||
if (NULL == pReq->tagName) {
|
||||
return terrno;
|
||||
}
|
||||
pReq->pTagArray = taosArrayInit(1, sizeof(STagVal));
|
||||
if (NULL == pReq->pTagArray) {
|
||||
return terrno;
|
||||
}
|
||||
pReq->colId = pSchema->colId;
|
||||
pReq->tagType = pSchema->type;
|
||||
|
||||
STag* pTag = NULL;
|
||||
SToken token;
|
||||
char tokenBuf[TSDB_MAX_TAGS_LEN];
|
||||
const char* tagStr = pStmt->pVal->literal;
|
||||
NEXT_TOKEN_WITH_PREV(tagStr, token);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkAndTrimValue(&token, tokenBuf, &pCxt->msgBuf, pSchema->type);
|
||||
if (TSDB_CODE_SUCCESS == code && TK_NK_VARIABLE == token.type) {
|
||||
code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values", token.z);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = parseTagValue(&pCxt->msgBuf, &tagStr, pTableMeta->tableInfo.precision, pSchema, &token, NULL,
|
||||
pReq->pTagArray, &pTag);
|
||||
if (pSchema->type == TSDB_DATA_TYPE_JSON && token.type == TK_NULL && code == TSDB_CODE_SUCCESS) {
|
||||
pReq->tagFree = true;
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && tagStr) {
|
||||
NEXT_VALID_TOKEN(tagStr, token);
|
||||
if (token.n != 0) {
|
||||
code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values", token.z);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||
code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values ", token.z);
|
||||
} else {
|
||||
STagVal* pTagVal = taosArrayGet(pReq->pTagArray, 0);
|
||||
if (pTagVal) {
|
||||
pReq->isNull = false;
|
||||
if (IS_VAR_DATA_TYPE(pSchema->type)) {
|
||||
pReq->nTagVal = pTagVal->nData;
|
||||
pReq->pTagVal = pTagVal->pData;
|
||||
} else {
|
||||
pReq->nTagVal = pSchema->bytes;
|
||||
pReq->pTagVal = (uint8_t*)&pTagVal->i64;
|
||||
}
|
||||
} else {
|
||||
pReq->isNull = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
static int32_t buildUpdateTagValReqImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
char* colName, SVAlterTbReq* pReq) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
// if (NULL == pReq->tagName) {
|
||||
// return terrno;
|
||||
// }
|
||||
|
||||
SSchema* pSchema = getTagSchema(pTableMeta, colName);
|
||||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName);
|
||||
}
|
||||
|
||||
pReq->tagName = taosStrdup(colName);
|
||||
if (NULL == pReq->tagName) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -15261,6 +15326,62 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
|
|||
|
||||
return code;
|
||||
}
|
||||
static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
SVAlterTbReq* pReq) {
|
||||
SName tbName = {0};
|
||||
SArray* pTsmas = NULL;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (pCxt->pMetaCache) {
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName);
|
||||
code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
if (pTsmas && pTsmas->size > 0) return TSDB_CODE_TSMA_MUST_BE_DROPPED;
|
||||
}
|
||||
return buildUpdateTagValReqImpl(pCxt, pStmt, pTableMeta, pStmt->colName, pReq);
|
||||
}
|
||||
|
||||
static int32_t buildUpdateMultiTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
SVAlterTbReq* pReq) {
|
||||
SName tbName = {0};
|
||||
SArray* pTsmas = NULL;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (pCxt->pMetaCache) {
|
||||
toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tbName);
|
||||
code = getTableTsmasFromCache(pCxt->pMetaCache, &tbName, &pTsmas);
|
||||
if (code != TSDB_CODE_SUCCESS) return code;
|
||||
if (pTsmas && pTsmas->size > 0) return TSDB_CODE_TSMA_MUST_BE_DROPPED;
|
||||
}
|
||||
SNodeList* pNodeList = pStmt->pNodeListTagValue;
|
||||
if (pNodeList == NULL) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||
}
|
||||
|
||||
int32_t nTagValues = pNodeList->length;
|
||||
if (nTagValues == 1) {
|
||||
SAlterTableStmt* head = (SAlterTableStmt*)pNodeList->pHead->pNode;
|
||||
pReq->action = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
|
||||
return buildUpdateTagValReqImpl(pCxt, head, pTableMeta, head->colName, pReq);
|
||||
} else {
|
||||
pReq->pMultiTag = taosArrayInit(nTagValues, sizeof(SMultiTagUpateVal));
|
||||
if (NULL == pReq->pTagArray) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
SAlterTableStmt* pTagStmt = NULL;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pNodeList) {
|
||||
SMultiTagUpateVal val;
|
||||
pTagStmt = (SAlterTableStmt*)pNode;
|
||||
code = buildUpdateTagValReqImpl2(pCxt, pTagStmt, pTableMeta, pTagStmt->colName, &val);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
TAOS_UNUSED(taosArrayPush(pReq->pMultiTag, &val));
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
SVAlterTbReq* pReq) {
|
||||
|
@ -15449,6 +15570,8 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt,
|
|||
case TSDB_ALTER_TABLE_UPDATE_TAG_NAME:
|
||||
case TSDB_ALTER_TABLE_UPDATE_TAG_BYTES:
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE);
|
||||
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL:
|
||||
return buildUpdateMultiTagValReq(pCxt, pStmt, pTableMeta, pReq);
|
||||
case TSDB_ALTER_TABLE_UPDATE_TAG_VAL:
|
||||
return buildUpdateTagValReq(pCxt, pStmt, pTableMeta, pReq);
|
||||
case TSDB_ALTER_TABLE_ADD_COLUMN:
|
||||
|
@ -16254,6 +16377,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||
code = rewriteDropSuperTable(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_TABLE_MULTI_STMT:
|
||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||
code = rewriteAlterTable(pCxt, pQuery);
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue