enh: support binary/hex integer

This commit is contained in:
kailixu 2024-03-13 15:12:21 +08:00
parent da0254b49b
commit 9901825bb0
11 changed files with 3674 additions and 3596 deletions

View File

@ -250,131 +250,133 @@
#define TK_SPLIT 231
#define TK_DELETE 232
#define TK_INSERT 233
#define TK_NULL 234
#define TK_NK_QUESTION 235
#define TK_NK_ALIAS 236
#define TK_NK_ARROW 237
#define TK_ROWTS 238
#define TK_QSTART 239
#define TK_QEND 240
#define TK_QDURATION 241
#define TK_WSTART 242
#define TK_WEND 243
#define TK_WDURATION 244
#define TK_IROWTS 245
#define TK_ISFILLED 246
#define TK_CAST 247
#define TK_NOW 248
#define TK_TODAY 249
#define TK_TIMEZONE 250
#define TK_CLIENT_VERSION 251
#define TK_SERVER_VERSION 252
#define TK_SERVER_STATUS 253
#define TK_CURRENT_USER 254
#define TK_CASE 255
#define TK_WHEN 256
#define TK_THEN 257
#define TK_ELSE 258
#define TK_BETWEEN 259
#define TK_IS 260
#define TK_NK_LT 261
#define TK_NK_GT 262
#define TK_NK_LE 263
#define TK_NK_GE 264
#define TK_NK_NE 265
#define TK_MATCH 266
#define TK_NMATCH 267
#define TK_CONTAINS 268
#define TK_IN 269
#define TK_JOIN 270
#define TK_INNER 271
#define TK_SELECT 272
#define TK_NK_HINT 273
#define TK_DISTINCT 274
#define TK_WHERE 275
#define TK_PARTITION 276
#define TK_BY 277
#define TK_SESSION 278
#define TK_STATE_WINDOW 279
#define TK_EVENT_WINDOW 280
#define TK_COUNT_WINDOW 281
#define TK_SLIDING 282
#define TK_FILL 283
#define TK_VALUE 284
#define TK_VALUE_F 285
#define TK_NONE 286
#define TK_PREV 287
#define TK_NULL_F 288
#define TK_LINEAR 289
#define TK_NEXT 290
#define TK_HAVING 291
#define TK_RANGE 292
#define TK_EVERY 293
#define TK_ORDER 294
#define TK_SLIMIT 295
#define TK_SOFFSET 296
#define TK_LIMIT 297
#define TK_OFFSET 298
#define TK_ASC 299
#define TK_NULLS 300
#define TK_ABORT 301
#define TK_AFTER 302
#define TK_ATTACH 303
#define TK_BEFORE 304
#define TK_BEGIN 305
#define TK_BITAND 306
#define TK_BITNOT 307
#define TK_BITOR 308
#define TK_BLOCKS 309
#define TK_CHANGE 310
#define TK_COMMA 311
#define TK_CONCAT 312
#define TK_CONFLICT 313
#define TK_COPY 314
#define TK_DEFERRED 315
#define TK_DELIMITERS 316
#define TK_DETACH 317
#define TK_DIVIDE 318
#define TK_DOT 319
#define TK_EACH 320
#define TK_FAIL 321
#define TK_FILE 322
#define TK_FOR 323
#define TK_GLOB 324
#define TK_ID 325
#define TK_IMMEDIATE 326
#define TK_IMPORT 327
#define TK_INITIALLY 328
#define TK_INSTEAD 329
#define TK_ISNULL 330
#define TK_KEY 331
#define TK_MODULES 332
#define TK_NK_BITNOT 333
#define TK_NK_SEMI 334
#define TK_NOTNULL 335
#define TK_OF 336
#define TK_PLUS 337
#define TK_PRIVILEGE 338
#define TK_RAISE 339
#define TK_RESTRICT 340
#define TK_ROW 341
#define TK_SEMI 342
#define TK_STAR 343
#define TK_STATEMENT 344
#define TK_STRICT 345
#define TK_STRING 346
#define TK_TIMES 347
#define TK_VALUES 348
#define TK_VARIABLE 349
#define TK_WAL 350
#define TK_NK_BIN 234
#define TK_NK_HEX 235
#define TK_NULL 236
#define TK_NK_QUESTION 237
#define TK_NK_ALIAS 238
#define TK_NK_ARROW 239
#define TK_ROWTS 240
#define TK_QSTART 241
#define TK_QEND 242
#define TK_QDURATION 243
#define TK_WSTART 244
#define TK_WEND 245
#define TK_WDURATION 246
#define TK_IROWTS 247
#define TK_ISFILLED 248
#define TK_CAST 249
#define TK_NOW 250
#define TK_TODAY 251
#define TK_TIMEZONE 252
#define TK_CLIENT_VERSION 253
#define TK_SERVER_VERSION 254
#define TK_SERVER_STATUS 255
#define TK_CURRENT_USER 256
#define TK_CASE 257
#define TK_WHEN 258
#define TK_THEN 259
#define TK_ELSE 260
#define TK_BETWEEN 261
#define TK_IS 262
#define TK_NK_LT 263
#define TK_NK_GT 264
#define TK_NK_LE 265
#define TK_NK_GE 266
#define TK_NK_NE 267
#define TK_MATCH 268
#define TK_NMATCH 269
#define TK_CONTAINS 270
#define TK_IN 271
#define TK_JOIN 272
#define TK_INNER 273
#define TK_SELECT 274
#define TK_NK_HINT 275
#define TK_DISTINCT 276
#define TK_WHERE 277
#define TK_PARTITION 278
#define TK_BY 279
#define TK_SESSION 280
#define TK_STATE_WINDOW 281
#define TK_EVENT_WINDOW 282
#define TK_COUNT_WINDOW 283
#define TK_SLIDING 284
#define TK_FILL 285
#define TK_VALUE 286
#define TK_VALUE_F 287
#define TK_NONE 288
#define TK_PREV 289
#define TK_NULL_F 290
#define TK_LINEAR 291
#define TK_NEXT 292
#define TK_HAVING 293
#define TK_RANGE 294
#define TK_EVERY 295
#define TK_ORDER 296
#define TK_SLIMIT 297
#define TK_SOFFSET 298
#define TK_LIMIT 299
#define TK_OFFSET 300
#define TK_ASC 301
#define TK_NULLS 302
#define TK_ABORT 303
#define TK_AFTER 304
#define TK_ATTACH 305
#define TK_BEFORE 306
#define TK_BEGIN 307
#define TK_BITAND 308
#define TK_BITNOT 309
#define TK_BITOR 310
#define TK_BLOCKS 311
#define TK_CHANGE 312
#define TK_COMMA 313
#define TK_CONCAT 314
#define TK_CONFLICT 315
#define TK_COPY 316
#define TK_DEFERRED 317
#define TK_DELIMITERS 318
#define TK_DETACH 319
#define TK_DIVIDE 320
#define TK_DOT 321
#define TK_EACH 322
#define TK_FAIL 323
#define TK_FILE 324
#define TK_FOR 325
#define TK_GLOB 326
#define TK_ID 327
#define TK_IMMEDIATE 328
#define TK_IMPORT 329
#define TK_INITIALLY 330
#define TK_INSTEAD 331
#define TK_ISNULL 332
#define TK_KEY 333
#define TK_MODULES 334
#define TK_NK_BITNOT 335
#define TK_NK_SEMI 336
#define TK_NOTNULL 337
#define TK_OF 338
#define TK_PLUS 339
#define TK_PRIVILEGE 340
#define TK_RAISE 341
#define TK_RESTRICT 342
#define TK_ROW 343
#define TK_SEMI 344
#define TK_STAR 345
#define TK_STATEMENT 346
#define TK_STRICT 347
#define TK_STRING 348
#define TK_TIMES 349
#define TK_VALUES 350
#define TK_VARIABLE 351
#define TK_WAL 352
#define TK_NK_SPACE 600
#define TK_NK_COMMENT 601
#define TK_NK_ILLEGAL 602
#define TK_NK_HEX 603 // hex number 0x123
// #define TK_NK_HEX 603 // hex number 0x123
#define TK_NK_OCT 604 // oct number
#define TK_NK_BIN 605 // bin format data 0b111
// #define TK_NK_BIN 605 // bin format data 0b111
#define TK_BATCH_SCAN 606
#define TK_NO_BATCH_SCAN 607
#define TK_SORT_FOR_GROUP 608

View File

@ -44,6 +44,11 @@ int32_t toDoubleEx(const char *z, int32_t n, uint32_t type, double *value);
int32_t toInteger(const char *z, int32_t n, int32_t base, int64_t *value);
int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value);
/**
* non floating point integers
*/
int32_t toIntegerPure(const char *z, int32_t n, int32_t base, int64_t *value);
void taosVariantCreateFromBinary(SVariant *pVar, const char *pz, size_t len, uint32_t type);
void taosVariantDestroy(SVariant *pV);

View File

@ -19,7 +19,7 @@
#include "ttokendef.h"
#include "tvariant.h"
int32_t parseBinaryUInteger(const char *z, int32_t n, uint64_t *value) {
static int32_t parseBinaryUInteger(const char *z, int32_t n, uint64_t *value) {
// skip head 0b
const char *p = z + 2;
int32_t l = n - 2;
@ -45,7 +45,7 @@ int32_t parseBinaryUInteger(const char *z, int32_t n, uint64_t *value) {
return TSDB_CODE_SUCCESS;
}
int32_t parseSignAndUInteger(const char *z, int32_t n, bool *is_neg, uint64_t *value) {
static int32_t parseSignAndUInteger(const char *z, int32_t n, bool *is_neg, uint64_t *value, bool parseFloat) {
// parse sign
bool has_sign = false;
if (z[0] == '-') {
@ -80,7 +80,7 @@ int32_t parseSignAndUInteger(const char *z, int32_t n, bool *is_neg, uint64_t *v
}
}
if (!parsed) {
if (!parsed && parseFloat) {
// parsing as double
double val = taosStr2Double(z, &endPtr);
if (val > UINT64_MAX) {
@ -96,24 +96,64 @@ 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) {
int32_t toDoubleEx(const char *z, int32_t n, uint32_t type, double *value) {
if (n == 0) {
errno = EINVAL;
return TSDB_CODE_FAILED;
}
errno = 0;
char* endPtr = NULL;
char *endPtr = NULL;
*value = taosStr2Double(z, &endPtr);
if (errno == ERANGE || errno == EINVAL) {
return TSDB_CODE_FAILED;
if (errno != ERANGE && errno != EINVAL && endPtr - z == n) {
return TSDB_CODE_SUCCESS;
}
if (endPtr - z != n) {
return TSDB_CODE_FAILED;
if (type == TK_NK_BIN || type == TK_NK_STRING) {
bool is_neg = false;
uint64_t uv = 0;
if (TSDB_CODE_SUCCESS == parseSignAndUInteger(z, n, &is_neg, &uv, false)) {
*value = is_neg ? -uv : uv;
return TSDB_CODE_SUCCESS;
}
}
return TSDB_CODE_SUCCESS;
return TSDB_CODE_FAILED;
}
int32_t toIntegerPure(const char *z, int32_t n, int32_t base, int64_t *value) {
errno = 0;
char *endPtr = NULL;
*value = taosStr2Int64(z, &endPtr, base);
if (endPtr - z == n) {
if (errno == ERANGE || errno == EINVAL) {
return TSDB_CODE_FAILED;
}
return TSDB_CODE_SUCCESS;
}
bool is_neg = false;
uint64_t uv = 0;
int32_t code = parseSignAndUInteger(z, n, &is_neg, &uv, false); // support 0b/0x
if (code == TSDB_CODE_SUCCESS) {
if (is_neg) {
if (uv > 1ull + INT64_MAX) {
*value = INT64_MIN;
return TSDB_CODE_FAILED;
} else {
*value = -uv;
}
} else {
if (uv > INT64_MAX) {
*value = INT64_MAX;
return TSDB_CODE_FAILED;
}
*value = uv;
}
}
return code;
}
int32_t toIntegerEx(const char *z, int32_t n, uint32_t type, int64_t *value) {
@ -190,7 +230,7 @@ int32_t toIntegerEx(const char *z, int32_t n, uint32_t type, int64_t *value) {
// 2. parse as other
bool is_neg = false;
uint64_t uv = 0;
int32_t code = parseSignAndUInteger(z, n, &is_neg, &uv);
int32_t code = parseSignAndUInteger(z, n, &is_neg, &uv, true);
if (code == TSDB_CODE_SUCCESS) {
// truncate into int64
if (is_neg) {
@ -279,7 +319,7 @@ int32_t toUIntegerEx(const char *z, int32_t n, uint32_t type, uint64_t *value) {
// 2. parse as other
bool is_neg = false;
int32_t code = parseSignAndUInteger(z, n, &is_neg, value);
int32_t code = parseSignAndUInteger(z, n, &is_neg, value, true);
if (is_neg) {
if (TSDB_CODE_SUCCESS == code && 0 == *value) {
return TSDB_CODE_SUCCESS;

View File

@ -24,6 +24,15 @@ extern "C" {
#include "ttokendef.h"
#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'))
// used to denote the minimum unite in sql parsing
typedef struct SToken {
uint32_t n;

View File

@ -45,15 +45,6 @@ extern "C" {
(*((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'))

View File

@ -767,6 +767,30 @@ tags_literal(A) ::= NK_MINUS(B) NK_FLOAT(C).
t.n = (C.z + C.n) - B.z;
A = createRawValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t, NULL);
}
tags_literal(A) ::= NK_BIN(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &B, NULL); }
tags_literal(A) ::= NK_PLUS(B) NK_BIN(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_BIN(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_HEX(B). { A = createRawValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &B, NULL); }
tags_literal(A) ::= NK_PLUS(B) NK_HEX(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_HEX(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_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); }

View File

@ -72,9 +72,7 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
goto abort_parse;
}
case TK_NK_HEX:
case TK_NK_OCT:
case TK_NK_BIN: {
case TK_NK_OCT: {
snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unsupported token: \"%s\"", t0.z);
cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
goto abort_parse;

View File

@ -260,7 +260,8 @@ 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) {
if (pToken->type != TK_NK_STRING || pToken->n == 0) {
if ((pToken->n == 0) ||
(pToken->type != TK_NK_STRING && pToken->type != TK_NK_HEX && pToken->type != TK_NK_BIN)) {
return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z);
}
if (IS_NOW_STR(pToken->z, pToken->n)) {
@ -269,7 +270,7 @@ static int parseTimestampOrInterval(const char** end, SToken* pToken, int16_t ti
} else if (IS_TODAY_STR(pToken->z, pToken->n)) {
*isTs = true;
*ts = taosGetTimestampToday(timePrec);
} else if (TSDB_CODE_SUCCESS == toInteger(pToken->z, pToken->n, 10, ts)) {
} else if (TSDB_CODE_SUCCESS == toIntegerPure(pToken->z, pToken->n, 10, ts)) {
*isTs = true;
} else {
return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp format", pToken->z);
@ -498,6 +499,9 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema,
*(int8_t*)(&val->i64) = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE);
} else if (pToken->type == TK_NK_FLOAT) {
*(int8_t*)(&val->i64) = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE);
} else if ((pToken->type == TK_NK_HEX || pToken->type == TK_NK_BIN) &&
(TSDB_CODE_SUCCESS == toIntegerPure(pToken->z, pToken->n, 10, &iv))) {
*(int8_t*)(&val->i64) = (iv == 0 ? FALSE_VALUE : TRUE_VALUE);
} else {
return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z);
}
@ -1438,6 +1442,9 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql,
pVal->value.val = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE);
} else if (pToken->type == TK_NK_FLOAT) {
pVal->value.val = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE);
} else if ((pToken->type == TK_NK_HEX || pToken->type == TK_NK_BIN) &&
(TSDB_CODE_SUCCESS == toIntegerPure(pToken->z, pToken->n, 10, &pVal->value.val))) {
*(int8_t*)(&pVal->value.val) = (pVal->value.val == 0 ? FALSE_VALUE : TRUE_VALUE);
} else {
return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z);
}

View File

@ -656,7 +656,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
*tokenId = TK_NK_ALIAS; // must be alias
return i;
}
if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) {
if ((IS_TRUE_STR(z, i) == 0) || (IS_FALSE_STR(z, i) == 0)) {
*tokenId = TK_NK_BOOL;
return i;
}

File diff suppressed because it is too large Load Diff

View File

@ -118,13 +118,14 @@ class TDTestCase:
def __insert_query_exec(self):
STR_EMPTY = ['\'\'', "\"\"", '\' \'', "\" \""]
STR_INTEGER_P = ["\"123\"", '\'+12\'', '\'+0\'', '\'-0\'', '\'0x12\'', '\'-0x0\'', '\'+0x0\'', '\'0b0101\'', '\'-0b00\'']
STR_INTEGER_M = ['\'-128\'', '\'-0x1\'', '\'-0b01\'']
STR_INTEGER_P = ["\"123\"", '\'+12\'', '\'+0\'', '\'-0\'', '\'0x12\'', '\'-0X0\'', '\'+0x0\'', '\'0B0101\'', '\'-0b00\'']
STR_INTEGER_M = ['\'-128\'', '\'-0X1\'', '\"-0x34\"', '\'-0b01\'', '\'-0B01111111\'']
STR_FLOAT_P = ['\'123.1\'', "\"+0.001\"", "\'\-0.0\'"]
STR_FLOAT_M = ["\"-23.001\""]
STR_FLOAT_E_P = ['\'1e1\'', "\"1e-2\"", "\"-1e-5\""]
STR_FLOAT_E_M = ["\"-0.1E+1\""]
STR_MISC = ["\"123ab\"", '\'123d\'', '\'-12s\'', '\'\x012\'', '\'x12\'', '\'x\'', '\'NULL \'', '\'True \'', '\' False\'']
STR_MISC = ["\"123ab\"", '\'123d\'', '\'-12s\'', '\'\x012\'', '\'x12\'', '\'x\'', '\'NULL \'', '\' NULL\'', '\'True \'', '\' False\'',
'\'0B0101 \'', '\' 0B0101\'', '\' -0x01 \'', '\'-0x02 \'']
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\'']
@ -132,18 +133,18 @@ class TDTestCase:
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 = ['\'\\x12\'', '\'\\x12ab\'']
STR_JSON_O = ['\'{\"k1\":\"v1\"}\'', '\'{}\'']
STR_VARBIN = ['\'\\x12\'', '\'\\x13\'', '\' \\x14 \'', '\'\\x12ab\'']
STR_JSON_O = ['\'{\"k1\":\"v1\"}\'', '\' {} \'']
STR_JSON_A = ['\'[]\'']
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_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_P = ['123', '+0127', '+0', '0', '-0', '0', '0x12', '-0x0', '+0x0', '0b0101', '-0b00']
RAW_INTEGER_M = ['-123', '-0128','-0x1', '-0b01']
RAW_FLOAT_P = ['123.012', '0.0', '+0.0', '-0.0']
RAW_FLOAT_M = ['-128.001']
RAW_FLOAT_E_P = ['1e-100', '+0.1E+2', '-0.1E-10']
RAW_FLOAT_E_M = ["-1E2"]
RAW_INTEGER_P = [' 123 ', '+0127 ', ' +0', '0 ', '-0', '0', ' 0X12', ' -0x0 ', '+0x0 ', ' 0B0101', ' -0b00']
RAW_INTEGER_M = [' -123 ', ' -0128',' -0x1', ' -0X35', '-0b01 ', ' -0B01111111 ']
RAW_FLOAT_P = [' 123.012', ' 0.0', ' +0.0', ' -0.0 ']
RAW_FLOAT_M = ['-128.001 ']
RAW_FLOAT_E_P = [' 1e-100', ' +0.1E+2', ' -0.1E-10']
RAW_FLOAT_E_M = [" -1E2 "]
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']
@ -152,7 +153,7 @@ class TDTestCase:
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 ']
RAW_NULL = ['NuLl', 'null ', ' NULL', ' NULL ']
OK_VC = [STR_EMPTY, STR_INTEGER_P, STR_INTEGER_M, STR_FLOAT_P, STR_FLOAT_M, STR_FLOAT_E_P, STR_FLOAT_E_M, STR_MISC, STR_OPTR, STR_TSK, STR_TSK_MISC, STR_TSKP,
STR_TSKP_MISC, STR_BOOL, STR_TS, STR_VARBIN, STR_JSON_O, STR_JSON_A, STR_GEO, STR_NULL, RAW_INTEGER_P, RAW_INTEGER_M, RAW_FLOAT_P, RAW_FLOAT_M,
@ -177,13 +178,12 @@ class TDTestCase:
OK_UI = [STR_INTEGER_P, STR_FLOAT_P, STR_FLOAT_E_P, STR_NULL, RAW_INTEGER_P, RAW_FLOAT_P, RAW_FLOAT_E_P, RAW_NULL]
KO_UI = [STR_EMPTY, STR_MISC, STR_INTEGER_M, STR_FLOAT_M, STR_FLOAT_E_M, STR_OPTR, STR_TSK, STR_TSK_MISC, STR_TSKP, STR_TSKP_MISC, STR_BOOL, STR_TS, STR_VARBIN,
STR_JSON_O, STR_JSON_A, STR_GEO, RAW_TSK, RAW_BOOL, RAW_INTEGER_M, RAW_FLOAT_M, RAW_FLOAT_E_M, RAW_MISC, RAW_OPTR, RAW_TSK_OPTR, RAW_TSKP, RAW_TSKP_OPTR]
OK_FL = [STR_INTEGER_P, STR_INTEGER_M, STR_FLOAT_P, STR_FLOAT_M, STR_FLOAT_E_P, STR_FLOAT_E_M, STR_NULL, RAW_INTEGER_P, RAW_INTEGER_M, RAW_FLOAT_P, RAW_FLOAT_M,
OK_FL = [RAW_INTEGER_P, STR_INTEGER_P, STR_INTEGER_M, STR_FLOAT_P, STR_FLOAT_M, STR_FLOAT_E_P, STR_FLOAT_E_M, STR_NULL, RAW_INTEGER_M, RAW_FLOAT_P, RAW_FLOAT_M,
RAW_FLOAT_E_P, RAW_FLOAT_E_M, RAW_NULL]
KO_FL = [STR_EMPTY, STR_MISC, STR_OPTR, STR_TSK, STR_TSK_MISC, STR_TSKP, STR_TSKP_MISC, STR_BOOL, STR_TS, STR_VARBIN, STR_JSON_O, STR_JSON_A, STR_GEO, RAW_TSK,
RAW_BOOL, RAW_MISC, RAW_OPTR, RAW_TSK_OPTR, RAW_TSKP, RAW_TSKP_OPTR]
OK_DB = OK_FL
KO_DB = [STR_EMPTY, STR_MISC, STR_OPTR, STR_TSK, STR_TSK_MISC, STR_TSKP, STR_TSKP_MISC, STR_BOOL, STR_TS, STR_VARBIN, STR_JSON_O, STR_JSON_A, STR_GEO, RAW_TSK,
RAW_BOOL, RAW_MISC, RAW_OPTR, RAW_TSK_OPTR, RAW_TSKP, RAW_TSKP_OPTR]
KO_DB = KO_FL
OK_GE = [STR_GEO, STR_NULL, RAW_NULL]
KO_GE = [STR_EMPTY, STR_MISC, STR_OPTR, STR_TSK, STR_TSK_MISC, STR_TSKP, STR_TSKP_MISC, STR_BOOL, STR_TS, STR_JSON_O, STR_JSON_A, STR_VARBIN, RAW_TSK, RAW_BOOL, RAW_MISC,
RAW_OPTR, RAW_TSK_OPTR, RAW_TSKP, RAW_TSKP_OPTR, STR_INTEGER_P, STR_INTEGER_M, STR_FLOAT_P, STR_FLOAT_M, STR_FLOAT_E_P, STR_FLOAT_E_M, RAW_INTEGER_P, RAW_INTEGER_M,
@ -194,15 +194,15 @@ class TDTestCase:
RAW_FLOAT_P, RAW_FLOAT_M, RAW_FLOAT_E_P, RAW_FLOAT_E_M]
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_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_ui", "ctb_ui", OK_UI, KO_UI, "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_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)\'"]
]