提交 08b39a22 编写于 作者: wmmhello's avatar wmmhello

optimize json length

上级 8d0798e2
...@@ -1082,7 +1082,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC ...@@ -1082,7 +1082,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
if(pSchema->type == TSDB_DATA_TYPE_JSON){ if(pSchema->type == TSDB_DATA_TYPE_JSON){
assert(spd.numOfBound == 1); assert(spd.numOfBound == 1);
if(sToken.n > TSDB_MAX_TAGS_LEN/TSDB_NCHAR_SIZE){ if(sToken.n > TSDB_MAX_JSON_TAGS_LEN/TSDB_NCHAR_SIZE){
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
tscDestroyBoundColumnInfo(&spd); tscDestroyBoundColumnInfo(&spd);
if (TK_STRING == sToken.type) free(sToken.z); if (TK_STRING == sToken.type) free(sToken.z);
......
...@@ -1528,18 +1528,21 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC ...@@ -1528,18 +1528,21 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
} }
int32_t nLen = 0; int32_t nLen = 0;
bool isJsonTag = false;
for (int32_t i = 0; i < numOfTags; ++i) { for (int32_t i = 0; i < numOfTags; ++i) {
TAOS_FIELD* p = taosArrayGet(pTagsList, i); TAOS_FIELD* p = taosArrayGet(pTagsList, i);
if (p->bytes == 0) { if (p->bytes == 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7);
return false; return false;
} }
if(p->type == TSDB_DATA_TYPE_JSON){
isJsonTag = true;
}
nLen += p->bytes; nLen += p->bytes;
} }
// max tag row length must be less than TSDB_MAX_TAGS_LEN // max tag row length must be less than TSDB_MAX_TAGS_LEN
if (nLen > TSDB_MAX_TAGS_LEN) { if (!isJsonTag && nLen > TSDB_MAX_TAGS_LEN) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
return false; return false;
} }
...@@ -6118,7 +6121,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { ...@@ -6118,7 +6121,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidOperationMsg(pMsg, msg25); return invalidOperationMsg(pMsg, msg25);
} }
if (pItem->pVar.nType > TSDB_MAX_TAGS_LEN / TSDB_NCHAR_SIZE) { if (pItem->pVar.nType > TSDB_MAX_JSON_TAGS_LEN / TSDB_NCHAR_SIZE) {
tscError("json tag too long"); tscError("json tag too long");
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidOperationMsg(pMsg, msg14); return invalidOperationMsg(pMsg, msg14);
...@@ -7686,11 +7689,6 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -7686,11 +7689,6 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
} else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) { } else if (pItem->pVar.nType == TSDB_DATA_TYPE_TIMESTAMP) {
pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision); pItem->pVar.i64 = convertTimePrecision(pItem->pVar.i64, TSDB_TIME_PRECISION_NANO, tinfo.precision);
} }
} else if (pSchema->type == TSDB_DATA_TYPE_JSON) {
if (pItem->pVar.nLen > TSDB_MAX_TAGS_LEN) {
tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
} }
ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true); ret = tVariantDump(&(pItem->pVar), tagVal, pSchema->type, true);
...@@ -7778,7 +7776,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) { ...@@ -7778,7 +7776,7 @@ int32_t doCheckForCreateFromStable(SSqlObj* pSql, SSqlInfo* pInfo) {
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
} }
if(pItem->pVar.nLen > TSDB_MAX_TAGS_LEN/TSDB_NCHAR_SIZE){ if(pItem->pVar.nLen > TSDB_MAX_JSON_TAGS_LEN/TSDB_NCHAR_SIZE){
tscError("json tag too long"); tscError("json tag too long");
tdDestroyKVRowBuilder(&kvRowBuilder); tdDestroyKVRowBuilder(&kvRowBuilder);
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
......
...@@ -1479,7 +1479,8 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) { ...@@ -1479,7 +1479,8 @@ int tscEstimateCreateTableMsgLength(SSqlObj *pSql, SSqlInfo *pInfo) {
SCreateTableSql *pCreateTableInfo = pInfo->pCreateTableInfo; SCreateTableSql *pCreateTableInfo = pInfo->pCreateTableInfo;
if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) { if (pCreateTableInfo->type == TSQL_CREATE_TABLE_FROM_STABLE) {
int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo); int32_t numOfTables = (int32_t)taosArrayGetSize(pInfo->pCreateTableInfo->childTableInfo);
size += numOfTables * (sizeof(SCreateTableMsg) + TSDB_MAX_TAGS_LEN); size += numOfTables * (sizeof(SCreateTableMsg) +
((TSDB_MAX_TAGS_LEN > TSDB_MAX_JSON_TAGS_LEN)?TSDB_MAX_TAGS_LEN:TSDB_MAX_JSON_TAGS_LEN));
} else { } else {
size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count); size += sizeof(SSchema) * (pCmd->numOfCols + pCmd->count);
} }
......
...@@ -5237,7 +5237,7 @@ char* parseTagDatatoJson(void *p){ ...@@ -5237,7 +5237,7 @@ char* parseTagDatatoJson(void *p){
memset(tagJsonKey, 0, sizeof(tagJsonKey)); memset(tagJsonKey, 0, sizeof(tagJsonKey));
memcpy(tagJsonKey, varDataVal(val), varDataLen(val)); memcpy(tagJsonKey, varDataVal(val), varDataLen(val));
}else{ // json value }else{ // json value
char tagJsonValue[TSDB_MAX_TAGS_LEN] = {0}; char tagJsonValue[TSDB_MAX_JSON_TAGS_LEN] = {0};
char* realData = POINTER_SHIFT(val, CHAR_BYTES); char* realData = POINTER_SHIFT(val, CHAR_BYTES);
char type = *(char*)val; char type = *(char*)val;
if(type == TSDB_DATA_TYPE_NCHAR) { if(type == TSDB_DATA_TYPE_NCHAR) {
...@@ -5365,11 +5365,11 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in ...@@ -5365,11 +5365,11 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
char *jsonValue = item->valuestring; char *jsonValue = item->valuestring;
strtrim(jsonValue); strtrim(jsonValue);
outLen = 0; outLen = 0;
char tagVal[TSDB_MAX_TAGS_LEN + VARSTR_HEADER_SIZE + CHAR_BYTES] = {0}; char tagVal[TSDB_MAX_JSON_TAGS_LEN + CHAR_BYTES] = {0};
*tagVal = jsonType2DbType(0, item->type); // type *tagVal = jsonType2DbType(0, item->type); // type
char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES); char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES);
if (!taosMbsToUcs4(jsonValue, strlen(jsonValue), varDataVal(tagData), if (!taosMbsToUcs4(jsonValue, strlen(jsonValue), varDataVal(tagData),
TSDB_MAX_TAGS_LEN, &outLen)) { TSDB_MAX_JSON_TAGS_LEN, &outLen)) {
tscError("json string error:%s|%s", strerror(errno), jsonValue); tscError("json string error:%s|%s", strerror(errno), jsonValue);
retCode = tscSQLSyntaxErrMsg(errMsg, "serizelize json error", NULL); retCode = tscSQLSyntaxErrMsg(errMsg, "serizelize json error", NULL);
goto end; goto end;
......
...@@ -384,7 +384,7 @@ tDataTypeDescriptor tDataTypes[16] = { ...@@ -384,7 +384,7 @@ tDataTypeDescriptor tDataTypes[16] = {
{TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_u16}, {TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_u16},
{TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32}, {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32},
{TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_u64}, {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_u64},
{TSDB_DATA_TYPE_JSON,4, JSON_BYTES, "JSON", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr}, {TSDB_DATA_TYPE_JSON,4, TSDB_MAX_JSON_TAGS_LEN, "JSON", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr},
}; };
char tTokenTypeSwitcher[13] = { char tTokenTypeSwitcher[13] = {
......
...@@ -50,7 +50,6 @@ extern const int32_t TYPE_BYTES[16]; ...@@ -50,7 +50,6 @@ extern const int32_t TYPE_BYTES[16];
#define DOUBLE_BYTES sizeof(double) #define DOUBLE_BYTES sizeof(double)
#define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*) #define POINTER_BYTES sizeof(void *) // 8 by default assert(sizeof(ptrdiff_t) == sizseof(void*)
#define JSON_BYTES (TSDB_MAX_TAGS_LEN + VARSTR_HEADER_SIZE)
#define TSDB_KEYSIZE sizeof(TSKEY) #define TSDB_KEYSIZE sizeof(TSKEY)
#if LINUX #if LINUX
...@@ -222,6 +221,7 @@ do { \ ...@@ -222,6 +221,7 @@ do { \
*/ */
#define TSDB_MAX_BYTES_PER_ROW 49151 #define TSDB_MAX_BYTES_PER_ROW 49151
#define TSDB_MAX_TAGS_LEN 16384 #define TSDB_MAX_TAGS_LEN 16384
#define TSDB_MAX_JSON_TAGS_LEN (4096*TSDB_NCHAR_SIZE + 2)
#define TSDB_MAX_TAGS 128 #define TSDB_MAX_TAGS 128
#define TSDB_MAX_TAG_CONDITIONS 1024 #define TSDB_MAX_TAG_CONDITIONS 1024
#define TSDB_MAX_JSON_KEY_LEN 256 #define TSDB_MAX_JSON_KEY_LEN 256
......
...@@ -3358,8 +3358,8 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, ...@@ -3358,8 +3358,8 @@ static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag,
tVariantCreateFromBinary(tag, varDataVal(val), len, type); tVariantCreateFromBinary(tag, varDataVal(val), len, type);
//tVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type); //tVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type);
} else if(type == TSDB_DATA_TYPE_JSON){ } else if(type == TSDB_DATA_TYPE_JSON){
char jsonVal[TSDB_MAX_TAGS_LEN] = {0}; char jsonVal[TSDB_MAX_JSON_TAGS_LEN] = {0};
getJsonTagValueAll(val, jsonVal, TSDB_MAX_TAGS_LEN); getJsonTagValueAll(val, jsonVal, TSDB_MAX_JSON_TAGS_LEN);
tVariantCreateFromBinary(tag, jsonVal, varDataTLen(jsonVal), type); tVariantCreateFromBinary(tag, jsonVal, varDataTLen(jsonVal), type);
} }
else { else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册