Merge pull request #28925 from taosdata/feat/updateMultiTag
Feat/updateMultiTag
This commit is contained in:
commit
ab604c18f9
|
@ -169,7 +169,7 @@ ALTER TABLE [db_name.]tb_name alter_table_clause
|
|||
|
||||
alter_table_clause: {
|
||||
alter_table_options
|
||||
| SET TAG tag_name = new_tag_value
|
||||
| SET TAG tag_name = new_tag_value,tag_name2=new_tag2_value...
|
||||
}
|
||||
|
||||
alter_table_options:
|
||||
|
|
|
@ -171,7 +171,7 @@ ALTER TABLE [db_name.]tb_name alter_table_clause
|
|||
|
||||
alter_table_clause: {
|
||||
alter_table_options
|
||||
| SET TAG tag_name = new_tag_value
|
||||
| SET TAG tag_name = new_tag_value,tag_name2=new_tag2_value...
|
||||
}
|
||||
|
||||
alter_table_options:
|
||||
|
|
|
@ -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
|
||||
|
@ -421,7 +422,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 +436,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 +986,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 +3259,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,14 +3295,16 @@ 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);
|
||||
int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq);
|
||||
int32_t tDecodeSVAlterTbReqSetCtime(SDecoder* pDecoder, SVAlterTbReq* pReq, int64_t ctimeMs);
|
||||
void tfreeMultiTagUpateVal(void* pMultiTag);
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
|
@ -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,18 @@ typedef struct SAlterTableStmt {
|
|||
SDataType dataType;
|
||||
SValueNode* pVal;
|
||||
SColumnOptions* pColOptions;
|
||||
SNodeList* pNodeListTagValue;
|
||||
} SAlterTableStmt;
|
||||
|
||||
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 +351,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 +661,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 +670,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
|
||||
|
|
|
@ -620,7 +620,10 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
|
|||
cJSON* type = cJSON_CreateString("alter");
|
||||
RAW_NULL_CHECK(type);
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "type", type));
|
||||
cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ? "child" : "normal");
|
||||
cJSON* tableType = cJSON_CreateString(vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_TAG_VAL ||
|
||||
vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL
|
||||
? "child"
|
||||
: "normal");
|
||||
RAW_NULL_CHECK(tableType);
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableType", tableType));
|
||||
cJSON* tableName = cJSON_CreateString(vAlterTbReq.tbName);
|
||||
|
@ -762,6 +765,58 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
|
|||
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "colValueNull", isNullCJson));
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL: {
|
||||
int32_t nTags = taosArrayGetSize(vAlterTbReq.pMultiTag);
|
||||
if (nTags <= 0) {
|
||||
uError("processAlterTable parse multi tags error");
|
||||
goto end;
|
||||
}
|
||||
|
||||
cJSON* tags = cJSON_CreateArray();
|
||||
RAW_NULL_CHECK(tags);
|
||||
for (int32_t i = 0; i < nTags; i++) {
|
||||
cJSON* member = cJSON_CreateObject();
|
||||
RAW_NULL_CHECK(member);
|
||||
|
||||
SMultiTagUpateVal* pTagVal = taosArrayGet(vAlterTbReq.pMultiTag, i);
|
||||
cJSON* tagName = cJSON_CreateString(pTagVal->tagName);
|
||||
RAW_NULL_CHECK(tagName);
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colName", tagName));
|
||||
|
||||
if (pTagVal->tagType == TSDB_DATA_TYPE_JSON) {
|
||||
uError("processAlterTable isJson false");
|
||||
goto end;
|
||||
}
|
||||
bool isNull = pTagVal->isNull;
|
||||
if (!isNull) {
|
||||
char* buf = NULL;
|
||||
int64_t bufSize = 0;
|
||||
if (pTagVal->tagType == TSDB_DATA_TYPE_VARBINARY) {
|
||||
bufSize = pTagVal->nTagVal * 2 + 2 + 3;
|
||||
} else {
|
||||
bufSize = pTagVal->nTagVal + 3;
|
||||
}
|
||||
buf = taosMemoryCalloc(bufSize, 1);
|
||||
RAW_NULL_CHECK(buf);
|
||||
if (dataConverToStr(buf, bufSize, pTagVal->tagType, pTagVal->pTagVal, pTagVal->nTagVal, NULL) !=
|
||||
TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(buf);
|
||||
goto end;
|
||||
}
|
||||
cJSON* colValue = cJSON_CreateString(buf);
|
||||
RAW_NULL_CHECK(colValue);
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValue", colValue));
|
||||
taosMemoryFree(buf);
|
||||
}
|
||||
cJSON* isNullCJson = cJSON_CreateBool(isNull);
|
||||
RAW_NULL_CHECK(isNullCJson);
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToObject(member, "colValueNull", isNullCJson));
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToArray(tags, member));
|
||||
}
|
||||
RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tags", tags));
|
||||
break;
|
||||
}
|
||||
|
||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS: {
|
||||
cJSON* colName = cJSON_CreateString(vAlterTbReq.colName);
|
||||
RAW_NULL_CHECK(colName);
|
||||
|
@ -775,6 +830,9 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) {
|
|||
|
||||
end:
|
||||
uDebug("alter table return");
|
||||
if (vAlterTbReq.action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
|
||||
taosArrayDestroy(vAlterTbReq.pMultiTag);
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
*pJson = json;
|
||||
}
|
||||
|
@ -1855,19 +1913,19 @@ end:
|
|||
typedef int32_t _raw_decode_func_(SDecoder* pDecoder, SMqDataRsp* pRsp);
|
||||
static int32_t decodeRawData(SDecoder* decoder, void* data, int32_t dataLen, _raw_decode_func_ func,
|
||||
SMqRspObj* rspObj) {
|
||||
int8_t dataVersion = *(int8_t*)data;
|
||||
if (dataVersion >= MQ_DATA_RSP_VERSION) {
|
||||
data = POINTER_SHIFT(data, sizeof(int8_t) + sizeof(int32_t));
|
||||
dataLen -= sizeof(int8_t) + sizeof(int32_t);
|
||||
int8_t dataVersion = *(int8_t*)data;
|
||||
if (dataVersion >= MQ_DATA_RSP_VERSION) {
|
||||
data = POINTER_SHIFT(data, sizeof(int8_t) + sizeof(int32_t));
|
||||
dataLen -= sizeof(int8_t) + sizeof(int32_t);
|
||||
}
|
||||
|
||||
rspObj->resIter = -1;
|
||||
tDecoderInit(decoder, data, dataLen);
|
||||
int32_t code = func(decoder, &rspObj->dataRsp);
|
||||
if (code != 0) {
|
||||
SET_ERROR_MSG("decode mq taosx data rsp failed");
|
||||
rspObj->resIter = -1;
|
||||
tDecoderInit(decoder, data, dataLen);
|
||||
int32_t code = func(decoder, &rspObj->dataRsp);
|
||||
if (code != 0) {
|
||||
SET_ERROR_MSG("decode mq taosx data rsp failed");
|
||||
}
|
||||
return code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t processCacheMeta(SHashObj* pVgHash, SHashObj* pNameHash, SHashObj* pMetaHash,
|
||||
|
@ -2195,44 +2253,44 @@ static int32_t getOffSetLen(const SMqDataRsp* pRsp) {
|
|||
|
||||
typedef int32_t __encode_func__(SEncoder* pEncoder, const SMqDataRsp* pRsp);
|
||||
static int32_t encodeMqDataRsp(__encode_func__* encodeFunc, SMqDataRsp* rspObj, tmq_raw_data* raw) {
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
SEncoder encoder = {0};
|
||||
void* buf = NULL;
|
||||
tEncodeSize(encodeFunc, rspObj, len, code);
|
||||
if (code < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
int32_t len = 0;
|
||||
int32_t code = 0;
|
||||
SEncoder encoder = {0};
|
||||
void* buf = NULL;
|
||||
tEncodeSize(encodeFunc, rspObj, len, code);
|
||||
if (code < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
}
|
||||
len += sizeof(int8_t) + sizeof(int32_t);
|
||||
buf = taosMemoryCalloc(1, len);
|
||||
if (buf == NULL) {
|
||||
code = terrno;
|
||||
goto FAILED;
|
||||
len += sizeof(int8_t) + sizeof(int32_t);
|
||||
buf = taosMemoryCalloc(1, len);
|
||||
if (buf == NULL) {
|
||||
code = terrno;
|
||||
goto FAILED;
|
||||
}
|
||||
tEncoderInit(&encoder, buf, len);
|
||||
if (tEncodeI8(&encoder, MQ_DATA_RSP_VERSION) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
tEncoderInit(&encoder, buf, len);
|
||||
if (tEncodeI8(&encoder, MQ_DATA_RSP_VERSION) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
}
|
||||
int32_t offsetLen = getOffSetLen(rspObj);
|
||||
if (offsetLen <= 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
int32_t offsetLen = getOffSetLen(rspObj);
|
||||
if (offsetLen <= 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
}
|
||||
if (tEncodeI32(&encoder, offsetLen) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
if (tEncodeI32(&encoder, offsetLen) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
}
|
||||
if (encodeFunc(&encoder, rspObj) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
if (encodeFunc(&encoder, rspObj) < 0) {
|
||||
code = TSDB_CODE_INVALID_MSG;
|
||||
goto FAILED;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
tEncoderClear(&encoder);
|
||||
|
||||
raw->raw = buf;
|
||||
raw->raw_len = len;
|
||||
return code;
|
||||
raw->raw = buf;
|
||||
raw->raw_len = len;
|
||||
return code;
|
||||
FAILED:
|
||||
tEncoderClear(&encoder);
|
||||
taosMemoryFree(buf);
|
||||
|
|
|
@ -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,21 @@ 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, pTag->nTagVal));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_ALTER_TABLE_UPDATE_OPTIONS:
|
||||
TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pReq->updateTTL));
|
||||
if (pReq->updateTTL) {
|
||||
|
@ -10577,6 +10592,28 @@ 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) {
|
||||
|
@ -10642,6 +10679,18 @@ _exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
void tfreeMultiTagUpateVal(void *val) {
|
||||
SMultiTagUpateVal *pTag = val;
|
||||
taosMemoryFree(pTag->tagName);
|
||||
for (int i = 0; i < taosArrayGetSize(pTag->pTagArray); ++i) {
|
||||
STagVal *p = (STagVal *)taosArrayGet(pTag->pTagArray, i);
|
||||
if (IS_VAR_DATA_TYPE(p->type)) {
|
||||
taosMemoryFreeClear(p->pData);
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTag->pTagArray);
|
||||
}
|
||||
int32_t tEncodeSVAlterTbRsp(SEncoder *pEncoder, const SVAlterTbRsp *pRsp) {
|
||||
int32_t code = 0;
|
||||
int32_t lino;
|
||||
|
|
|
@ -2011,6 +2011,255 @@ _err:
|
|||
return terrno != 0 ? terrno : TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int metaUpdateTableMultiTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||
SMetaEntry ctbEntry = {0};
|
||||
SMetaEntry stbEntry = {0};
|
||||
void *pVal = NULL;
|
||||
int nVal = 0;
|
||||
int ret;
|
||||
int c;
|
||||
tb_uid_t uid;
|
||||
int64_t oversion;
|
||||
const void *pData = NULL;
|
||||
int nData = 0;
|
||||
SHashObj *pTagTable = NULL;
|
||||
|
||||
// search name index
|
||||
ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal);
|
||||
if (ret < 0) {
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pVal;
|
||||
tdbFree(pVal);
|
||||
pVal = NULL;
|
||||
|
||||
// search uid index
|
||||
TBC *pUidIdxc = NULL;
|
||||
|
||||
TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL));
|
||||
if (tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c) < 0) {
|
||||
metaTrace("meta/table: failed to move to uid index, uid:%" PRId64, uid);
|
||||
}
|
||||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: failed to get uid index, uid:%" PRId64, uid);
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
||||
// search table.db
|
||||
TBC *pTbDbc = NULL;
|
||||
SDecoder dc1 = {0};
|
||||
SDecoder dc2 = {0};
|
||||
|
||||
/* get ctbEntry */
|
||||
TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL));
|
||||
if (tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c) != 0) {
|
||||
metaError("meta/table: failed to move to tb db, uid:%" PRId64, uid);
|
||||
}
|
||||
if (c != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c);
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) != 0) {
|
||||
metaError("meta/table: failed to get tb db, uid:%" PRId64, uid);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
|
||||
if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
return terrno;
|
||||
}
|
||||
memcpy(ctbEntry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc1, ctbEntry.pBuf, nData);
|
||||
ret = metaDecodeEntry(&dc1, &ctbEntry);
|
||||
if (ret < 0) {
|
||||
terrno = ret;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
/* get stbEntry*/
|
||||
if (tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal) != 0) {
|
||||
metaError("meta/table: failed to get uid index, uid:%" PRId64, ctbEntry.ctbEntry.suid);
|
||||
}
|
||||
if (!pVal) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}),
|
||||
sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal) != 0) {
|
||||
metaError("meta/table: failed to get tb db, uid:%" PRId64, ctbEntry.ctbEntry.suid);
|
||||
}
|
||||
tdbFree(pVal);
|
||||
tDecoderInit(&dc2, stbEntry.pBuf, nVal);
|
||||
ret = metaDecodeEntry(&dc2, &stbEntry);
|
||||
if (ret < 0) {
|
||||
terrno = ret;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
int32_t nTagVals = taosArrayGetSize(pAlterTbReq->pMultiTag);
|
||||
pTagTable = taosHashInit(nTagVals, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
if (pTagTable == NULL) {
|
||||
ret = terrno;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// remove duplicate tag name
|
||||
for (int i = 0; i < nTagVals; i++) {
|
||||
SMultiTagUpateVal *pTagVal = taosArrayGet(pAlterTbReq->pMultiTag, i);
|
||||
ret = taosHashPut(pTagTable, pTagVal->tagName, strlen(pTagVal->tagName), pTagVal, sizeof(*pTagVal));
|
||||
if (ret != 0) {
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
|
||||
SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
|
||||
SSchema *pColumn = NULL;
|
||||
int32_t iCol = 0;
|
||||
int32_t count = 0;
|
||||
|
||||
for (;;) {
|
||||
pColumn = NULL;
|
||||
|
||||
if (iCol >= pTagSchema->nCols) break;
|
||||
pColumn = &pTagSchema->pSchema[iCol];
|
||||
if (taosHashGet(pTagTable, pColumn->name, strlen(pColumn->name)) != NULL) {
|
||||
count++;
|
||||
}
|
||||
iCol++;
|
||||
}
|
||||
if (count != taosHashGetSize(pTagTable)) {
|
||||
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
ctbEntry.version = version;
|
||||
if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
|
||||
terrno = TSDB_CODE_VND_COL_NOT_EXISTS;
|
||||
goto _err;
|
||||
} else {
|
||||
const STag *pOldTag = (const STag *)ctbEntry.ctbEntry.pTags;
|
||||
STag *pNewTag = NULL;
|
||||
SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
|
||||
if (!pTagArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
for (int32_t i = 0; i < pTagSchema->nCols; i++) {
|
||||
SSchema *pCol = &pTagSchema->pSchema[i];
|
||||
SMultiTagUpateVal *pTagVal = taosHashGet(pTagTable, pCol->name, strlen(pCol->name));
|
||||
if (pTagVal == NULL) {
|
||||
STagVal val = {.cid = pCol->colId};
|
||||
if (tTagGet(pOldTag, &val)) {
|
||||
if (taosArrayPush(pTagArray, &val) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosArrayDestroy(pTagArray);
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
STagVal val = {0};
|
||||
val.type = pCol->type;
|
||||
val.cid = pCol->colId;
|
||||
if (pTagVal->isNull) continue;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
val.pData = pTagVal->pTagVal;
|
||||
val.nData = pTagVal->nTagVal;
|
||||
} else {
|
||||
memcpy(&val.i64, pTagVal->pTagVal, pTagVal->nTagVal);
|
||||
}
|
||||
if (taosArrayPush(pTagArray, &val) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosArrayDestroy(pTagArray);
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((terrno = tTagNew(pTagArray, pTagSchema->version, false, &pNewTag)) < 0) {
|
||||
taosArrayDestroy(pTagArray);
|
||||
goto _err;
|
||||
}
|
||||
ctbEntry.ctbEntry.pTags = (uint8_t *)pNewTag;
|
||||
taosArrayDestroy(pTagArray);
|
||||
}
|
||||
|
||||
metaWLock(pMeta);
|
||||
|
||||
// save to table.db
|
||||
if (metaSaveToTbDb(pMeta, &ctbEntry) < 0) {
|
||||
metaError("meta/table: failed to save to tb db:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
// save to uid.idx
|
||||
if (metaUpdateUidIdx(pMeta, &ctbEntry) < 0) {
|
||||
metaError("meta/table: failed to update uid idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
if (metaUpdateTagIdx(pMeta, &ctbEntry) < 0) {
|
||||
metaError("meta/table: failed to update tag idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
if (NULL == ctbEntry.ctbEntry.pTags) {
|
||||
metaError("meta/table: null tags, update tag val failed.");
|
||||
goto _err;
|
||||
}
|
||||
|
||||
SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid};
|
||||
if (tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags,
|
||||
((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn) < 0) {
|
||||
metaError("meta/table: failed to upsert ctb idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
if (metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid) < 0) {
|
||||
metaError("meta/table: failed to clear uid cache:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
if (metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid) < 0) {
|
||||
metaError("meta/table: failed to clear group cache:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
if (metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs) < 0) {
|
||||
metaError("meta/table: failed to update change time:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid);
|
||||
}
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
tDecoderClear(&dc1);
|
||||
tDecoderClear(&dc2);
|
||||
taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
|
||||
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
|
||||
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
|
||||
tdbTbcClose(pTbDbc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
taosHashCleanup(pTagTable);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tDecoderClear(&dc1);
|
||||
tDecoderClear(&dc2);
|
||||
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
|
||||
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
|
||||
tdbTbcClose(pTbDbc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
taosHashCleanup(pTagTable);
|
||||
return -1;
|
||||
}
|
||||
static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||
SMetaEntry ctbEntry = {0};
|
||||
SMetaEntry stbEntry = {0};
|
||||
|
@ -2051,7 +2300,9 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
}
|
||||
|
||||
if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) != 0) {
|
||||
tdbTbcClose(pUidIdxc);
|
||||
metaError("meta/table: failed to get uid index, uid:%" PRId64, uid);
|
||||
return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST;
|
||||
}
|
||||
oversion = ((SUidIdxVal *)pData)[0].version;
|
||||
|
||||
|
@ -2074,6 +2325,9 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
|
||||
if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) != 0) {
|
||||
metaError("meta/table: failed to get tb db, uid:%" PRId64, uid);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
return terrno = TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
|
||||
if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) {
|
||||
|
@ -2113,6 +2367,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag;
|
||||
SSchema *pColumn = NULL;
|
||||
int32_t iCol = 0;
|
||||
|
||||
for (;;) {
|
||||
pColumn = NULL;
|
||||
|
||||
|
@ -2736,6 +2991,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:
|
||||
|
|
|
@ -145,8 +145,12 @@ static int32_t vnodePreProcessAlterTableMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
SVAlterTbReq vAlterTbReq = {0};
|
||||
int64_t ctimeMs = taosGetTimestampMs();
|
||||
if (tDecodeSVAlterTbReqSetCtime(&dc, &vAlterTbReq, ctimeMs) < 0) {
|
||||
taosArrayDestroy(vAlterTbReq.pMultiTag);
|
||||
vAlterTbReq.pMultiTag = NULL;
|
||||
goto _exit;
|
||||
}
|
||||
taosArrayDestroy(vAlterTbReq.pMultiTag);
|
||||
vAlterTbReq.pMultiTag = NULL;
|
||||
|
||||
code = 0;
|
||||
|
||||
|
@ -666,10 +670,9 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
}
|
||||
} break;
|
||||
case TDMT_VND_STREAM_TASK_RESET: {
|
||||
if (pVnode->restored && vnodeIsLeader(pVnode) &&
|
||||
(code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
if (pVnode->restored && vnodeIsLeader(pVnode) && (code = tqProcessTaskResetReq(pVnode->pTq, pMsg)) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
} break;
|
||||
case TDMT_VND_ALTER_CONFIRM:
|
||||
|
@ -690,7 +693,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg
|
|||
case TDMT_VND_DROP_INDEX:
|
||||
vnodeProcessDropIndexReq(pVnode, ver, pReq, len, pRsp);
|
||||
break;
|
||||
case TDMT_VND_STREAM_CHECK_POINT_SOURCE: // always return true
|
||||
case TDMT_VND_STREAM_CHECK_POINT_SOURCE: // always return true
|
||||
tqProcessTaskCheckPointSourceReq(pVnode->pTq, pMsg, pRsp);
|
||||
break;
|
||||
case TDMT_VND_STREAM_TASK_UPDATE: // always return true
|
||||
|
@ -1367,6 +1370,7 @@ static int32_t vnodeProcessAlterTbReq(SVnode *pVnode, int64_t ver, void *pReq, i
|
|||
}
|
||||
|
||||
_exit:
|
||||
taosArrayDestroy(vAlterTbReq.pMultiTag);
|
||||
tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret);
|
||||
pRsp->pCont = rpcMallocCont(pRsp->contLen);
|
||||
tEncoderInit(&ec, pRsp->pCont, pRsp->contLen);
|
||||
|
|
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_tag_value_list { SNodeList* }
|
||||
%destructor column_tag_value_list { nodesDestroyList($$); }
|
||||
column_tag_value(A) ::= column_name(C) NK_EQ tags_literal(D). { A = createAlterSingleTagColumnNode(pCxt, &C, D); }
|
||||
column_tag_value_list(A) ::= column_tag_value(B). { A = createNodeList(pCxt, B); }
|
||||
column_tag_value_list(A) ::= column_tag_value_list(B) NK_COMMA column_tag_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_tag_value_list(C). { A = createAlterTableSetMultiTagValue(pCxt, B, C); }
|
||||
|
||||
%type multi_create_clause { SNodeList* }
|
||||
%destructor multi_create_clause { nodesDestroyList($$); }
|
||||
|
|
|
@ -2541,6 +2541,20 @@ _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;
|
||||
pStmt->pNodeListTagValue = NULL;
|
||||
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 +2571,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) {
|
||||
|
@ -211,14 +211,14 @@ static int32_t isTbnameEqCondOperator(SOperatorNode* pOperator, char** ppTableNa
|
|||
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;
|
||||
|
@ -239,7 +239,8 @@ static EDealRes collectMetaKeyFromOperator(SCollectMetaKeyFromExprCxt* pCxt, SOp
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -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,88 @@ 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;
|
||||
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;
|
||||
static int32_t buildUpdateTagValReqImpl2(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
char* colName, SMultiTagUpateVal* pReq) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SSchema* pSchema = getTagSchema(pTableMeta, colName);
|
||||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s", colName);
|
||||
}
|
||||
|
||||
SSchema* pSchema = getTagSchema(pTableMeta, pStmt->colName);
|
||||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s",
|
||||
pStmt->colName);
|
||||
pReq->tagName = taosStrdup(colName);
|
||||
if (NULL == pReq->tagName) {
|
||||
TAOS_CHECK_GOTO(terrno, NULL, _err);
|
||||
}
|
||||
pReq->tagName = taosStrdup(pStmt->colName);
|
||||
|
||||
pReq->pTagArray = taosArrayInit(1, sizeof(STagVal));
|
||||
if (NULL == pReq->pTagArray) {
|
||||
TAOS_CHECK_GOTO(terrno, NULL, _err);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
_err:
|
||||
if (code != 0) {
|
||||
taosArrayDestroy(pReq->pTagArray);
|
||||
taosMemoryFree(pReq->tagName);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
static int32_t buildUpdateTagValReqImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
char* colName, SVAlterTbReq* pReq) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
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 +15324,82 @@ 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) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SName tbName = {0};
|
||||
SArray* pTsmas = NULL;
|
||||
SHashObj* pUnique = NULL;
|
||||
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 (pReq->pMultiTag == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
pUnique = taosHashInit(nTagValues, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
if (pUnique == NULL) {
|
||||
TAOS_CHECK_GOTO(terrno, NULL, _err);
|
||||
}
|
||||
|
||||
SAlterTableStmt* pTagStmt = NULL;
|
||||
SNode* pNode = NULL;
|
||||
int8_t dummpy = 0;
|
||||
FOREACH(pNode, pNodeList) {
|
||||
SMultiTagUpateVal val = {0};
|
||||
pTagStmt = (SAlterTableStmt*)pNode;
|
||||
|
||||
SMultiTagUpateVal* p = taosHashGet(pUnique, pTagStmt->colName, strlen(pTagStmt->colName));
|
||||
if (p) {
|
||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN);
|
||||
TAOS_CHECK_GOTO(code, NULL, _err);
|
||||
}
|
||||
|
||||
code = taosHashPut(pUnique, pTagStmt->colName, strlen(pTagStmt->colName), &dummpy, sizeof(dummpy));
|
||||
TAOS_CHECK_GOTO(code, NULL, _err);
|
||||
|
||||
code = buildUpdateTagValReqImpl2(pCxt, pTagStmt, pTableMeta, pTagStmt->colName, &val);
|
||||
TAOS_CHECK_GOTO(code, NULL, _err);
|
||||
|
||||
if (taosArrayPush(pReq->pMultiTag, &val) == NULL) {
|
||||
tfreeMultiTagUpateVal((void*)&val);
|
||||
TAOS_CHECK_GOTO(terrno, NULL, _err);
|
||||
}
|
||||
}
|
||||
}
|
||||
_err:
|
||||
taosHashCleanup(pUnique);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
SVAlterTbReq* pReq) {
|
||||
|
@ -15449,6 +15588,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:
|
||||
|
@ -15550,6 +15691,10 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) {
|
|||
taosMemoryFreeClear(p->pData);
|
||||
}
|
||||
}
|
||||
if (pReq->action == TSDB_ALTER_TABLE_UPDATE_MULTI_TAG_VAL) {
|
||||
taosArrayDestroyEx(pReq->pMultiTag, tfreeMultiTagUpateVal);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pReq->pTagArray);
|
||||
if (pReq->tagFree) tTagFree((STag*)pReq->pTagVal);
|
||||
}
|
||||
|
|
|
@ -1582,6 +1582,7 @@
|
|||
,,y,script,./test.sh -f tsim/tag/tinyint.sim
|
||||
,,y,script,./test.sh -f tsim/tag/drop_tag.sim
|
||||
,,y,script,./test.sh -f tsim/tag/tbNameIn.sim
|
||||
,,y,script,./test.sh -f tsim/tag/change_multi_tag.sim
|
||||
,,y,script,./test.sh -f tmp/monitor.sim
|
||||
,,y,script,./test.sh -f tsim/tagindex/add_index.sim
|
||||
,,n,script,./test.sh -f tsim/tagindex/sma_and_tag_index.sim
|
||||
|
|
|
@ -0,0 +1,205 @@
|
|||
system sh/stop_dnodes.sh
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
sql connect
|
||||
|
||||
print ======================== dnode1 start
|
||||
|
||||
$dbPrefix = ta_ad_db
|
||||
$tbPrefix = ta_ad_tb
|
||||
$mtPrefix = ta_ad_mt
|
||||
$tbNum = 10
|
||||
$rowNum = 20
|
||||
$totalNum = 200
|
||||
|
||||
print =============== step1
|
||||
$i = 0
|
||||
$db = $dbPrefix . $i
|
||||
|
||||
sql create database $db
|
||||
sql use $db
|
||||
|
||||
print =============== step2
|
||||
$j = 3
|
||||
$i = 2
|
||||
$mt = $mtPrefix . $i
|
||||
$tb = $tbPrefix . $i
|
||||
$tbj = $tbPrefix . $j
|
||||
$ntable = tb_normal_table
|
||||
|
||||
sql create table $mt (ts timestamp, tbcol int) TAGS(tagCol1 bool, tagCol2 tinyint, tagCol3 smallint, tagCol4 int, tagCol5 bigint, tagCol6 nchar(10), tagCol7 binary(8))
|
||||
sql create table $tb using $mt tags( 1, 2, 3, 5,7, "test", "test")
|
||||
sql create table $tbj using $mt tags( 2, 3, 4, 6,8, "testj", "testj")
|
||||
sql create table $ntable (ts timestamp, f int)
|
||||
|
||||
sql insert into $tb values(now, 1)
|
||||
sql insert into $tb values(now, 1)
|
||||
sql_error alter table $mt set tag tgcol1 = 1,tagcol2 = 2, tag3 = 4 # set tag value on supertable
|
||||
sql_error alter table $ntable set tag f = 10 # set normal table value
|
||||
sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 # dumplicate tag name
|
||||
sql_error alter table $tbj set tag tagCol1=1,tagCol1 = 2 # not exist tag
|
||||
sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx"
|
||||
sql_error alter table $tbj set tag tagCol1 = 1, tagCol5="xxxxxxxxxxxxxxxx", tagCol7="yyyyyyyyyyyyyyyyyyyyyyyyy"
|
||||
sql_error alter table $tbj set tag tagCol1=1,tagCol5=10, tagCol1=3
|
||||
sql_error alter table $tbj set tag tagCol5="xxxx"
|
||||
sql alter table $tbj set tag tagCol1 = 100, tagCol2 = 100
|
||||
|
||||
sql select * from $mt where tagCol2 = 100
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol1 = 1
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql alter table $tbj set tag tagCol1=true,tagCol2=-1,tagcol3=-10, tagcol4=-100,tagcol5=-1000,tagCol6="empty",tagCol7="empty1"
|
||||
sql alter table $tb set tag tagCol1=0
|
||||
|
||||
sql select * from $mt where tagCol1 = true
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol2 = -1
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol3 = -10
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol4 = -100
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol5 = -1000
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
sql select * from $mt where tagCol6 = "empty"
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol6 = "empty1"
|
||||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql insert into $tbj values (now, 1)
|
||||
|
||||
sql select * from $mt where tagCol1 = true
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol2 = -1
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol3 = -10
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol4 = -100
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol5 = -1000
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
sql select * from $mt where tagCol6 = "empty"
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol7 = "empty1"
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql alter table $tbj set tag tagCol1=true
|
||||
sql alter table $tb set tag tagCol1=true
|
||||
|
||||
sql select * from $mt where tagCol1 = true
|
||||
if $rows != 3 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql alter table $tb set tag tagCol1=false
|
||||
|
||||
sql alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=-10000,tagCol6="empty1",tagCol7="empty2"
|
||||
|
||||
sql select * from $mt where tagCol1 = true
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol2 = -10
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol3 = -100
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol4 = -1000
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol5 = -10000
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
sql select * from $mt where tagCol6 = "empty1"
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol7 = "empty2"
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL
|
||||
|
||||
sql alter table $mt drop tag tagCol7
|
||||
sql alter table $mt drop tag tagCol3
|
||||
|
||||
sql alter table $mt add tag tagCol8 int
|
||||
|
||||
sql_error alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL
|
||||
sql_error alter table $tbj set tag tagCol1=true,tagCol2=-10,tagcol3=-100, tagcol4=-1000,tagcol5=NULL,tagCol6=NULL,tagCol7=NULL
|
||||
|
||||
sql alter table $tbj set tag tagCol8 = 8
|
||||
|
||||
sql select * from $mt where tagCol4 = -1000
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select * from $mt where tagCol8 = 8
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -145,7 +145,6 @@ class TDTestCase:
|
|||
'select * from ``',
|
||||
'alter table meters add column `` int',
|
||||
'alter table meters drop column ``',
|
||||
'alter table t0 set tag `` = ""',
|
||||
'alter stable meters add tag `` int',
|
||||
'alter stable meters rename tag cc ``',
|
||||
'alter stable meters drop tag ``',
|
||||
|
|
Loading…
Reference in New Issue