fix: unify tag value parsing syntax

This commit is contained in:
kailixu 2024-03-10 22:14:57 +08:00
parent a083f45ac1
commit 433179af0d
29 changed files with 3894 additions and 3509 deletions

View File

@ -2822,6 +2822,7 @@ typedef struct {
int8_t tagType;
uint32_t nTagVal;
uint8_t* pTagVal;
SArray* pTagArray;
// TSDB_ALTER_TABLE_UPDATE_OPTIONS
int8_t updateTTL;
int32_t newTTL;

View File

@ -98,8 +98,8 @@ int32_t parseSignAndUInteger(const char *z, int32_t n, bool *is_neg, uint64_t *v
int32_t toDoubleEx(const char *z, int32_t n, uint32_t type, double* value) {
if (n == 0) {
*value = 0;
return TSDB_CODE_SUCCESS;
errno = EINVAL;
return TSDB_CODE_FAILED;
}
errno = 0;
@ -144,8 +144,8 @@ int32_t toIntegerEx(const char *z, int32_t n, uint32_t type, int64_t *value) {
}
if (n == 0) {
*value = 0;
return TSDB_CODE_SUCCESS;
errno = EINVAL;
return TSDB_CODE_FAILED;
}
// 1. try to parse as integer

View File

@ -108,6 +108,8 @@ SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode
SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName);
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral);
SNode* createRawValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode *pNode);
SNode* createRawValueNodeExt(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode *pLeft, SNode *pRight);
SNodeList* createHintNodeList(SAstCreateContext* pCxt, const SToken* pLiteral);
SNode* createIdentifierValueNode(SAstCreateContext* pCxt, SToken* pLiteral);
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral);

View File

@ -23,6 +23,7 @@ extern "C" {
#include "catalog.h"
#include "os.h"
#include "parser.h"
#include "parToken.h"
#include "query.h"
#define parserFatal(param, ...) qFatal("PARSER: " param, ##__VA_ARGS__)
@ -35,6 +36,54 @@ extern "C" {
#define ROWTS_PSEUDO_COLUMN_NAME "_rowts"
#define C0_PSEUDO_COLUMN_NAME "_c0"
#define IS_NOW_STR(s, n) \
((*(s) == 'n' || *(s) == 'N') && (*((s) + 1) == 'o' || *((s) + 1) == 'O') && \
(*((s) + 2) == 'w' || *((s) + 2) == 'W') && (n == 3 || (n == 5 && *((s) + 3) == '(' && *((s) + 4) == ')')))
#define IS_TODAY_STR(s, n) \
((*(s) == 't' || *(s) == 'T') && (*((s) + 1) == 'o' || *((s) + 1) == 'O') && \
(*((s) + 2) == 'd' || *((s) + 2) == 'D') && (*((s) + 3) == 'a' || *((s) + 3) == 'A') && \
(*((s) + 4) == 'y' || *((s) + 4) == 'Y') && (n == 5 || (n == 7 && *((s) + 5) == '(' && *((s) + 6) == ')')))
#define IS_TRUE_STR(s, n) \
(n == 4 && (*(s) == 't' || *(s) == 'T') && (*((s) + 1) == 'r' || *((s) + 1) == 'R') && \
(*((s) + 2) == 'u' || *((s) + 2) == 'U') && (*((s) + 3) == 'e' || *((s) + 3) == 'E'))
#define IS_FALSE_STR(s, n) \
(n == 5 && (*(s) == 'f' || *(s) == 'F') && (*((s) + 1) == 'a' || *((s) + 1) == 'A') && \
(*((s) + 2) == 'l' || *((s) + 2) == 'L') && (*((s) + 3) == 's' || *((s) + 3) == 'S') && \
(*((s) + 4) == 'e' || *((s) + 4) == 'E'))
#define IS_NULL_STR(s, n) \
(n == 4 && (*(s) == 'N' || *(s) == 'n') && (*((s) + 1) == 'U' || *((s) + 1) == 'u') && \
(*((s) + 2) == 'L' || *((s) + 2) == 'l') && (*((s) + 3) == 'L' || *((s) + 3) == 'l'))
#define NEXT_TOKEN_WITH_PREV(pSql, token) \
do { \
int32_t index = 0; \
token = tStrGetToken(pSql, &index, true, NULL); \
pSql += index; \
} while (0)
#define NEXT_TOKEN_WITH_PREV_EXT(pSql, token, pIgnoreComma) \
do { \
int32_t index = 0; \
token = tStrGetToken(pSql, &index, true, pIgnoreComma); \
pSql += index; \
} while (0)
#define NEXT_TOKEN_KEEP_SQL(pSql, token, index) \
do { \
token = tStrGetToken(pSql, &index, false, NULL); \
} while (0)
#define NEXT_VALID_TOKEN(pSql, token) \
do { \
(token).n = tGetToken(pSql, &(token).type); \
(token).z = (char*)pSql; \
pSql += (token).n; \
} while (TK_NK_SPACE == (token).type)
typedef struct SMsgBuf {
int32_t len;
char* buf;
@ -89,6 +138,9 @@ int32_t getTableTypeFromTableNode(SNode *pTable);
int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen);
int32_t getVnodeSysTableTargetName(int32_t acctId, SNode* pWhere, SName* pName);
int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf, int8_t type);
int32_t parseTagValue(SMsgBuf* pMsgBuf, const char** pSql, uint8_t precision, SSchema* pTagSchema, SToken* pToken,
SArray* pTagName, SArray* pTagVals, STag** pTag);
int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq);
int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache);

View File

@ -354,7 +354,7 @@ alter_table_clause(A) ::=
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); }
alter_table_clause(A) ::=
full_table_name(B) SET TAG column_name(C) NK_EQ signed_literal(D). { A = createAlterTableSetTag(pCxt, B, &C, D); }
full_table_name(B) SET TAG column_name(C) NK_EQ tags_literal(D). { A = createAlterTableSetTag(pCxt, B, &C, D); }
%type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); }
@ -363,7 +363,7 @@ multi_create_clause(A) ::= multi_create_clause(B) create_subtable_clause(C).
create_subtable_clause(A) ::=
not_exists_opt(B) full_table_name(C) USING full_table_name(D)
specific_cols_opt(E) TAGS NK_LP expression_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
specific_cols_opt(E) TAGS NK_LP tags_literal_list(F) NK_RP table_options(G). { A = createCreateSubTableClause(pCxt, B, C, D, E, F, G); }
%type multi_drop_clause { SNodeList* }
%destructor multi_drop_clause { nodesDestroyList($$); }
@ -744,6 +744,52 @@ insert_query(A) ::= INSERT INTO full_table_name(D)
NK_LP col_name_list(B) NK_RP query_or_subquery(C). { A = createInsertStmt(pCxt, D, B, C); }
insert_query(A) ::= INSERT INTO full_table_name(C) query_or_subquery(B). { A = createInsertStmt(pCxt, C, NULL, B); }
/************************************************ tags_literal *************************************************************/
tags_literal(A) ::= NK_INTEGER(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &B, NULL); }
tags_literal(A) ::= NK_PLUS(B) NK_INTEGER(C). {
SToken t = B;
t.n = (C.z + C.n) - B.z;
A = createRawValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &t, NULL);
}
tags_literal(A) ::= NK_MINUS(B) NK_INTEGER(C). {
SToken t = B;
t.n = (C.z + C.n) - B.z;
A = createRawValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &t, NULL);
}
tags_literal(A) ::= NK_FLOAT(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B, NULL); }
tags_literal(A) ::= NK_PLUS(B) NK_FLOAT(C). {
SToken t = B;
t.n = (C.z + C.n) - B.z;
A = createRawValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t, NULL);
}
tags_literal(A) ::= NK_MINUS(B) NK_FLOAT(C). {
SToken t = B;
t.n = (C.z + C.n) - B.z;
A = createRawValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t, NULL);
}
tags_literal(A) ::= NK_STRING(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B, NULL); }
tags_literal(A) ::= NK_BOOL(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B, NULL); }
tags_literal(A) ::= NULL(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_NULL, &B, NULL); }
tags_literal(A) ::= literal_func(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_BINARY, NULL, B); }
tags_literal(A) ::= literal_func(B) NK_PLUS duration_literal(C). {
SToken l = getTokenFromRawExprNode(pCxt, B);
SToken r = getTokenFromRawExprNode(pCxt, C);
l.n = (r.z + r.n) - l.z;
A = createRawValueNodeExt(pCxt, TSDB_DATA_TYPE_BINARY, &l, B, C);
}
tags_literal(A) ::= literal_func(B) NK_MINUS duration_literal(C). {
SToken l = getTokenFromRawExprNode(pCxt, B);
SToken r = getTokenFromRawExprNode(pCxt, C);
l.n = (r.z + r.n) - l.z;
A = createRawValueNodeExt(pCxt, TSDB_DATA_TYPE_BINARY, &l, B, C);
}
%type tags_literal_list { SNodeList* }
%destructor tags_literal_list { nodesDestroyList($$); }
tags_literal_list(A) ::= tags_literal(B). { A = createNodeList(pCxt, B); }
tags_literal_list(A) ::= tags_literal_list(B) NK_COMMA tags_literal(C). { A = addNodeToList(pCxt, B, C); }
/************************************************ literal *************************************************************/
literal(A) ::= NK_INTEGER(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &B)); }
literal(A) ::= NK_FLOAT(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B)); }
@ -924,6 +970,7 @@ function_expression(A) ::= literal_func(B).
literal_func(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNode(pCxt, &B, NULL)); }
literal_func(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
literal_func(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
%type noarg_func { SToken }
%destructor noarg_func { }

View File

@ -371,6 +371,80 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
return (SNode*)val;
}
SNode* createRawValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode* pNode) {
CHECK_PARSER_STATUS(pCxt);
SValueNode* val = NULL;
if (!(val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE))) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY, "Out of memory");
goto _exit;
}
if (pLiteral) {
val->literal = strndup(pLiteral->z, pLiteral->n);
} else if (pNode) {
SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
if (!nodesIsExprNode(pRawExpr->pNode)) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, pRawExpr->p);
goto _exit;
}
val->literal = strndup(pRawExpr->p, pRawExpr->n);
} else {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTERNAL_ERROR, "Invalid parameters");
goto _exit;
}
if (!val->literal) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY, "Out of memory");
goto _exit;
}
val->node.resType.type = dataType;
val->node.resType.bytes = IS_VAR_DATA_TYPE(dataType) ? strlen(val->literal) : tDataTypes[dataType].bytes;
if (TSDB_DATA_TYPE_TIMESTAMP == dataType) {
val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
}
_exit:
nodesDestroyNode(pNode);
if (pCxt->errCode != 0) {
nodesDestroyNode((SNode*)val);
return NULL;
}
return (SNode*)val;
}
SNode* createRawValueNodeExt(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral, SNode* pLeft,
SNode* pRight) {
CHECK_PARSER_STATUS(pCxt);
SValueNode* val = NULL;
if (!(val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE))) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY, "Out of memory");
goto _exit;
}
if (pLiteral) {
if (!(val->literal = strndup(pLiteral->z, pLiteral->n))) {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY, "Out of memory");
goto _exit;
}
} else {
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTERNAL_ERROR, "Invalid parameters");
goto _exit;
}
val->node.resType.type = dataType;
val->node.resType.bytes = IS_VAR_DATA_TYPE(dataType) ? strlen(val->literal) : tDataTypes[dataType].bytes;
if (TSDB_DATA_TYPE_TIMESTAMP == dataType) {
val->node.resType.precision = TSDB_TIME_PRECISION_MILLI;
}
_exit:
nodesDestroyNode(pLeft);
nodesDestroyNode(pRight);
if (pCxt->errCode != 0) {
nodesDestroyNode((SNode*)val);
return NULL;
}
return (SNode*)val;
}
static bool hasHint(SNodeList* pHintList, EHintOption hint) {
if (!pHintList) return false;
SNode* pNode;

View File

@ -20,32 +20,6 @@
#include "ttime.h"
#include "geosWrapper.h"
#define NEXT_TOKEN_WITH_PREV(pSql, token) \
do { \
int32_t index = 0; \
token = tStrGetToken(pSql, &index, true, NULL); \
pSql += index; \
} while (0)
#define NEXT_TOKEN_WITH_PREV_EXT(pSql, token, pIgnoreComma) \
do { \
int32_t index = 0; \
token = tStrGetToken(pSql, &index, true, pIgnoreComma); \
pSql += index; \
} while (0)
#define NEXT_TOKEN_KEEP_SQL(pSql, token, index) \
do { \
token = tStrGetToken(pSql, &index, false, NULL); \
} while (0)
#define NEXT_VALID_TOKEN(pSql, token) \
do { \
(token).n = tGetToken(pSql, &(token).type); \
(token).z = (char*)pSql; \
pSql += (token).n; \
} while (TK_NK_SPACE == (token).type)
typedef struct SInsertParseContext {
SParseContext* pComCxt;
SMsgBuf msg;
@ -63,13 +37,9 @@ typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t
static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE;
static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE;
static bool isNullStr(SToken* pToken) {
return ((pToken->type == TK_NK_STRING) && (strlen(TSDB_DATA_NULL_STR_L) == pToken->n) &&
(strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0));
}
static bool isNullValue(int8_t dataType, SToken* pToken) {
return TK_NULL == pToken->type || (!IS_STR_DATA_TYPE(dataType) && isNullStr(pToken));
static FORCE_INLINE bool isNullValue(int8_t dataType, SToken* pToken) {
return TK_NULL == pToken->type ||
(TK_NK_STRING == pToken->type && !IS_STR_DATA_TYPE(dataType) && IS_NULL_STR(pToken->z, pToken->n));
}
static FORCE_INLINE int32_t toDouble(SToken* pToken, double* value, char** endPtr) {
@ -268,7 +238,8 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, E
return code;
}
static int parseTimestampOrInterval(const char** end, SToken* pToken, int16_t timePrec, int64_t* ts, int64_t* interval, SMsgBuf* pMsgBuf, bool* isTs) {
static int parseTimestampOrInterval(const char** end, SToken* pToken, int16_t timePrec, int64_t* ts, int64_t* interval,
SMsgBuf* pMsgBuf, bool* isTs) {
if (pToken->type == TK_NOW) {
*isTs = true;
*ts = taosGetTimestamp(timePrec);
@ -289,7 +260,20 @@ static int parseTimestampOrInterval(const char** end, SToken* pToken, int16_t ti
} else { // parse the RFC-3339/ISO-8601 timestamp format string
*isTs = true;
if (taosParseTime(pToken->z, ts, pToken->n, timePrec, tsDaylight) != TSDB_CODE_SUCCESS) {
return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z);
if (pToken->type != TK_NK_STRING) {
return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z);
}
if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, ts)) {
if (IS_NOW_STR(pToken->z, pToken->n)) {
*isTs = true;
*ts = taosGetTimestamp(timePrec);
} else if (IS_TODAY_STR(pToken->z, pToken->n)) {
*isTs = true;
*ts = taosGetTimestampToday(timePrec);
} else {
return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z);
}
}
}
}
@ -313,10 +297,22 @@ static int parseTime(const char** end, SToken* pToken, int16_t timePrec, int64_t
for (int k = pToken->n; pToken->z[k] != '\0'; k++) {
if (pToken->z[k] == ' ' || pToken->z[k] == '\t') continue;
if (pToken->z[k] == '(' && pToken->z[k + 1] == ')') { // for insert NOW()/TODAY()
*end = pTokenEnd = &pToken->z[k + 2];
k++;
continue;
if (pToken->z[k] == '(') { // for insert NOW()/TODAY()
if (pToken->z[k + 1] == ')') {
*end = pTokenEnd = &pToken->z[k + 2];
++k;
continue;
} else {
char nc = pToken->z[k + 1];
while (nc == ' ' || nc == '\t' || nc == '\n' || nc == '\r' || nc == '\f') {
nc = pToken->z[(++k) + 1];
}
if (nc == ')') {
*end = pTokenEnd = &pToken->z[k + 2];
++k;
continue;
}
}
}
if (pToken->z[k] == ',') {
*end = pTokenEnd;
@ -491,9 +487,9 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema,
switch (pSchema->type) {
case TSDB_DATA_TYPE_BOOL: {
if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) {
if (strncmp(pToken->z, "true", pToken->n) == 0) {
if (IS_TRUE_STR(pToken->z, pToken->n)) {
*(int8_t*)(&val->i64) = TRUE_VALUE;
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
} else if (IS_FALSE_STR(pToken->z, pToken->n)) {
*(int8_t*)(&val->i64) = FALSE_VALUE;
} else {
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
@ -709,30 +705,29 @@ static int32_t parseBoundTagsClause(SInsertParseContext* pCxt, SVnodeModifyOpStm
return parseBoundColumns(pCxt, &pStmt->pSql, BOUND_TAGS, pStmt->pTableMeta, &pCxt->tags);
}
static int32_t parseTagValue(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt, const char** ppSql, SSchema* pTagSchema, SToken* pToken,
SArray* pTagName, SArray* pTagVals, STag** pTag) {
int32_t parseTagValue(SMsgBuf* pMsgBuf, const char** pSql, uint8_t precision, SSchema* pTagSchema, SToken* pToken,
SArray* pTagName, SArray* pTagVals, STag** pTag) {
bool isNull = isNullValue(pTagSchema->type, pToken);
if (!isNull) {
if (!isNull && pTagName) {
taosArrayPush(pTagName, pTagSchema->name);
}
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
return buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", pToken->z);
return buildSyntaxErrMsg(pMsgBuf, "json string too long than 4095", pToken->z);
}
if (isNull) {
return tTagNew(pTagVals, 1, true, pTag);
} else {
return parseJsontoTagData(pToken->z, pTagVals, pTag, &pCxt->msg);
return parseJsontoTagData(pToken->z, pTagVals, pTag, pMsgBuf);
}
}
if (isNull) return 0;
STagVal val = {0};
int32_t code =
parseTagToken(ppSql, pToken, pTagSchema, pStmt->pTableMeta->tableInfo.precision, &val, &pCxt->msg);
int32_t code = parseTagToken(pSql, pToken, pTagSchema, precision, &val, pMsgBuf);
if (TSDB_CODE_SUCCESS == code) {
taosArrayPush(pTagVals, &val);
}
@ -755,7 +750,7 @@ static int32_t buildCreateTbReq(SVnodeModifyOpStmt* pStmt, STag* pTag, SArray* p
return TSDB_CODE_SUCCESS;
}
static int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf, int8_t type) {
int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf, int8_t type) {
if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER &&
pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL &&
pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT &&
@ -911,12 +906,19 @@ static int32_t checkSubtablePrivilege(SArray* pTagVals, SArray* pTagName, SNode*
static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) {
int32_t code = TSDB_CODE_SUCCESS;
SSchema* pSchema = getTableTagSchema(pStmt->pTableMeta);
SArray* pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal));
SArray* pTagName = taosArrayInit(8, TSDB_COL_NAME_LEN);
SArray* pTagVals = NULL;
SArray* pTagName = NULL;
uint8_t precision = pStmt->pTableMeta->tableInfo.precision;
SToken token;
bool isParseBindParam = false;
bool isJson = false;
STag* pTag = NULL;
if (!(pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal))) ||
!(pTagName = taosArrayInit(pCxt->tags.numOfBound, TSDB_COL_NAME_LEN))) {
return TSDB_CODE_OUT_OF_MEMORY;
}
for (int i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->tags.numOfBound; ++i) {
NEXT_TOKEN_WITH_PREV(pStmt->pSql, token);
@ -938,16 +940,15 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
SSchema* pTagSchema = &pSchema[pCxt->tags.pColIndex[i]];
isJson = pTagSchema->type == TSDB_DATA_TYPE_JSON;
code = checkAndTrimValue(&token, pCxt->tmpTokenBuf, &pCxt->msg, pTagSchema->type);
if (TK_NK_VARIABLE == token.type) {
if (TSDB_CODE_SUCCESS == code && TK_NK_VARIABLE == token.type) {
code = buildSyntaxErrMsg(&pCxt->msg, "not expected tags values ", token.z);
}
if (TSDB_CODE_SUCCESS == code) {
code = parseTagValue(pCxt, pStmt, &pStmt->pSql, pTagSchema, &token, pTagName, pTagVals, &pTag);
code = parseTagValue(&pCxt->msg, &pStmt->pSql, precision, pTagSchema, &token, pTagName, pTagVals, &pTag);
}
}
if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pTagCond) {
assert(0);
code = checkSubtablePrivilege(pTagVals, pTagName, &pStmt->pTagCond);
}
@ -960,8 +961,8 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt
pTag = NULL;
}
for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
STagVal* p = (STagVal*)taosArrayGet(pTagVals, i);
for (int32_t i = 0; i < TARRAY_SIZE(pTagVals); ++i) {
STagVal* p = (STagVal*)TARRAY_GET_ELEM(pTagVals, i);
if (IS_VAR_DATA_TYPE(p->type)) {
taosMemoryFreeClear(p->pData);
}
@ -1426,9 +1427,9 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
switch (pSchema->type) {
case TSDB_DATA_TYPE_BOOL: {
if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) {
if (strncmp(pToken->z, "true", pToken->n) == 0) {
if (IS_TRUE_STR(pToken->z, pToken->n)) {
pVal->value.val = TRUE_VALUE;
} else if (strncmp(pToken->z, "false", pToken->n) == 0) {
} else if (IS_FALSE_STR(pToken->z, pToken->n)) {
pVal->value.val = FALSE_VALUE;
} else {
return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z);
@ -1511,7 +1512,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
break;
}
case TSDB_DATA_TYPE_FLOAT: {
double dv;
double dv;
int32_t code = toDoubleEx(pToken->z, pToken->n, pToken->type, &dv);
if (TSDB_CODE_SUCCESS != code) {
return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z);
@ -1524,7 +1525,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
double dv;
double dv;
int32_t code = toDoubleEx(pToken->z, pToken->n, pToken->type, &dv);
if (TSDB_CODE_SUCCESS != code) {
return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z);
@ -1550,7 +1551,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
}
case TSDB_DATA_TYPE_VARBINARY: {
int32_t code = parseVarbinary(pToken, &pVal->value.pData, &pVal->value.nData, pSchema->bytes);
if(code != TSDB_CODE_SUCCESS){
if (code != TSDB_CODE_SUCCESS) {
return generateSyntaxErrMsg(&pCxt->msg, code, pSchema->name);
}
break;
@ -1588,9 +1589,9 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
break;
}
case TSDB_DATA_TYPE_GEOMETRY: {
int32_t code = TSDB_CODE_FAILED;
unsigned char *output = NULL;
size_t size = 0;
int32_t code = TSDB_CODE_FAILED;
unsigned char* output = NULL;
size_t size = 0;
code = parseGeometry(pToken, &output, &size);
if (code != TSDB_CODE_SUCCESS) {
@ -1599,13 +1600,11 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
// Too long values will raise the invalid sql error message
else if (size + VARSTR_HEADER_SIZE > pSchema->bytes) {
code = generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name);
}
else {
} else {
pVal->value.pData = taosMemoryMalloc(size);
if (NULL == pVal->value.pData) {
code = TSDB_CODE_OUT_OF_MEMORY;
}
else {
} else {
memcpy(pVal->value.pData, output, size);
pVal->value.nData = size;
}
@ -1640,18 +1639,14 @@ static int32_t parseValueToken(SInsertParseContext* pCxt, const char** pSql, STo
return buildSyntaxErrMsg(&pCxt->msg, "primary timestamp should not be null", pToken->z);
}
if (TK_NK_VARIABLE == pToken->type && pSchema->type != TSDB_DATA_TYPE_TIMESTAMP) {
return buildSyntaxErrMsg(&pCxt->msg, "invalid values", pToken->z);
}
pVal->flag = CV_FLAG_NULL;
return TSDB_CODE_SUCCESS;
}
if (TSDB_CODE_SUCCESS == code && IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) {
return buildSyntaxErrMsg(&pCxt->msg, "invalid numeric data", pToken->z);
}
if (TSDB_CODE_SUCCESS == code) {
if (pToken->n == 0 && IS_NUMERIC_TYPE(pSchema->type)) {
return buildSyntaxErrMsg(&pCxt->msg, "invalid numeric data", pToken->z);
}
code = parseValueTokenImpl(pCxt, pSql, pToken, pSchema, timePrec, pVal);
}
@ -1729,18 +1724,19 @@ static int32_t processCtbTagsAfterCtbName(SInsertParseContext* pCxt, SVnodeModif
const SToken* tagTokens, SSchema* const* tagSchemas,
int numOfTagTokens) {
int32_t code = TSDB_CODE_SUCCESS;
uint8_t precision = pStmt->pTableMeta->tableInfo.precision;
if (code == TSDB_CODE_SUCCESS && ctbFirst) {
for (int32_t i = 0; code == TSDB_CODE_SUCCESS && i < numOfTagTokens; ++i) {
SToken* pTagToken = (SToken*)(tagTokens + i);
SSchema* pTagSchema = tagSchemas[i];
code = checkAndTrimValue(pTagToken, pCxt->tmpTokenBuf, &pCxt->msg, pTagSchema->type);
if (TK_NK_VARIABLE == pTagToken->type) {
if (code == TSDB_CODE_SUCCESS && TK_NK_VARIABLE == pTagToken->type) {
code = buildInvalidOperationMsg(&pCxt->msg, "not expected tag");
}
if (code == TSDB_CODE_SUCCESS) {
code = parseTagValue(pCxt, pStmt, NULL, pTagSchema, pTagToken, pStbRowsCxt->aTagNames, pStbRowsCxt->aTagVals,
code = parseTagValue(&pCxt->msg, NULL, precision, pTagSchema, pTagToken, pStbRowsCxt->aTagNames, pStbRowsCxt->aTagVals,
&pStbRowsCxt->pTag);
}
}
@ -1760,11 +1756,12 @@ static int32_t doGetStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
const SBoundColInfo* pCols, const SSchema* pSchemas,
SToken* tagTokens, SSchema** tagSchemas, int* pNumOfTagTokens, bool* bFoundTbName) {
int32_t code = TSDB_CODE_SUCCESS;
SArray* pTagNames = pStbRowsCxt->aTagNames;
SArray* pTagVals = pStbRowsCxt->aTagVals;
bool canParseTagsAfter = !pStbRowsCxt->pTagCond && !pStbRowsCxt->hasTimestampTag;
SArray* pTagNames = pStbRowsCxt->aTagNames;
SArray* pTagVals = pStbRowsCxt->aTagVals;
bool canParseTagsAfter = !pStbRowsCxt->pTagCond && !pStbRowsCxt->hasTimestampTag;
int32_t numOfCols = getNumOfColumns(pStbRowsCxt->pStbMeta);
int32_t tbnameIdx = getTbnameSchemaIndex(pStbRowsCxt->pStbMeta);
uint8_t precision = getTableInfo(pStbRowsCxt->pStbMeta).precision;
for (int i = 0; i < pCols->numOfBound && (code) == TSDB_CODE_SUCCESS; ++i) {
const char* pTmpSql = *ppSql;
bool ignoreComma = false;
@ -1782,7 +1779,7 @@ static int32_t doGetStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
if (pCols->pColIndex[i] < numOfCols) {
const SSchema* pSchema = &pSchemas[pCols->pColIndex[i]];
SColVal* pVal = taosArrayGet(pStbRowsCxt->aColVals, pCols->pColIndex[i]);
code = parseValueToken(pCxt, ppSql, pToken, (SSchema*)pSchema, getTableInfo(pStbRowsCxt->pStbMeta).precision, pVal);
code = parseValueToken(pCxt, ppSql, pToken, (SSchema*)pSchema, precision, pVal);
if (TK_NK_VARIABLE == pToken->type) {
code = buildInvalidOperationMsg(&pCxt->msg, "not expected row value");
}
@ -1794,11 +1791,11 @@ static int32_t doGetStbRowValues(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
++(*pNumOfTagTokens);
} else {
code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg, pTagSchema->type);
if (TK_NK_VARIABLE == pToken->type) {
if (code == TSDB_CODE_SUCCESS && TK_NK_VARIABLE == pToken->type) {
code = buildInvalidOperationMsg(&pCxt->msg, "not expected row value");
}
if (code == TSDB_CODE_SUCCESS) {
code = parseTagValue(pCxt, pStmt, ppSql, (SSchema*)pTagSchema, pToken, pTagNames, pTagVals, &pStbRowsCxt->pTag);
code = parseTagValue(&pCxt->msg, ppSql, precision, (SSchema*)pTagSchema, pToken, pTagNames, pTagVals, &pStbRowsCxt->pTag);
}
}
}

View File

@ -1517,12 +1517,13 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal,
void* data = NULL;
uint32_t size = 0;
bool isHexChar = isHex(pVal->literal, strlen(pVal->literal));
uint32_t vlen = strlen(pVal->literal);
bool isHexChar = isHex(pVal->literal, vlen);
if (isHexChar) {
if (!isValidateHex(pVal->literal, strlen(pVal->literal))) {
if (!isValidateHex(pVal->literal, vlen)) {
return TSDB_CODE_PAR_INVALID_VARBINARY;
}
if (taosHex2Ascii(pVal->literal, strlen(pVal->literal), &data, &size) < 0) {
if (taosHex2Ascii(pVal->literal, vlen, &data, &size) < 0) {
return TSDB_CODE_OUT_OF_MEMORY;
}
} else {
@ -10025,75 +10026,6 @@ static int32_t createCastFuncForTag(STranslateContext* pCxt, SNode* pNode, SData
return code;
}
static int32_t createTagValFromExpr(STranslateContext* pCxt, SDataType targetDt, SNode* pNode, SValueNode** pVal) {
SNode* pCast = NULL;
int32_t code = createCastFuncForTag(pCxt, pNode, targetDt, &pCast);
SNode* pNew = NULL;
if (TSDB_CODE_SUCCESS == code) {
code = scalarCalculateConstants(pCast, &pNew);
}
if (TSDB_CODE_SUCCESS == code) {
pCast = pNew;
if (QUERY_NODE_VALUE != nodeType(pCast)) {
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pNode)->aliasName);
}
}
if (TSDB_CODE_SUCCESS == code) {
*pVal = (SValueNode*)pCast;
} else {
nodesDestroyNode(pCast);
}
return code;
}
static int32_t createTagValFromVal(STranslateContext* pCxt, SDataType targetDt, SNode* pNode, SValueNode** pVal) {
SValueNode* pTempVal = (SValueNode*)nodesCloneNode(pNode);
if (NULL == pTempVal) {
return TSDB_CODE_OUT_OF_MEMORY;
}
if (DEAL_RES_ERROR == translateValueImpl(pCxt, pTempVal, targetDt, true)) {
nodesDestroyNode((SNode*)pTempVal);
return pCxt->errCode;
}
*pVal = pTempVal;
return TSDB_CODE_SUCCESS;
}
static int32_t createTagVal(STranslateContext* pCxt, uint8_t precision, SSchema* pSchema, SNode* pNode,
SValueNode** pVal) {
if (QUERY_NODE_VALUE == nodeType(pNode)) {
return createTagValFromVal(pCxt, schemaToDataType(precision, pSchema), pNode, pVal);
} else {
return createTagValFromExpr(pCxt, schemaToDataType(precision, pSchema), pNode, pVal);
}
}
static int32_t buildJsonTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SValueNode* pVal, SArray* pTagArray,
STag** ppTag) {
if (pVal->literal && strlen(pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
}
return parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf);
}
static int32_t buildNormalTagVal(STranslateContext* pCxt, SSchema* pTagSchema, SValueNode* pVal, SArray* pTagArray) {
if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
void* nodeVal = nodesGetValueFromNode(pVal);
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
// strcpy(val.colName, pTagSchema->name);
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
val.pData = varDataVal(nodeVal);
val.nData = varDataLen(nodeVal);
} else {
memcpy(&val.i64, nodeVal, pTagSchema->bytes);
}
taosArrayPush(pTagArray, &val);
}
return TSDB_CODE_SUCCESS;
}
static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta,
STag** ppTag, SArray* tagName) {
int32_t numOfTags = getNumOfTags(pSuperTableMeta);
@ -10109,42 +10041,56 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
int32_t code = TSDB_CODE_SUCCESS;
bool isJson = false;
SNodeList* pVals = NULL;
SNode * pTag = NULL, *pNode = NULL;
FORBOTH(pTag, pStmt->pSpecificTags, pNode, pStmt->pValsOfTags) {
SColumnNode* pCol = (SColumnNode*)pTag;
SSchema* pSchema = getTagSchema(pSuperTableMeta, pCol->colName);
if (NULL == pSchema) {
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName);
}
SValueNode* pVal = NULL;
bool isJson = false;
SNode * pTagNode = NULL, *pNode = NULL;
uint8_t precision = pSuperTableMeta->tableInfo.precision;
SToken token;
char tokenBuf[TSDB_MAX_TAGS_LEN];
const char* tagStr = NULL;
FORBOTH(pTagNode, pStmt->pSpecificTags, pNode, pStmt->pValsOfTags) {
tagStr = ((SValueNode*)pNode)->literal;
NEXT_TOKEN_WITH_PREV(tagStr, token);
SSchema* pSchema = NULL;
if (TSDB_CODE_SUCCESS == code) {
code = createTagVal(pCxt, pSuperTableMeta->tableInfo.precision, pSchema, pNode, &pVal);
if ((pSchema = getTagSchema(pSuperTableMeta, ((SColumnNode*)pTagNode)->colName))) {
code = checkAndTrimValue(&token, tokenBuf, &pCxt->msgBuf, pSchema->type);
if (TSDB_CODE_SUCCESS == code && TK_NK_VARIABLE == token.type) {
code = TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
}
} else {
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, ((SColumnNode*)pTagNode)->colName);
}
}
if (TSDB_CODE_SUCCESS == code) {
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
isJson = true;
code = buildJsonTagVal(pCxt, pSchema, pVal, pTagArray, ppTag);
taosArrayPush(tagName, pCol->colName);
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
code = buildNormalTagVal(pCxt, pSchema, pVal, pTagArray);
taosArrayPush(tagName, pCol->colName);
}
code = parseTagValue(&pCxt->msgBuf, &tagStr, precision, pSchema, &token, tagName, pTagArray, ppTag);
}
if (TSDB_CODE_SUCCESS == code) {
NEXT_VALID_TOKEN(tagStr, token);
if (token.n != 0) {
code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values", token.z);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeAppend(&pVals, (SNode*)pVal);
}
if (TSDB_CODE_SUCCESS != code) {
break;
}
}
if (TSDB_CODE_SUCCESS == code && !isJson) {
code = tTagNew(pTagArray, 1, false, ppTag);
}
nodesDestroyList(pVals);
for (int i = 0; i < taosArrayGetSize(pTagArray); ++i) {
STagVal* p = (STagVal*)taosArrayGet(pTagArray, i);
if (IS_VAR_DATA_TYPE(p->type)) {
taosMemoryFreeClear(p->pData);
}
}
taosArrayDestroy(pTagArray);
return code;
}
@ -10162,51 +10108,52 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
int32_t code = TSDB_CODE_SUCCESS;
bool isJson = false;
int32_t index = 0;
SSchema* pTagSchemas = getTableTagSchema(pSuperTableMeta);
SNodeList* pVals = NULL;
SNode* pNode;
bool isJson = false;
SNode* pNode;
uint8_t precision = pSuperTableMeta->tableInfo.precision;
SSchema* pTagSchema = getTableTagSchema(pSuperTableMeta);
SToken token;
char tokenBuf[TSDB_MAX_TAGS_LEN];
const char* tagStr = NULL;
FOREACH(pNode, pStmt->pValsOfTags) {
SValueNode* pVal = NULL;
SSchema* pTagSchema = pTagSchemas + index;
code = createTagVal(pCxt, pSuperTableMeta->tableInfo.precision, pTagSchema, pNode, &pVal);
tagStr = ((SValueNode*)pNode)->literal;
NEXT_TOKEN_WITH_PREV(tagStr, token);
code = checkAndTrimValue(&token, tokenBuf, &pCxt->msgBuf, pTagSchema->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) {
if (pTagSchema->type == TSDB_DATA_TYPE_JSON) {
isJson = true;
code = buildJsonTagVal(pCxt, pTagSchema, pVal, pTagArray, ppTag);
if (TSDB_CODE_SUCCESS != code) {
nodesDestroyNode((SNode*)pVal);
}
taosArrayPush(tagName, pTagSchema->name);
} else if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL && !pVal->isNull) {
char* tmpVal = nodesGetValueFromNode(pVal);
STagVal val = {.cid = pTagSchema->colId, .type = pTagSchema->type};
// strcpy(val.colName, pTagSchema->name);
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
val.pData = varDataVal(tmpVal);
val.nData = varDataLen(tmpVal);
} else {
memcpy(&val.i64, tmpVal, pTagSchema->bytes);
}
taosArrayPush(pTagArray, &val);
taosArrayPush(tagName, pTagSchema->name);
}
code = parseTagValue(&pCxt->msgBuf, &tagStr, precision, pTagSchema, &token, tagName, pTagArray, ppTag);
}
if (TSDB_CODE_SUCCESS == code) {
NEXT_VALID_TOKEN(tagStr, token);
if (token.n != 0) {
code = buildSyntaxErrMsg(&pCxt->msgBuf, "not expected tags values", token.z);
}
}
if (TSDB_CODE_SUCCESS == code) {
code = nodesListMakeAppend(&pVals, (SNode*)pVal);
}
if (TSDB_CODE_SUCCESS != code) {
break;
}
++index;
++pTagSchema;
}
if (TSDB_CODE_SUCCESS == code && !isJson) {
code = tTagNew(pTagArray, 1, false, ppTag);
}
nodesDestroyList(pVals);
for (int32_t i = 0; i < TARRAY_SIZE(pTagArray); ++i) {
STagVal* p = (STagVal*)TARRAY_GET_ELEM(pTagArray, i);
if (IS_VAR_DATA_TYPE(p->type)) {
taosMemoryFreeClear(p->pData);
}
}
taosArrayDestroy(pTagArray);
return code;
}
@ -10467,58 +10414,65 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE, "Invalid tag name: %s",
pStmt->colName);
}
pReq->tagName = taosStrdup(pStmt->colName);
if (NULL == pReq->tagName) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pReq->pTagArray = taosArrayInit(1, sizeof(STagVal));
if (NULL == pReq->pTagArray) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pReq->colId = pSchema->colId;
pReq->tagType = pSchema->type;
SDataType targetDt = schemaToDataType(pTableMeta->tableInfo.precision, pSchema);
int32_t code = 0;
if (QUERY_NODE_VALUE != pStmt->pVal->node.type) {
SValueNode* pVal = NULL;
pCxt->errCode = createTagValFromExpr(pCxt, targetDt, (SNode*)pStmt->pVal, &pVal);
if (pCxt->errCode) {
return pCxt->errCode;
}
nodesDestroyNode((SNode*)pStmt->pVal);
pStmt->pVal = pVal;
} else if (DEAL_RES_ERROR == translateValueImpl(pCxt, pStmt->pVal, targetDt, true)) {
return pCxt->errCode;
}
pReq->tagType = targetDt.type;
if (targetDt.type == TSDB_DATA_TYPE_JSON) {
if (pStmt->pVal->literal &&
strlen(pStmt->pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pStmt->pVal->literal);
}
SArray* pTagVals = taosArrayInit(1, sizeof(STagVal));
int32_t code = TSDB_CODE_SUCCESS;
STag* pTag = NULL;
code = parseJsontoTagData(pStmt->pVal->literal, pTagVals, &pTag, &pCxt->msgBuf);
taosArrayDestroy(pTagVals);
if (code != TSDB_CODE_SUCCESS) {
return code;
}
pReq->nTagVal = pTag->len;
pReq->pTagVal = (uint8_t*)pTag;
pStmt->pVal->datum.p = (char*)pTag; // for free
} else {
pReq->isNull = pStmt->pVal->isNull;
pReq->nTagVal = pStmt->pVal->node.resType.bytes;
pReq->pTagVal = nodesGetValueFromNode(pStmt->pVal);
// data and length are seperated for new tag format STagVal
if (IS_VAR_DATA_TYPE(pStmt->pVal->node.resType.type)) {
pReq->nTagVal = varDataLen(pReq->pTagVal);
pReq->pTagVal = varDataVal(pReq->pTagVal);
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);
}
}
return TSDB_CODE_SUCCESS;
if (TSDB_CODE_SUCCESS == code) {
code = parseTagValue(&pCxt->msgBuf, &tagStr, pTableMeta->tableInfo.precision, pSchema, &token, NULL,
pReq->pTagArray, &pTag);
}
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) {
pReq->nTagVal = pTag->len;
pReq->pTagVal = (uint8_t*)pTag;
pStmt->pVal->datum.p = (char*)pTag; // for free
} 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 buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
@ -10742,6 +10696,13 @@ static void destoryAlterTbReq(SVAlterTbReq* pReq) {
taosMemoryFree(pReq->colNewName);
taosMemoryFree(pReq->tagName);
taosMemoryFree(pReq->newComment);
for (int i = 0; i < taosArrayGetSize(pReq->pTagArray); ++i) {
STagVal* p = (STagVal*)taosArrayGet(pReq->pTagArray, i);
if (IS_VAR_DATA_TYPE(p->type)) {
taosMemoryFreeClear(p->pData);
}
}
taosArrayDestroy(pReq->pTagArray);
}
static int32_t rewriteAlterTableImpl(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,

File diff suppressed because it is too large Load Diff

View File

@ -485,7 +485,7 @@ bool isHex(const char* z, uint32_t n){
}
bool isValidateHex(const char* z, uint32_t n){
if(n % 2 != 0) return false;
if((n & 1) != 0) return false;
for(size_t i = HEX_PREFIX_LEN; i < n; i++){
if(isxdigit(z[i]) == 0){
return false;
@ -494,13 +494,16 @@ bool isValidateHex(const char* z, uint32_t n){
return true;
}
int32_t taosHex2Ascii(const char *z, uint32_t n, void** data, uint32_t* size){
n -= HEX_PREFIX_LEN; // remove 0x
int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) {
n -= HEX_PREFIX_LEN; // remove 0x
z += HEX_PREFIX_LEN;
*size = n / HEX_PREFIX_LEN;
if(*size == 0) return 0;
uint8_t* tmp = (uint8_t*)taosMemoryCalloc(*size, 1);
if(tmp == NULL) return -1;
if (*size == 0) {
if (!(*data = taosStrdup(""))) return -1;
return 0;
}
uint8_t *tmp = (uint8_t *)taosMemoryCalloc(*size, 1);
if (tmp == NULL) return -1;
int8_t num = 0;
uint8_t *byte = tmp + *size - 1;

View File

@ -613,7 +613,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_GET_META_ERROR, "Fail to get table i
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, "Not unique table/alias")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED_FUNC, "System table not allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_SYSTABLE_NOT_ALLOWED, "System table not allowed")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VARBINARY, "Invalidate varbinary value")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_VARBINARY, "Invalid varbinary value")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_IP_RANGE, "Invalid IPV4 address ranges")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INTERNAL_ERROR, "Parser internal error")
TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Invalid stream query")

View File

@ -327,6 +327,7 @@
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/db_tb_name_check.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/InsertFuturets.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/insert_wide_column.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/insert_column_value.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/rowlength64k_benchmark.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/rowlength64k.py
,,y,system-test,./pytest.sh python3 ./test.py -f 1-insert/rowlength64k.py -R

View File

@ -28,10 +28,26 @@ if $data05 != NULL then
return -1
endi
sql_error create table st_bigint_2 using mt_bigint tags ('NULL')
sql_error create table st_bigint_3 using mt_bigint tags ('NULL')
sql_error create table st_bigint_4 using mt_bigint tags ("NULL")
sql_error create table st_bigint_5 using mt_bigint tags ("NULL")
sql create table st_bigint_2 using mt_bigint tags ('NULL')
sql show tags from st_bigint_2
if $data05 != NULL then
return -1
endi
sql create table st_bigint_3 using mt_bigint tags ('NULL')
sql show tags from st_bigint_3
if $data05 != NULL then
return -1
endi
sql create table st_bigint_4 using mt_bigint tags ("NULL")
sql show tags from st_bigint_4
if $data05 != NULL then
return -1
endi
sql create table st_bigint_5 using mt_bigint tags ("NULL")
sql show tags from st_bigint_5
if $data05 != NULL then
return -1
endi
sql create table st_bigint_6 using mt_bigint tags (-9223372036854775807)
sql show tags from st_bigint_6
@ -97,6 +113,39 @@ if $data01 != NULL then
return -1
endi
sql insert into st_bigint_2 values (now, NULL)
sql select * from st_bigint_2
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_bigint_3 values (now, NULL)
sql select * from st_bigint_3
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_bigint_4 values (now, NULL)
sql select * from st_bigint_4
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_bigint_5 values (now, NULL)
sql select * from st_bigint_5
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_bigint_6 values (now, 9223372036854775807)
sql select * from st_bigint_6
if $rows != 1 then
@ -348,7 +397,7 @@ sql_error create table st_bigint_e0 using mt_bigint tags ("123abc")
sql_error create table st_bigint_e0 using mt_bigint tags (abc)
sql_error create table st_bigint_e0 using mt_bigint tags ("abc")
sql_error create table st_bigint_e0 using mt_bigint tags (" ")
sql create table st_bigint_e0_error using mt_bigint tags ('')
sql_error create table st_bigint_e0_error using mt_bigint tags ('')
sql create table st_bigint_e0 using mt_bigint tags (123)
sql create table st_bigint_e1 using mt_bigint tags (123)
@ -401,7 +450,7 @@ sql_error insert into st_bigint_e20 using mt_bigint tags ("123abc") values (now,
sql_error insert into st_bigint_e22 using mt_bigint tags (abc) values (now, -033)
sql_error insert into st_bigint_e23 using mt_bigint tags ("abc") values (now, -033)
sql_error insert into st_bigint_e24 using mt_bigint tags (" ") values (now, -033)
sql insert into st_bigint_e25 using mt_bigint tags ('') values (now, -033)
sql_error insert into st_bigint_e25 using mt_bigint tags ('') values (now, -033)
sql insert into st_bigint_e13 using mt_bigint tags (033) values (now, 00062)
sql insert into st_bigint_e14 using mt_bigint tags (033) values (now, 00062)
@ -417,15 +466,15 @@ sql insert into st_bigint_e23 using mt_bigint tags (033) values (now, 00062)
sql insert into st_bigint_e24 using mt_bigint tags (033) values (now, 00062)
sql insert into st_bigint_e25 using mt_bigint tags (033) values (now, 00062)
#sql alter table st_bigint_e13 set tag tagname=9223372036854775808
#sql_error alter table st_bigint_e14 set tag tagname=-9223372036854775808
#sql alter table st_bigint_e15 set tag tagname=92233720368547758080
#sql_error alter table st_bigint_e16 set tag tagname=-92233720368547758080
#sql_error alter table st_bigint_e19 set tag tagname=123abc
#sql_error alter table st_bigint_e20 set tag tagname="123abc"
#sql_error alter table st_bigint_e22 set tag tagname=abc
#sql_error alter table st_bigint_e23 set tag tagname="abc"
#sql_error alter table st_bigint_e24 set tag tagname=" "
#sql_error alter table st_bigint_e25 set tag tagname=''
sql_error alter table st_bigint_e13 set tag tagname=9223372036854775808
sql alter table st_bigint_e14 set tag tagname=-9223372036854775808
sql_error alter table st_bigint_e15 set tag tagname=92233720368547758080
sql_error alter table st_bigint_e16 set tag tagname=-92233720368547758080
sql_error alter table st_bigint_e19 set tag tagname=123abc
sql_error alter table st_bigint_e20 set tag tagname="123abc"
sql_error alter table st_bigint_e22 set tag tagname=abc
sql_error alter table st_bigint_e23 set tag tagname="abc"
sql_error alter table st_bigint_e24 set tag tagname=" "
sql_error alter table st_bigint_e25 set tag tagname=''
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -31,26 +31,26 @@ if $data05 != NULL then
endi
sql create table st_bool_2 using mt_bool tags ('NULL')
sql show tags from st_bool_2
if $data05 != false then
print ==3== expect: false, actually: $data05
if $data05 != NULL then
print ==3== expect: NULL, actually: $data05
return -1
endi
sql create table st_bool_3 using mt_bool tags ('NULL')
sql show tags from st_bool_3
if $data05 != false then
print ==4== expect: false, actually: $data05
if $data05 != NULL then
print ==4== expect: NULL, actually: $data05
return -1
endi
sql create table st_bool_4 using mt_bool tags ("NULL")
sql show tags from st_bool_4
if $data05 != false then
print ==5== expect: false, actually: $data05
if $data05 != NULL then
print ==5== expect: NULL, actually: $data05
return -1
endi
sql create table st_bool_5 using mt_bool tags ("NULL")
sql show tags from st_bool_5
if $data05 != false then
print ==6== expect: false, actually: $data05
if $data05 != NULL then
print ==6== expect: NULL, actually: $data05
return -1
endi
sql create table st_bool_6 using mt_bool tags ("true")
@ -581,12 +581,12 @@ endi
# case 04: illegal input
sql_error create table st_bool_e0 using mt_bool tags (123abc)
sql create table st_bool_e1 using mt_bool tags ("123abc")
sql create table st_bool_e2 using mt_bool tags ("123")
sql_error create table st_bool_e1 using mt_bool tags ("123abc")
sql_error create table st_bool_e2 using mt_bool tags ("123")
sql_error create table st_bool_e3 using mt_bool tags (abc)
sql create table st_bool_e4 using mt_bool tags ("abc")
sql create table st_bool_e5 using mt_bool tags (" ")
sql create table st_bool_e6 using mt_bool tags ('')
sql_error create table st_bool_e4 using mt_bool tags ("abc")
sql_error create table st_bool_e5 using mt_bool tags (" ")
sql_error create table st_bool_e6 using mt_bool tags ('')
sql create table st_bool_f0 using mt_bool tags (true)
sql create table st_bool_f1 using mt_bool tags (true)
@ -629,11 +629,11 @@ sql insert into st_bool_i5 using mt_bool tags (1) values (now, 1)
sql insert into st_bool_i6 using mt_bool tags (1) values (now, 1)
sql_error alter table st_bool_i0 set tag tagname=123abc
sql alter table st_bool_i1 set tag tagname="123abc"
sql alter table st_bool_i2 set tag tagname="123"
sql_error alter table st_bool_i1 set tag tagname="123abc"
sql_error alter table st_bool_i2 set tag tagname="123"
sql_error alter table st_bool_i3 set tag tagname=abc
sql alter table st_bool_i4 set tag tagname="abc"
sql alter table st_bool_i5 set tag tagname=" "
sql alter table st_bool_i6 set tag tagname=''
sql_error alter table st_bool_i4 set tag tagname="abc"
sql_error alter table st_bool_i5 set tag tagname=" "
sql_error alter table st_bool_i6 set tag tagname=''
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -28,22 +28,22 @@ if $data05 != NULL then
endi
sql create table st_double_2 using mt_double tags ('NULL')
sql show tags from st_double_2
if $data05 != 0.000000000 then
if $data05 != NULL then
return -1
endi
sql create table st_double_3 using mt_double tags ('NULL')
sql show tags from st_double_3
if $data05 != 0.000000000 then
if $data05 != NULL then
return -1
endi
sql create table st_double_4 using mt_double tags ("NULL")
sql show tags from st_double_4
if $data05 != 0.000000000 then
if $data05 != NULL then
return -1
endi
sql create table st_double_5 using mt_double tags ("NULL")
sql show tags from st_double_5
if $data05 != 0.000000000 then
if $data05 != NULL then
return -1
endi
sql create table st_double_6 using mt_double tags (-123.321)
@ -445,11 +445,11 @@ sql_error create table st_double_e0 using mt_double tags (-31.7976931348623157e+
#sql_error create table st_double_e0 using mt_double tags (12.80) truncate integer part
#sql_error create table st_double_e0 using mt_double tags (-11.80)
sql_error create table st_double_e0 using mt_double tags (123abc)
sql create table st_double_e0_1 using mt_double tags ("123abc")
sql_error create table st_double_e0_1 using mt_double tags ("123abc")
sql_error create table st_double_e0 using mt_double tags (abc)
sql create table st_double_e0_2 using mt_double tags ("abc")
sql create table st_double_e0_3 using mt_double tags (" ")
sql create table st_double_e0_4 using mt_double tags ('')
sql_error create table st_double_e0_2 using mt_double tags ("abc")
sql_error create table st_double_e0_3 using mt_double tags (" ")
sql_error create table st_double_e0_4 using mt_double tags ('')
sql create table st_double_e0 using mt_double tags (123)
sql create table st_double_e1 using mt_double tags (123)
@ -502,7 +502,8 @@ sql_error insert into st_double_e20 using mt_double tags ("123abc") values (now,
sql_error insert into st_double_e22 using mt_double tags (abc) values (now, -033)
sql_error insert into st_double_e23 using mt_double tags ("abc") values (now, -033)
sql_error insert into st_double_e24 using mt_double tags (" ") values (now, -033)
sql insert into st_double_e25 using mt_double tags ('') values (now, -033)
sql_error insert into st_double_e25 using mt_double tags ('') values (now, -033)
sql insert into st_double_e20 using mt_double tags ("123") values (now, -033)
sql insert into st_double_e13 using mt_double tags (033) values (now, 00062)
sql insert into st_double_e14 using mt_double tags (033) values (now, 00062)
@ -523,10 +524,11 @@ sql_error alter table st_double_e14 set tag tagname=-1.8976931348623157e+308
sql_error alter table st_double_e15 set tag tagname=131.7976931348623157e+308
sql_error alter table st_double_e16 set tag tagname=-131.7976931348623157e+308
sql_error alter table st_double_e19 set tag tagname=123abc
sql alter table st_double_e20 set tag tagname="123abc"
sql_error alter table st_double_e20 set tag tagname="123abc"
sql_error alter table st_double_e22 set tag tagname=abc
sql alter table st_double_e23 set tag tagname="abc"
sql alter table st_double_e24 set tag tagname=" "
sql alter table st_double_e25 set tag tagname=''
sql_error alter table st_double_e23 set tag tagname="abc"
sql_error alter table st_double_e24 set tag tagname=" "
sql_error alter table st_double_e25 set tag tagname=''
sql alter table st_double_e25 set tag tagname='123'
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -29,22 +29,22 @@ if $data05 != NULL then
endi
sql create table st_float_2 using mt_float tags ('NULL')
sql show tags from st_float_2
if $data05 != 0.00000 then
if $data05 != NULL then
return -1
endi
sql create table st_float_3 using mt_float tags ('NULL')
sql show tags from st_float_3
if $data05 != 0.00000 then
if $data05 != NULL then
return -1
endi
sql create table st_float_4 using mt_float tags ("NULL")
sql show tags from st_float_4
if $data05 != 0.00000 then
if $data05 != NULL then
return -1
endi
sql create table st_float_5 using mt_float tags ("NULL")
sql show tags from st_float_5
if $data05 != 0.00000 then
if $data05 != NULL then
return -1
endi
sql create table st_float_6 using mt_float tags (-123.321)
@ -477,11 +477,11 @@ sql_error create table st_float_e0 using mt_float tags (-333.40282347e+38)
#sql_error create table st_float_e0 using mt_float tags (12.80) truncate integer part
#sql_error create table st_float_e0 using mt_float tags (-11.80)
sql_error create table st_float_e0 using mt_float tags (123abc)
sql create table st_float_e0_1 using mt_float tags ("123abc")
sql_error create table st_float_e0_1 using mt_float tags ("123abc")
sql_error create table st_float_e0 using mt_float tags (abc)
sql create table st_float_e0_2 using mt_float tags ("abc")
sql create table st_float_e0_3 using mt_float tags (" ")
sql create table st_float_e0_4 using mt_float tags ('')
sql_error create table st_float_e0_2 using mt_float tags ("abc")
sql_error create table st_float_e0_3 using mt_float tags (" ")
sql_error create table st_float_e0_4 using mt_float tags ('')
sql create table st_float_e0 using mt_float tags (123)
sql create table st_float_e1 using mt_float tags (123)
@ -534,7 +534,7 @@ sql_error insert into st_float_e20 using mt_float tags ("123abc") values (now, -
sql_error insert into st_float_e22 using mt_float tags (abc) values (now, -033)
sql_error insert into st_float_e23 using mt_float tags ("abc") values (now, -033)
sql_error insert into st_float_e24 using mt_float tags (" ") values (now, -033)
sql insert into st_float_e25_3 using mt_float tags ('') values (now, -033)
sql_error insert into st_float_e25_3 using mt_float tags ('') values (now, -033)
sql insert into st_float_e13 using mt_float tags (033) values (now, 00062)
sql insert into st_float_e14 using mt_float tags (033) values (now, 00062)
@ -555,10 +555,10 @@ sql_error alter table st_float_e14 set tag tagname=-3.50282347e+38
sql_error alter table st_float_e15 set tag tagname=13.40282347e+38
sql_error alter table st_float_e16 set tag tagname=-13.40282347e+38
sql_error alter table st_float_e19 set tag tagname=123abc
sql alter table st_float_e20 set tag tagname="123abc"
sql_error alter table st_float_e20 set tag tagname="123abc"
sql_error alter table st_float_e22 set tag tagname=abc
sql alter table st_float_e23 set tag tagname="abc"
sql alter table st_float_e24 set tag tagname=" "
sql alter table st_float_e25 set tag tagname=''
sql_error alter table st_float_e23 set tag tagname="abc"
sql_error alter table st_float_e24 set tag tagname=" "
sql_error alter table st_float_e25 set tag tagname=''
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -28,10 +28,26 @@ if $data05 != NULL then
return -1
endi
sql_error create table st_int_2 using mt_int tags ('NULL')
sql_error create table st_int_3 using mt_int tags ('NULL')
sql_error create table st_int_4 using mt_int tags ("NULL")
sql_error create table st_int_5 using mt_int tags ("NULL")
sql create table st_int_2 using mt_int tags ('NULL')
sql show tags from st_int_2
if $data05 != NULL then
return -1
endi
sql create table st_int_3 using mt_int tags ('NULL')
sql show tags from st_int_3
if $data05 != NULL then
return -1
endi
sql create table st_int_4 using mt_int tags ("NULL")
sql show tags from st_int_4
if $data05 != NULL then
return -1
endi
sql create table st_int_5 using mt_int tags ("NULL")
sql show tags from st_int_5
if $data05 != NULL then
return -1
endi
sql create table st_int_6 using mt_int tags (-2147483647)
sql show tags from st_int_6
@ -346,7 +362,7 @@ sql_error create table st_int_e0 using mt_int tags ("123abc")
sql_error create table st_int_e0 using mt_int tags (abc)
sql_error create table st_int_e0 using mt_int tags ("abc")
sql_error create table st_int_e0 using mt_int tags (" ")
sql create table st_int_e0_err2 using mt_int tags ('')
sql_error create table st_int_e0_err2 using mt_int tags ('')
sql create table st_int_e0 using mt_int tags (123)
sql create table st_int_e1 using mt_int tags (123)
@ -399,7 +415,10 @@ sql_error insert into st_int_e20 using mt_int tags ("123abc") values (now, -033)
sql_error insert into st_int_e22 using mt_int tags (abc) values (now, -033)
sql_error insert into st_int_e23 using mt_int tags ("abc") values (now, -033)
sql_error insert into st_int_e24 using mt_int tags (" ") values (now, -033)
sql insert into st_int_e25_1 using mt_int tags ('') values (now, -033)
sql_error insert into st_int_e25_1 using mt_int tags ('') values (now, -033)
sql insert into st_int_e26_1 using mt_int tags ('123') values (now, -033)
sql insert into st_int_e27_1 using mt_int tags ('12.80') values (now, -033)
sql insert into st_int_e28_1 using mt_int tags ('-11.80') values (now, -033)
sql insert into st_int_e13 using mt_int tags (033) values (now, 00062)
sql insert into st_int_e14 using mt_int tags (033) values (now, 00062)
@ -424,6 +443,9 @@ sql_error alter table st_int_e20 set tag tagname="123abc"
sql_error alter table st_int_e22 set tag tagname=abc
sql_error alter table st_int_e23 set tag tagname="abc"
sql_error alter table st_int_e24 set tag tagname=" "
sql alter table st_int_e25 set tag tagname=''
sql_error alter table st_int_e25 set tag tagname=''
sql alter table st_int_e26_1 set tag tagname='123'
sql alter table st_int_e27_1 set tag tagname='12.80'
sql alter table st_int_e28_1 set tag tagname='-11.80'
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -31,10 +31,27 @@ if $data05 != NULL then
return -1
endi
sql_error create table st_smallint_2 using mt_smallint tags ('NULL')
sql_error create table st_smallint_3 using mt_smallint tags ('NULL')
sql_error create table st_smallint_4 using mt_smallint tags ("NULL")
sql_error create table st_smallint_5 using mt_smallint tags ("NULL")
sql create table st_smallint_2 using mt_smallint tags ('NULL')
sql show tags from st_smallint_2
if $data05 != NULL then
return -1
endi
sql create table st_smallint_3 using mt_smallint tags ('NULL')
sql show tags from st_smallint_3
if $data05 != NULL then
return -1
endi
sql create table st_smallint_4 using mt_smallint tags ("NULL")
sql show tags from st_smallint_4
if $data05 != NULL then
return -1
endi
sql create table st_smallint_5 using mt_smallint tags ("NULL")
sql show tags from st_smallint_5
if $data05 != NULL then
return -1
endi
sql create table st_smallint_6 using mt_smallint tags (-32767)
sql show tags from st_smallint_6
@ -349,7 +366,8 @@ sql_error create table st_smallint_e0 using mt_smallint tags ("123abc")
sql_error create table st_smallint_e0 using mt_smallint tags (abc)
sql_error create table st_smallint_e0 using mt_smallint tags ("abc")
sql_error create table st_smallint_e0 using mt_smallint tags (" ")
sql create table st_smallint_e0_1 using mt_smallint tags ('')
sql_error create table st_smallint_e0_1 using mt_smallint tags ('')
sql create table st_smallint_e0_2 using mt_smallint tags ('123')
sql create table st_smallint_e0 using mt_smallint tags (123)
sql create table st_smallint_e1 using mt_smallint tags (123)
@ -402,7 +420,8 @@ sql_error insert into st_smallint_e20 using mt_smallint tags ("123abc") values (
sql_error insert into st_smallint_e22 using mt_smallint tags (abc) values (now, -033)
sql_error insert into st_smallint_e23 using mt_smallint tags ("abc") values (now, -033)
sql_error insert into st_smallint_e24 using mt_smallint tags (" ") values (now, -033)
sql insert into st_smallint_e25 using mt_smallint tags ('') values (now, -033)
sql_error insert into st_smallint_e25 using mt_smallint tags ('') values (now, -033)
sql insert into st_smallint_e26 using mt_smallint tags ('123') values (now, -033)
sql insert into st_smallint_e13 using mt_smallint tags (033) values (now, 00062)
sql insert into st_smallint_e14 using mt_smallint tags (033) values (now, 00062)
@ -427,6 +446,7 @@ sql_error alter table st_smallint_e20 set tag tagname="123abc"
sql_error alter table st_smallint_e22 set tag tagname=abc
sql_error alter table st_smallint_e23 set tag tagname="abc"
sql_error alter table st_smallint_e24 set tag tagname=" "
sql alter table st_smallint_e25 set tag tagname=''
sql_error alter table st_smallint_e25 set tag tagname=''
sql alter table st_smallint_e26 set tag tagname='123'
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -29,10 +29,26 @@ if $data05 != NULL then
return -1
endi
sql_error create table st_tinyint_2 using mt_tinyint tags ('NULL')
sql_error create table st_tinyint_3 using mt_tinyint tags ('NULL')
sql_error create table st_tinyint_4 using mt_tinyint tags ("NULL")
sql_error create table st_tinyint_5 using mt_tinyint tags ("NULL")
sql create table st_tinyint_2 using mt_tinyint tags ('NULL')
sql show tags from st_tinyint_2
if $data05 != NULL then
return -1
endi
sql create table st_tinyint_3 using mt_tinyint tags ('NULL')
sql show tags from st_tinyint_3
if $data05 != NULL then
return -1
endi
sql create table st_tinyint_4 using mt_tinyint tags ("NULL")
sql show tags from st_tinyint_4
if $data05 != NULL then
return -1
endi
sql create table st_tinyint_5 using mt_tinyint tags ("NULL")
sql show tags from st_tinyint_5
if $data05 != NULL then
return -1
endi
sql create table st_tinyint_6 using mt_tinyint tags (-127)
sql show tags from st_tinyint_6
@ -97,6 +113,40 @@ endi
if $data01 != NULL then
return -1
endi
sql insert into st_tinyint_2 values (now, NULL)
sql select * from st_tinyint_2
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_tinyint_3 values (now, NULL)
sql select * from st_tinyint_3
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_tinyint_4 values (now, NULL)
sql select * from st_tinyint_4
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_tinyint_5 values (now, NULL)
sql select * from st_tinyint_5
if $rows != 1 then
return -1
endi
if $data01 != NULL then
return -1
endi
sql insert into st_tinyint_6 values (now, 127)
sql select * from st_tinyint_6
if $rows != 1 then
@ -347,7 +397,7 @@ sql_error create table st_tinyint_e0 using mt_tinyint tags ("123abc")
sql_error create table st_tinyint_e0 using mt_tinyint tags (abc)
sql_error create table st_tinyint_e0 using mt_tinyint tags ("abc")
sql_error create table st_tinyint_e0 using mt_tinyint tags (" ")
sql create table st_tinyint_e0_2 using mt_tinyint tags ('')
sql_error create table st_tinyint_e0_2 using mt_tinyint tags ('')
sql create table st_tinyint_e0 using mt_tinyint tags (123)
sql create table st_tinyint_e1 using mt_tinyint tags (123)
@ -400,7 +450,7 @@ sql_error insert into st_tinyint_e20 using mt_tinyint tags ("123abc") values (no
sql_error insert into st_tinyint_e22 using mt_tinyint tags (abc) values (now, -033)
sql_error insert into st_tinyint_e23 using mt_tinyint tags ("abc") values (now, -033)
sql_error insert into st_tinyint_e24 using mt_tinyint tags (" ") values (now, -033)
sql insert into st_tinyint_e25 using mt_tinyint tags ('') values (now, -033)
sql_error insert into st_tinyint_e25 using mt_tinyint tags ('') values (now, -033)
sql insert into st_tinyint_e13 using mt_tinyint tags (033) values (now, 00062)
sql insert into st_tinyint_e14 using mt_tinyint tags (033) values (now, 00062)
@ -425,6 +475,6 @@ sql_error alter table st_tinyint_e20 set tag tagname="123abc"
sql_error alter table st_tinyint_e22 set tag tagname=abc
sql_error alter table st_tinyint_e23 set tag tagname="abc"
sql_error alter table st_tinyint_e24 set tag tagname=" "
sql alter table st_tinyint_e25 set tag tagname=''
sql_error alter table st_tinyint_e25 set tag tagname=''
system sh/exec.sh -n dnode1 -s stop -x SIGINT

View File

@ -187,7 +187,7 @@ sql_error create table $tb using $mt tags (abc)
sql_error create table $tb using $mt tags ('abc')
sql drop table if exists $tb
sql reset query cache
sql_error create table $tb using $mt tags (1e1)
sql create table $tb using $mt tags (1e1)
sql_error create table $tb using $mt tags ('1e1')
sql_error create table $tb using $mt tags (2147483649)

View File

@ -139,8 +139,8 @@ if $data03 != 0 then
endi
### bool:
sql create table stx using mt2 tags ('NULL', '123aBc', 104, '123')
sql create table sty using mt2 tags ('NULL', '123aBc', 104, 'xtz')
sql_error create table stx using mt2 tags ('NULL', '123aBc', 104, '123')
sql_error create table sty using mt2 tags ('NULL', '123aBc', 104, 'xtz')
sql create table st4 using mt2 tags ('NULL', '123aBc', 104, 'NULL')
sql insert into st4 (ts, col1) values(now, 1)
sql select tag1,tag2,tag3,tag5 from st4
@ -156,7 +156,7 @@ endi
if $data02 != 104 then
return -1
endi
if $data03 != 0 then
if $data03 != NULL then
print ==6== expect: NULL, actually: $data03
return -1
endi
@ -306,8 +306,8 @@ if $data02 != NULL then
print ==10== expect: NULL, actually: $data02
return -1
endi
sql_error alter table st41 set tag tag_int = 'NULL'
sql alter table st41 set tag tag_int = ''
sql alter table st41 set tag tag_int = 'NULL'
sql_error alter table st41 set tag tag_int = ''
sql_error alter table st41 set tag tag_int = abc379
################### bool
@ -333,8 +333,8 @@ if $data03 != 1 then
endi
sql alter table st41 set tag tag_bool = 'NULL'
sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
if $data03 != 0 then
print ==14== expect: 0, actually: $data03
if $data03 != NULL then
print ==14== expect: NULL, actually: $data03
return -1
endi
sql alter table st41 set tag tag_bool = NULL
@ -343,8 +343,8 @@ if $data03 != NULL then
return -1
endi
sql alter table st41 set tag tag_bool = '123'
sql alter table st41 set tag tag_bool = ''
sql_error alter table st41 set tag tag_bool = '123'
sql_error alter table st41 set tag tag_bool = ''
sql_error alter table st41 set tag tag_bool = abc379
################### float
@ -396,10 +396,10 @@ if $data04 != -54.12346 then
print ==19== expect: -54.12346, actually : $data04
return -1
endi
sql alter table st41 set tag tag_float = ''
sql_error alter table st41 set tag tag_float = ''
sql alter table st41 set tag tag_float = 'abc'
sql alter table st41 set tag tag_float = '123abc'
sql_error alter table st41 set tag tag_float = 'abc'
sql_error alter table st41 set tag tag_float = '123abc'
sql_error alter table st41 set tag tag_float = abc
################### double
@ -428,14 +428,15 @@ if $data05 != NULL then
endi
sql alter table st41 set tag tag_double = 'NULL'
sql select tag_binary, tag_nchar, tag_int, tag_bool, tag_float, tag_double from st41
if $data05 != 0.000000000 then
print ==20== expect: 0.000000000, actually : $data05
if $data05 != NULL then
print ==20== expect: NULL, actually : $data05
return -1
endi
sql alter table st41 set tag tag_double = ''
sql alter table st41 set tag tag_double = 'abc'
sql alter table st41 set tag tag_double = '123abc'
sql_error alter table st41 set tag tag_double = ''
sql alter table st41 set tag tag_double = '123'
sql_error alter table st41 set tag tag_double = 'abc'
sql_error alter table st41 set tag tag_double = '123abc'
sql_error alter table st41 set tag tag_double = abc
################### bigint smallint tinyint
@ -459,8 +460,8 @@ if $data00 != -9223372036854775807 then
endi
sql alter table st51 set tag tag_bigint = -9223372036854775808
sql_error alter table st51 set tag tag_bigint = 'NULL'
sql alter table st51 set tag tag_bigint = ''
sql alter table st51 set tag tag_bigint = 'NULL'
sql_error alter table st51 set tag tag_bigint = ''
sql_error alter table st51 set tag tag_bigint = abc379
####
@ -480,8 +481,8 @@ if $data01 != -32767 then
endi
sql alter table st51 set tag tag_smallint = -32768
sql_error alter table st51 set tag tag_smallint = 'NULL'
sql alter table st51 set tag tag_smallint = ''
sql alter table st51 set tag tag_smallint = 'NULL'
sql_error alter table st51 set tag tag_smallint = ''
sql_error alter table st51 set tag tag_smallint = abc379
####
@ -499,8 +500,8 @@ if $data02 != -127 then
endi
sql alter table st51 set tag tag_tinyint = '-128'
sql_error alter table st51 set tag tag_tinyint = 128
sql_error alter table st51 set tag tag_tinyint = 'NULL'
sql alter table st51 set tag tag_tinyint = ''
sql alter table st51 set tag tag_tinyint = 'NULL'
sql_error alter table st51 set tag tag_tinyint = ''
sql_error alter table st51 set tag tag_tinyint = abc379
# test end

View File

@ -391,7 +391,7 @@ sql alter table $mt add tag tgcol6 bool
sql reset query cache
sql alter table $tb set tag tgcol4=4
sql alter table $tb set tag tgcol5='5'
sql alter table $tb set tag tgcol6='1'
sql_error alter table $tb set tag tgcol6='1'
sql reset query cache
sql select * from $mt where tgcol5 = '5'
@ -409,7 +409,7 @@ endi
if $data03 != 5 then
return -1
endi
if $data04 != 0 then
if $data04 != NULL then
return -1
endi

View File

@ -0,0 +1,159 @@
import datetime
from util.log import *
from util.sql import *
from util.cases import *
from util.common import *
from util.dnodes import *
from util.sqlset import *
DBNAME = "db"
class TDTestCase:
def init(self, conn, logSql, replicaVar=1):
self.replicaVar = int(replicaVar)
tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor())
tdSql.execute(f'drop database if exists db')
tdSql.execute(f'create database if not exists db vgroups 1')
def __create_tb(self, dbname="db"):
CREATE_STB_LIST = [ f"create table {dbname}.stb_vc (ts timestamp, c0 binary(50), c1 binary(50)) tags(t0 binary(50), t1 binary(50));",
f"create table {dbname}.stb_nc (ts timestamp, c0 nchar(50), c1 nchar(50)) tags(t0 nchar(50), t1 nchar(50));",
f"create table {dbname}.stb_ts (ts timestamp, c0 timestamp, c1 timestamp) tags(t0 timestamp, t1 timestamp);",
f"create table {dbname}.stb_bo (ts timestamp, c0 bool, c1 bool) tags(t0 bool, t1 bool);",
f"create table {dbname}.stb_vb (ts timestamp, c0 varbinary(50), c1 varbinary(50)) tags(t0 varbinary(50), t1 varbinary(50));",
f"create table {dbname}.stb_in (ts timestamp, c0 int, c1 int) tags(t0 int, t1 int);",
f"create table {dbname}.stb_fl (ts timestamp, c0 float, c1 float) tags(t0 float, t1 float);",
f"create table {dbname}.stb_db (ts timestamp, c0 float, c1 float) tags(t0 float, t1 float);",
f"create table {dbname}.stb_ge (ts timestamp, c0 geometry(512), c1 geometry(512)) tags(t0 geometry(512), t1 geometry(512));",
f"create table {dbname}.stb_js (ts timestamp, c0 int) tags(t0 json);" ]
for _stb in CREATE_STB_LIST:
tdSql.execute(_stb)
tdSql.query(f'show {dbname}.stables')
tdSql.checkRows(len(CREATE_STB_LIST))
def __insert_query_common(self, dbname="db", stbname="", ctbname="", oklist=[], kolist=[], okv=None):
for _l in kolist:
for _e in _l:
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, {okv})' %(_e))
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, %s)' %(_e))
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, %s)' %(_e, _e))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, %s) values(now, {okv}, {okv})' %(_e))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, {okv}) values(now, {okv}, {okv})' %(_e))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, {okv}) values(now, %s, {okv})' %(_e))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, {okv}) values(now, {okv}, %s)' %(_e))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, {okv}) values(now, %s, %s)' %(_e, _e))
tdSql.execute(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, {okv}) values(now, {okv}, {okv})')
tdSql.query(f'select * from {dbname}.{stbname}')
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
for _l in oklist:
for _e in _l:
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, {okv})' %(_e))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now + 0s, %s, {okv})' %(_e))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now + 1s, {okv}, %s)' %(_e))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now + 2s, %s, %s)' %(_e, _e))
tdSql.query(f'select * from {dbname}.{stbname}')
tdSql.checkRows(3)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, %s)' %(_e, _e))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now, %s, %s)' %(_e, _e))
tdSql.query(f'select * from {dbname}.{stbname}')
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, {okv}) values(now, %s, {okv})' %(_e, _e))
tdSql.query(f'select * from {dbname}.{stbname}')
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags({okv}, %s) values(now, {okv}, %s)' %(_e, _e))
tdSql.query(f'select * from {dbname}.{stbname}')
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags(%s, %s) values(now, %s, %s)' %(_e, _e, _e, _e))
tdSql.query(f'select * from {dbname}.{stbname}')
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
def __insert_query_exec(self):
STR_EMPTY = ['\'\'', "\"\""]
STR_INTEGER = ["\"123\"", '\'+12\'', '\'+0\'', '\'-0\'', '\'-128\'']
STR_FLOAT = ['\'123.1\'', "\"-23.001\"", "\"+0.001\"" ]
STR_FLOAT_E = ['\'1e1\'', "\"-0.1E+1\"", "\"1e-2\""]
STR_MISC = ['\' \'', "\" \"", "\"123ab\"", '\'123d\'', '\'-12s\'', '\'\x012\'', '\'x12\'', '\'x\'', '\'NULL \'']
STR_OPTR = ['\'1*10\'', '\'1+2\'', '\'-2-0\'','\'1%2\'', '\'2/0\'', '\'1&31\'']
STR_TSK = ['\'now\'', '\'today\'']
STR_TSK_MISC = ['\'now+1s\'', '\' now\'', '\'today \'', '\'today+1m\'', '\'today-1w\'']
STR_TSKP = ['\'now()\'', '\'today()\'']
STR_TSKP_MISC = ['\'now()+1s\'', '\' now()\'', '\'now( )\'', '\'today() \'', '\'today())\'', '\'today()+1m\'', '\'today()-1w\'']
STR_BOOL = ['\'true\'', '\'false\'', '\'TRUE\'', '\'FALSE\'', '\'tRuE\'', '\'falsE\'']
STR_TS = ["\"2024-02-01 00:00:01.001-08:00\"", "\'2024-02-01T00:00:01.001+09:00\'", "\"2024-02-01\"", "\'2024-02-02 00:00:01\'", "\'2024-02-02 00:00:01.009\'"]
STR_VARBIN = ['\'\\x\'', '\'\\x12ab\'']
STR_JSON = ['\'{\"k1\":\"v1\"}\'', '\'[]\'', '\'{}\'']
STR_GEO = ['\'POINT(1.0 1.0)\'', '\'LINESTRING(1.00 +2.0, 2.1 -3.2, 5.00 5.01)\'', '\'POLYGON((1.0 1.0, -2.0 +2.0, 1.0 1.0))\'' ]
STR_NULL = ['\'NuLl\'', '\'null\'', '\'NULL\'']
RAW_INTEGER = ['123', '+0123', '-0128', '+0', '-0', '0']
RAW_FLOAT = ['123.012', '-128.001', '-0.0', '0.0', '+0.0']
RAW_FLOAT_E = ['1e-100', "-1E-10", '+0.1E+2']
RAW_MISC = ['123abc', "123c", '-123d', '+', '-', ' *', ' /', '% ', '&', "|", "^", "&&", "||", "!", " =", 'now+1 s', 'now-1','now-1y','now+2 d',
'today+1 s', 'today-1','today-1y','today+2 d', 'now()+1 s', 'now()-1','now()-1y','now()+2 d', 'today()+1 s', 'today()-1','today()-1y','today()+2 d']
RAW_OPTR = ['1*10', '1+2', '-2-0','1%2', '2/0', '1&31']
RAW_TSK = [' now ', 'today ']
RAW_TSK_OPTR = [' now +1s', 'today + 2d']
RAW_TSKP = ['now( ) ', ' toDay() ']
RAW_TSKP_OPTR = [' noW ( ) + 1s', 'nOw( ) + 2D', 'NOW () + 000s', ' today()+1M', 'today( ) - 1w ', 'TodaY ( ) - 1U ']
RAW_BOOL = ['true', 'false', ' TRUE ', 'FALSE ', ' tRuE', ' falsE ']
RAW_NULL = ['NuLl', 'null', 'NULL', ' NULL ']
OK_VC = [STR_EMPTY, STR_INTEGER, STR_FLOAT, STR_FLOAT_E, STR_MISC, STR_TSK, STR_TSK_MISC, STR_TSKP, STR_TSKP_MISC, STR_BOOL, STR_TS, STR_VARBIN,
STR_JSON, STR_GEO, STR_NULL, RAW_INTEGER, RAW_FLOAT, RAW_FLOAT_E, RAW_TSK, RAW_BOOL, RAW_NULL]
KO_VC = [RAW_MISC, RAW_OPTR, RAW_TSK_OPTR, RAW_TSKP, RAW_TSKP_OPTR]
OK_NC = []
KO_NC = []
OK_TS = [STR_TSK, STR_TSKP, STR_NULL, RAW_INTEGER, RAW_TSK, RAW_TSK_OPTR, RAW_TSKP, RAW_TSKP_OPTR, RAW_NULL]
KO_TS = [STR_EMPTY, STR_INTEGER, STR_FLOAT, STR_FLOAT_E, STR_MISC, STR_OPTR, STR_TSK_MISC, STR_BOOL, STR_VARBIN,
STR_JSON,STR_GEO, STR_FLOAT, RAW_FLOAT_E, RAW_MISC, RAW_OPTR, RAW_BOOL]
OK_BO = []
KO_BO = []
OK_VB = []
KO_VB = []
OK_IN = []
KO_IN = []
OK_FL = []
KO_FL = []
OK_DB = []
KO_DB = []
OK_GE = []
KO_GE = []
OK_JS = []
KO_JS = []
PARAM_LIST = [
["db", "stb_vc", "ctb_vc", OK_VC, KO_VC, "\'vc\'"],
["db", "stb_nc", "ctb_nc", OK_NC, KO_NC, "\'nc\'"],
["db", "stb_ts", "ctb_ts", OK_TS, KO_TS, "now"],
["db", "stb_bo", "ctb_bo", OK_BO, KO_BO, "true"],
["db", "stb_vb", "ctb_vb", OK_VB, KO_VB, "\'\\x\'"],
["db", "stb_in", "ctb_in", OK_IN, KO_IN, "1"],
["db", "stb_fl", "ctb_fl", OK_FL, KO_FL, "1.0"],
["db", "stb_db", "ctb_db", OK_DB, KO_DB, "1.0"],
["db", "stb_ge", "ctb_ge", OK_GE, KO_GE, "\'POINT(1.0 1.0)\'"],
["db", "stb_js", "ctb_js", OK_JS, KO_JS, "\'{\'k1\':\'v1\',\k2\':\'v2\'}\'"],
]
for _pl in PARAM_LIST:
self.__insert_query_common(_pl[0], _pl[1], _pl[2], _pl[3], _pl[4], _pl[5])
def run(self):
tdLog.printNoPrefix("==========step1:create table")
self.__create_tb()
self.__insert_query_exec()
def stop(self):
tdSql.close()
tdLog.success(f"{__file__} successfully executed")
tdCases.addLinux(__file__, TDTestCase())
tdCases.addWindows(__file__, TDTestCase())

View File

@ -22,7 +22,7 @@ class TDTestCase:
for i in range(tb_nums):
tbname = f"{dbname}.sub_{stb_name}_{i}"
ts = self.ts + i*10000
tdSql.execute(f"create table {tbname} using {dbname}.{stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )")
tdSql.execute(f"create table {tbname} using {dbname}.{stb_name} tags ({ts} , {i} , %d , %f , %f , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )"%(i*10,i*1.0,i*1.0))
for row in range(row_nums):
ts = self.ts + row*1000

View File

@ -21,7 +21,7 @@ class TDTestCase:
for i in range(tb_nums):
tbname = f"{dbname}.sub_{stb_name}_{i}"
ts = self.ts + i*1000*120
tdSql.execute(f"create table {tbname} using {dbname}.{stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )")
tdSql.execute(f"create table {tbname} using {dbname}.{stb_name} tags ({ts} , {i} , %d , %f , %f , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )"%(i*10,i*1.0,i*1.0))
for row in range(row_nums):
ts = ts + row*1000

View File

@ -1,3 +1,4 @@
import datetime
from util.log import *
from util.sql import *
from util.cases import *
@ -53,56 +54,201 @@ class TDTestCase:
tdSql.checkRows(0)
def __ts4421(self, dbname="db", stbname='stb4421', ctbname='ctb4421'):
TAG_TYPE = ['varchar', 'nchar']
TAG_LEN = [2, 8, 200]
TAG_VAL = [0, -200, 123456789]
TAG_RESULT = [True,False,False,True,True,False,True,True,True,True,False,False,True,True,False,True,True,True]
TAG_BIND = [True, False]
TAG_TYPE = ['varchar', 'nchar']
TAG_LEN = [2, 8, 200]
TAG_VAL_INT = [0, -200, 123456789]
TAG_VAL_STR = ["noW()", "now", "'now'", "todAy()", "today", "\"today\"" ]
TAG_VAL_BOOL_INT = [ -1, 1, 0, -0]
TAG_VAL_BOOL_STR = ["TrUe", "\"true\"","fALse", "'FALSE'"]
TAG_VAL_TIMESTAMP = ["now()", "NoW", "'now'", "\"now()\"", "toDay()", "toDaY", "'today'", "\"today()\"", "\"2200-01-01 08:00:00\"", "'2200-01-02'","\"2200-01-02T00:00:00.000Z\"", "'2200-01-02T00:00:00.000'", "2200-01-01 08:00:00", "\"2200-01-02'", "2200-01-02T00:00:00.000Z"]
TAG_RESULT_INT = [True,False,False,True,True,False,True,True,True,True,False,False,True,True,False,True,True,True]
TAG_RESULT_STR = [False,False,False,False,False,False,False,True,True,False,True,True,False,True,True,False,True,True,False,False,False,False,False,False,False,True,True,False,True,True,False,True,True,False,True,True]
TAG_RESULT_BOOL = ["True","True","False","False"]
TAG_RESULT_TIMESTAMP = [True, True, True, True, True, True, True, True, True, True, True, True, False, False, False]
# check int for vartype(one tag)
nTagCtb = 0
for tagType in TAG_TYPE:
for tagLen in TAG_LEN:
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 %s(%d))'%(tagType, tagLen))
for tagVal in TAG_VAL:
if TAG_RESULT[nTagCtb] == False:
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags(%d)'%(tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags(%d) values(now,1)'%(tagVal))
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} tags("%d")'%(tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags("%d") values(now,1)'%(tagVal))
tdSql.error(f"create table {dbname}.{ctbname} using {dbname}.{stbname} tags('%d')"%(tagVal))
tdSql.error(f"insert into {dbname}.{ctbname} using {dbname}.{stbname} tags('%d') values(now,1)"%(tagVal))
else:
# integer as tag value
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.stb4421 tags(%d)'%(tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.query(f'select * from {dbname}.{ctbname} where t1="%s"'%(tagVal))
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags(%d) values(now,1)'%(tagVal))
tdSql.query(f'select * from {dbname}.{ctbname} where t1="%s"'%(tagVal))
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
# string as tag value
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.stb4421 tags("%d")'%(tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.query(f'select * from {dbname}.{ctbname} where t1="%s"'%(tagVal))
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} tags("%d") values(now,1)'%(tagVal))
tdSql.query(f'select * from {dbname}.{ctbname} where t1="%s"'%(tagVal))
tdSql.checkRows(1)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f"create table {dbname}.{ctbname} using {dbname}.stb4421 tags('%d')"%(tagVal))
tdSql.execute(f"insert into {dbname}.{ctbname} values(now,1)")
tdSql.query(f"select * from {dbname}.{ctbname} where t1='%s'"%(tagVal))
tdSql.checkRows(1)
tdSql.execute(f"drop table {dbname}.{ctbname}")
tdSql.execute(f"insert into {dbname}.{ctbname} using {dbname}.{stbname} tags('%d') values(now,1)"%(tagVal))
tdSql.query(f"select * from {dbname}.{ctbname} where t1='%s'"%(tagVal))
tdSql.checkRows(1)
tdSql.execute(f"drop table {dbname}.{ctbname}")
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 %s(%d))'%(tagType,tagLen))
for tagVal in TAG_VAL_INT:
for tagBind in TAG_BIND:
if tagBind == True:
bindStr = "(t1)"
else:
bindStr = ""
tdLog.info(f'nTagCtb={nTagCtb}, tagType={tagType}, tagLen = {tagLen}, tagVal = {tagVal}, tagBind={tagBind}')
if TAG_RESULT_INT[nTagCtb] == False:
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d)'%(bindStr,tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d) values(now,1)'%(bindStr,tagVal))
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags("%d")'%(bindStr,tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags("%d") values(now,1)'%(bindStr,tagVal))
tdSql.error(f"create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags('%d')"%(bindStr,tagVal))
tdSql.error(f"insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags('%d') values(now,1)"%(bindStr,tagVal))
else:
# integer as tag value
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d)'%(bindStr,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%d) values(now,1)'%(bindStr,tagVal))
tdSql.query(f'select * from {dbname}.{stbname} where t1="%d"'%(tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
# string as tag value
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags("%d")'%(bindStr,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags("%d") values(now,1)'%(bindStr,tagVal))
tdSql.query(f'select * from {dbname}.{stbname} where t1="%d"'%(tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
tdSql.execute(f"create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags('%d')"%(bindStr,tagVal))
tdSql.execute(f"insert into {dbname}.{ctbname} values(now,1)")
tdSql.execute(f"insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags('%d') values(now,1)"%(bindStr,tagVal))
tdSql.query(f"select * from {dbname}.{stbname} where t1='%d'"%(tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
nTagCtb += 1
tdSql.execute(f'drop table {dbname}.{stbname}')
# check int for vartype(two tags/bind tags)
nTagCtb = 0
for tagType in TAG_TYPE:
for tagLen in TAG_LEN:
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 %s(%d),t2 %s(%d) )'%(tagType,tagLen,tagType,tagLen))
for tagVal in TAG_VAL_INT:
for tagBind in TAG_BIND:
if tagBind == True:
bindStr = "(t1,t2)"
else:
bindStr = ""
if TAG_RESULT_INT[nTagCtb] == False:
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d,%d)'%(bindStr,tagVal,tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d,%d) values(now,1)'%(bindStr,tagVal,tagVal))
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags("%d","%d")'%(bindStr,tagVal,tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags("%d","%d") values(now,1)'%(bindStr,tagVal,tagVal))
tdSql.error(f"create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags('%d','%d')"%(bindStr,tagVal,tagVal))
tdSql.error(f"insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags('%d','%d') values(now,1)"%(bindStr,tagVal,tagVal))
else:
# integer as tag value
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d,%d)'%(bindStr,tagVal,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%d,%d) values(now,1)'%(bindStr,tagVal,tagVal))
tdSql.query(f"select * from {dbname}.{stbname} where t1='%d' and t2='%d'"%(tagVal,tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
# string as tag value
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags("%d","%d")'%(bindStr,tagVal,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags("%d","%d") values(now,1)'%(bindStr,tagVal,tagVal))
tdSql.query(f'select * from {dbname}.{stbname} where t1="%d" and t2="%d"'%(tagVal,tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
tdSql.execute(f"create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags('%d','%d')"%(bindStr,tagVal,tagVal))
tdSql.execute(f"insert into {dbname}.{ctbname} values(now,1)")
tdSql.execute(f"insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags('%d','%d') values(now,1)"%(bindStr,tagVal,tagVal))
tdSql.query(f"select * from {dbname}.{stbname} where t1='%d' and t2='%d'"%(tagVal,tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
nTagCtb += 1
tdSql.execute(f'drop table {dbname}.{stbname}')
# check now/today for vartype
nTagCtb = 0
for tagType in TAG_TYPE:
for tagLen in TAG_LEN:
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 %s(%d))'%(tagType,tagLen))
for tagVal in TAG_VAL_STR:
for tagBind in TAG_BIND:
if tagBind == True:
bindStr = "(t1)"
else:
bindStr = ""
if TAG_RESULT_STR[nTagCtb] == False:
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%s)'%(bindStr,tagVal))
tdSql.error(f'insert into {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%s) values(now,1)'%(bindStr,tagVal))
else:
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%s)'%(bindStr,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%s) values(now,1)'%(bindStr,tagVal))
if tagVal.startswith("'") or tagVal.startswith("\""):
tdSql.query(f'select * from {dbname}.{stbname} where t1=%s'%(tagVal))
else:
tdSql.query(f'select * from {dbname}.{stbname} where t1=\"%s\"'%(tagVal))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
nTagCtb += 1
tdSql.execute(f'drop table {dbname}.{stbname}')
# check int for bool
nTagCtb = 0
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 bool)')
for tagVal in TAG_VAL_BOOL_INT:
for tagBind in TAG_BIND:
if tagBind == True:
bindStr = "(t1)"
else:
bindStr = ""
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%d)'%(bindStr,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%d) values(now,1)'%(bindStr,tagVal))
tdSql.query(f'select * from {dbname}.{stbname} where t1=%s'%(TAG_RESULT_BOOL[nTagCtb]))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
nTagCtb += 1
tdSql.execute(f'drop table {dbname}.{stbname}')
# check str for bool
nTagCtb = 0
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 bool)')
for tagVal in TAG_VAL_BOOL_STR:
for tagBind in TAG_BIND:
if tagBind == True:
bindStr = "(t1)"
else:
bindStr = ""
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%s)'%(bindStr,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%s) values(now,1)'%(bindStr,tagVal))
tdSql.query(f'select * from {dbname}.{stbname} where t1=%s'%(TAG_RESULT_BOOL[nTagCtb]))
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
nTagCtb += 1
tdSql.execute(f'drop table {dbname}.{stbname}')
# check misc for timestamp
nTagCtb = 0
tdSql.execute(f'create stable {dbname}.{stbname}(ts timestamp, f1 int) tags(t1 timestamp)')
checkTS = datetime.datetime.today() - datetime.timedelta(days=1)
for tagVal in TAG_VAL_TIMESTAMP:
for tagBind in TAG_BIND:
if tagBind == True:
bindStr = "(t1)"
else:
bindStr = ""
if TAG_RESULT_TIMESTAMP[nTagCtb] == False:
tdSql.error(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%s)'%(bindStr,tagVal))
tdSql.error(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%s) values(now,1)'%(bindStr,tagVal))
else:
tdSql.execute(f'create table {dbname}.{ctbname} using {dbname}.{stbname} %s tags(%s)'%(bindStr,tagVal))
tdSql.execute(f'insert into {dbname}.{ctbname} values(now,1)')
tdSql.execute(f'insert into {dbname}.{ctbname}t using {dbname}.{stbname} %s tags(%s) values(now,1)'%(bindStr,tagVal))
tdSql.query(f'select * from {dbname}.{stbname} where t1>"{checkTS}"')
tdSql.checkRows(2)
tdSql.execute(f'drop table {dbname}.{ctbname}')
tdSql.execute(f'drop table {dbname}.{ctbname}t')
nTagCtb += 1
tdSql.execute(f'drop table {dbname}.{stbname}')
def run(self):
tdLog.printNoPrefix("==========step1:create table")
self.__create_tb()

View File

@ -33,7 +33,7 @@ class TDTestCase:
for i in range(ctbNum):
tagValue = 'beijing'
if (i % 10 == 0):
sql += f" {dbName}.%s%d using %s (name,fleet,driver,device_version,load_capacity,fuel_capacity,nominal_fuel_consumption) tags('truck_%d', 'South%d','Trish%d','v2.%d', 1500+%d*20, 150+%d*2, 5+%d)"%(ctbPrefix,i,stbName,i,i,i,i,(1500+i*20),(150+i*2),(5+i))
sql += f" {dbName}.%s%d using %s (name,fleet,driver,device_version,load_capacity,fuel_capacity,nominal_fuel_consumption) tags('truck_%d', 'South%d','Trish%d','v2.%d', %d, %d, %d)"%(ctbPrefix,i,stbName,i,i,i,i,1500+(1500+i*20)*20,150+(150+i*2)*2,5+(5+i))
else:
model = 'H-%d'%i
sql += f" {dbName}.%s%d using %s tags('truck_%d', 'South%d','Trish%d','%s','v2.%d', %d, %d,%d)"%(ctbPrefix,i,stbName,i,i,i,model,i,(1500+i*20),(150+i*2),(5+i))

View File

@ -22,6 +22,7 @@ python3 ./test.py -f 1-insert/update_data_muti_rows.py -P
python3 ./test.py -f 1-insert/db_tb_name_check.py -P
python3 ./test.py -f 1-insert/InsertFuturets.py -P
python3 ./test.py -f 1-insert/insert_wide_column.py -P
python3 ./test.py -f 1-insert/insert_column_value.py
python3 ./test.py -f 2-query/nestedQuery.py -P
python3 ./test.py -f 2-query/nestedQuery_str.py -P
python3 ./test.py -f 2-query/nestedQuery_math.py -P

View File

@ -233,6 +233,7 @@ python3 ./test.py -f 1-insert/update_data_muti_rows.py
python3 ./test.py -f 1-insert/db_tb_name_check.py
python3 ./test.py -f 1-insert/InsertFuturets.py
python3 ./test.py -f 1-insert/insert_wide_column.py
python3 ./test.py -f 1-insert/insert_column_value.py
python3 ./test.py -f 1-insert/rowlength64k_benchmark.py
python3 ./test.py -f 1-insert/rowlength64k.py
python3 ./test.py -f 1-insert/rowlength64k.py -R