提交 559dcff6 编写于 作者: S shenglian zhou

schemaless:before retrying loading meta

上级 a687df67
......@@ -116,7 +116,7 @@ static int32_t validateColumnName(char* name);
static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo, int32_t killType);
static int32_t setCompactVnodeInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
static int32_t validateOneTag(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
static bool hasTimestampForPointInterpQuery(SQueryInfo* pQueryInfo);
static bool hasNormalColumnFilter(SQueryInfo* pQueryInfo);
......@@ -307,31 +307,6 @@ static int32_t invalidOperationMsg(char* dstBuffer, const char* errMsg) {
return tscInvalidOperationMsg(dstBuffer, errMsg, NULL);
}
int32_t tscErrorMsgWithCode(int32_t code, char* dstBuffer, const char* errMsg, const char* sql) {
const char* msgFormat1 = "%s:%s";
const char* msgFormat2 = "%s:\'%s\' (%s)";
const char* msgFormat3 = "%s:\'%s\'";
const int32_t BACKWARD_CHAR_STEP = 0;
if (sql == NULL) {
assert(errMsg != NULL);
sprintf(dstBuffer, msgFormat1, tstrerror(code), errMsg);
return code;
}
char buf[64] = {0}; // only extract part of sql string
strncpy(buf, (sql - BACKWARD_CHAR_STEP), tListLen(buf) - 1);
if (errMsg != NULL) {
sprintf(dstBuffer, msgFormat2, tstrerror(code), buf, errMsg);
} else {
sprintf(dstBuffer, msgFormat3, tstrerror(code), buf); // no additional information for invalid sql error
}
return code;
}
static int convertTimestampStrToInt64(tVariant *pVar, int32_t precision) {
int64_t time = 0;
strdequote(pVar->pz);
......@@ -1418,6 +1393,7 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
const char* msg = "illegal number of columns";
const char* msg1 = "first column must be timestamp";
const char* msg2 = "row length exceeds max length";
const char* msg3 = "duplicated column names";
const char* msg4 = "invalid data type";
const char* msg5 = "invalid binary/nchar column length";
const char* msg6 = "invalid column name";
......@@ -1466,7 +1442,7 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
// field name must be unique
if (has(pFieldList, i + 1, pField->name) == true) {
tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), pField->name, NULL);
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
return false;
}
......@@ -1488,6 +1464,8 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
const char* msg1 = "invalid number of tag columns";
const char* msg2 = "tag length too long";
const char* msg3 = "duplicated column names";
//const char* msg4 = "timestamp not allowed in tags";
const char* msg5 = "invalid data type in tags";
const char* msg6 = "invalid tag name";
const char* msg7 = "invalid binary/nchar tag length";
......@@ -1518,7 +1496,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
}
if (has(pTagsList, i + 1, p->name) == true) {
tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), p->name, NULL);
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
return false;
}
}
......@@ -1545,7 +1523,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
TAOS_FIELD* p = taosArrayGet(pTagsList, i);
if (has(pFieldList, 0, p->name) == true) {
tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), p->name, NULL);
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
return false;
}
}
......@@ -1556,7 +1534,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
/*
* tags name /column name is truncated in sql.y
*/
bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
int32_t validateOneTag(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
const char* msg3 = "tag length too long";
const char* msg4 = "invalid tag name";
const char* msg5 = "invalid binary/nchar tag length";
......@@ -1571,8 +1549,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
// no more max columns
if (numOfTags + numOfCols >= TSDB_MAX_COLUMNS) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7);
}
// no more than 6 tags
......@@ -1580,8 +1557,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
char msg[128] = {0};
sprintf(msg, "tags no more than %d", TSDB_MAX_TAGS);
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg);
}
// no timestamp allowable
......@@ -1591,8 +1567,7 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
//}
if ((pTagField->type < TSDB_DATA_TYPE_BOOL) || (pTagField->type > TSDB_DATA_TYPE_UBIGINT)) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
SSchema* pTagSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta);
......@@ -1604,20 +1579,17 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
// length less than TSDB_MAX_TASG_LEN
if (nLen + pTagField->bytes > TSDB_MAX_TAGS_LEN) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
// tags name can not be a keyword
if (validateColumnName(pTagField->name) != TSDB_CODE_SUCCESS) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
}
// binary(val), val can not be equalled to or less than 0
if ((pTagField->type == TSDB_DATA_TYPE_BINARY || pTagField->type == TSDB_DATA_TYPE_NCHAR) && pTagField->bytes <= 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
// field name must be unique
......@@ -1625,15 +1597,14 @@ bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField) {
for (int32_t i = 0; i < numOfTags + numOfCols; ++i) {
if (strncasecmp(pTagField->name, pSchema[i].name, sizeof(pTagField->name) - 1) == 0) {
tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), pTagField->name, NULL);
return false;
return tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), pTagField->name, NULL);
}
}
return true;
return TSDB_CODE_SUCCESS;
}
bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
int32_t validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
const char* msg1 = "too many columns";
const char* msg3 = "column length too long";
const char* msg4 = "invalid data type";
......@@ -1649,18 +1620,15 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
// no more max columns
if (numOfCols >= TSDB_MAX_COLUMNS || numOfTags + numOfCols >= TSDB_MAX_COLUMNS) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if (pColField->type < TSDB_DATA_TYPE_BOOL || pColField->type > TSDB_DATA_TYPE_UBIGINT) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4);
}
if (validateColumnName(pColField->name) != TSDB_CODE_SUCCESS) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5);
}
SSchema* pSchema = tscGetTableSchema(pTableMeta);
......@@ -1671,25 +1639,22 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
}
if (pColField->bytes <= 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6);
}
// length less than TSDB_MAX_BYTES_PER_ROW
if (nLen + pColField->bytes > TSDB_MAX_BYTES_PER_ROW) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
return false;
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
// field name must be unique
for (int32_t i = 0; i < numOfTags + numOfCols; ++i) {
if (strncasecmp(pColField->name, pSchema[i].name, sizeof(pColField->name) - 1) == 0) {
tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), pColField->name, NULL);
return false;
return tscErrorMsgWithCode(TSDB_CODE_TSC_DUP_COL_NAMES, tscGetErrorMsgPayload(pCmd), pColField->name, NULL);
}
}
return true;
return TSDB_CODE_SUCCESS;
}
/* is contained in pFieldList or not */
......@@ -6108,8 +6073,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
TAOS_FIELD* p = taosArrayGet(pFieldList, 0);
if (!validateOneTags(pCmd, p)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
int32_t ret = validateOneTag(pCmd, p);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
}
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, p);
......@@ -6286,8 +6252,9 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
}
TAOS_FIELD* p = taosArrayGet(pFieldList, 0);
if (!validateOneColumn(pCmd, p)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
int32_t ret = validateOneColumn(pCmd, p);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
}
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, p);
......@@ -8702,8 +8669,6 @@ static STableMeta* extractTempTableMetaFromSubquery(SQueryInfo* pUpstream) {
n += 1;
}
info->numOfColumns = n;
return meta;
}
......
......@@ -4096,6 +4096,31 @@ int32_t tscInvalidOperationMsg(char* msg, const char* additionalInfo, const char
return TSDB_CODE_TSC_INVALID_OPERATION;
}
int32_t tscErrorMsgWithCode(int32_t code, char* dstBuffer, const char* errMsg, const char* sql) {
const char* msgFormat1 = "%s:%s";
const char* msgFormat2 = "%s:\'%s\' (%s)";
const char* msgFormat3 = "%s:\'%s\'";
const int32_t BACKWARD_CHAR_STEP = 0;
if (sql == NULL) {
assert(errMsg != NULL);
sprintf(dstBuffer, msgFormat1, tstrerror(code), errMsg);
return code;
}
char buf[64] = {0}; // only extract part of sql string
strncpy(buf, (sql - BACKWARD_CHAR_STEP), tListLen(buf) - 1);
if (errMsg != NULL) {
sprintf(dstBuffer, msgFormat2, tstrerror(code), buf, errMsg);
} else {
sprintf(dstBuffer, msgFormat3, tstrerror(code), buf); // no additional information for invalid sql error
}
return code;
}
bool tscHasReachLimitation(SQueryInfo* pQueryInfo, SSqlRes* pRes) {
assert(pQueryInfo != NULL && pQueryInfo->clauseLimit != 0);
return (pQueryInfo->clauseLimit > 0 && pRes->numOfClauseTotal >= pQueryInfo->clauseLimit);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册