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

fix id.id error in order by & change ? to contains

上级 36497668
...@@ -286,8 +286,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) { ...@@ -286,8 +286,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) {
return TSDB_RELATION_MATCH; return TSDB_RELATION_MATCH;
case TK_NMATCH: case TK_NMATCH:
return TSDB_RELATION_NMATCH; return TSDB_RELATION_NMATCH;
case TK_QUESTION: case TK_CONTAINS:
return TSDB_RELATION_QUESTION; return TSDB_RELATION_CONTAINS;
case TK_ARROW: case TK_ARROW:
return TSDB_RELATION_ARROW; return TSDB_RELATION_ARROW;
case TK_ISNULL: case TK_ISNULL:
...@@ -4743,7 +4743,7 @@ static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) { ...@@ -4743,7 +4743,7 @@ static int32_t validateJsonTagExpr(tSqlExpr* pExpr, char* msgBuf) {
tSqlExpr* pLeft = pExpr->pLeft; tSqlExpr* pLeft = pExpr->pLeft;
tSqlExpr* pRight = pExpr->pRight; tSqlExpr* pRight = pExpr->pRight;
if (pExpr->tokenId == TK_QUESTION) { if (pExpr->tokenId == TK_CONTAINS) {
if (pRight != NULL && !IS_VAR_DATA_TYPE(pRight->value.nType)) if (pRight != NULL && !IS_VAR_DATA_TYPE(pRight->value.nType))
return invalidOperationMsg(msgBuf, msg3); return invalidOperationMsg(msgBuf, msg3);
......
...@@ -181,7 +181,7 @@ do { \ ...@@ -181,7 +181,7 @@ do { \
#define TSDB_RELATION_MATCH 14 #define TSDB_RELATION_MATCH 14
#define TSDB_RELATION_NMATCH 15 #define TSDB_RELATION_NMATCH 15
#define TSDB_RELATION_QUESTION 16 #define TSDB_RELATION_CONTAINS 16
#define TSDB_RELATION_ARROW 17 #define TSDB_RELATION_ARROW 17
#define TSDB_BINARY_OP_ADD 30 #define TSDB_BINARY_OP_ADD 30
......
...@@ -40,29 +40,29 @@ ...@@ -40,29 +40,29 @@
#define TK_LIKE 22 #define TK_LIKE 22
#define TK_MATCH 23 #define TK_MATCH 23
#define TK_NMATCH 24 #define TK_NMATCH 24
#define TK_GLOB 25 #define TK_CONTAINS 25
#define TK_BETWEEN 26 #define TK_GLOB 26
#define TK_IN 27 #define TK_BETWEEN 27
#define TK_GT 28 #define TK_IN 28
#define TK_GE 29 #define TK_GT 29
#define TK_LT 30 #define TK_GE 30
#define TK_LE 31 #define TK_LT 31
#define TK_BITAND 32 #define TK_LE 32
#define TK_BITOR 33 #define TK_BITAND 33
#define TK_LSHIFT 34 #define TK_BITOR 34
#define TK_RSHIFT 35 #define TK_LSHIFT 35
#define TK_PLUS 36 #define TK_RSHIFT 36
#define TK_MINUS 37 #define TK_PLUS 37
#define TK_DIVIDE 38 #define TK_MINUS 38
#define TK_TIMES 39 #define TK_DIVIDE 39
#define TK_STAR 40 #define TK_TIMES 40
#define TK_SLASH 41 #define TK_STAR 41
#define TK_REM 42 #define TK_SLASH 42
#define TK_CONCAT 43 #define TK_REM 43
#define TK_UMINUS 44 #define TK_CONCAT 44
#define TK_UPLUS 45 #define TK_UMINUS 45
#define TK_BITNOT 46 #define TK_UPLUS 46
#define TK_QUESTION 47 #define TK_BITNOT 47
#define TK_ARROW 48 #define TK_ARROW 48
#define TK_SHOW 49 #define TK_SHOW 49
#define TK_DATABASES 50 #define TK_DATABASES 50
...@@ -225,6 +225,7 @@ ...@@ -225,6 +225,7 @@
#define TK_HEX 303 // hex number 0x123 #define TK_HEX 303 // hex number 0x123
#define TK_OCT 304 // oct number #define TK_OCT 304 // oct number
#define TK_BIN 305 // bin format data 0b111 #define TK_BIN 305 // bin format data 0b111
#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
#endif #endif
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
%left OR. %left OR.
%left AND. %left AND.
%right NOT. %right NOT.
%left EQ NE ISNULL NOTNULL IS LIKE MATCH NMATCH GLOB BETWEEN IN. %left EQ NE ISNULL NOTNULL IS LIKE MATCH NMATCH CONTAINS GLOB BETWEEN IN.
%left GT GE LT LE. %left GT GE LT LE.
%left BITAND BITOR LSHIFT RSHIFT. %left BITAND BITOR LSHIFT RSHIFT.
%left PLUS MINUS. %left PLUS MINUS.
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
%left STAR SLASH REM. %left STAR SLASH REM.
%left CONCAT. %left CONCAT.
%right UMINUS UPLUS BITNOT. %right UMINUS UPLUS BITNOT.
%right QUESTION ARROW. %right ARROW.
%include { %include {
#include <stdio.h> #include <stdio.h>
...@@ -651,10 +651,13 @@ sortlist(A) ::= arrow(Y) sortorder(Z). { ...@@ -651,10 +651,13 @@ sortlist(A) ::= arrow(Y) sortorder(Z). {
} }
%type item {tVariant} %type item {tVariant}
item(A) ::= ID(X). { toTSDBType(X.type); tVariantCreate(&A, &X, true); } item(A) ::= ID(X). {
toTSDBType(X.type);
tVariantCreate(&A, &X, true);
}
item(A) ::= ID(X) DOT ID(Y). { item(A) ::= ID(X) DOT ID(Y). {
toTSDBType(X.type); toTSDBType(X.type);
X.n += Y.n; X.n += (1+Y.n);
tVariantCreate(&A, &X, true); tVariantCreate(&A, &X, true);
} }
...@@ -779,8 +782,9 @@ expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); } ...@@ -779,8 +782,9 @@ expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
expr(A) ::= expr(X) MATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_MATCH); } expr(A) ::= expr(X) MATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_MATCH); }
expr(A) ::= expr(X) NMATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_NMATCH); } expr(A) ::= expr(X) NMATCH expr(Y). {A = tSqlExprCreate(X, Y, TK_NMATCH); }
// question expression // contains expression
expr(A) ::= ID(X) QUESTION STRING(Y). { tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Y, TK_STRING); A = tSqlExprCreate(S, M, TK_QUESTION); } expr(A) ::= ID(X) CONTAINS STRING(Y). { tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Y, TK_STRING); A = tSqlExprCreate(S, M, TK_CONTAINS); }
expr(A) ::= ID(X) DOT ID(Y) CONTAINS STRING(Z). { X.n += (1+Y.n); tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Z, TK_STRING); A = tSqlExprCreate(S, M, TK_CONTAINS); }
// arrow expression // arrow expression
%type arrow {tSqlExpr*} %type arrow {tSqlExpr*}
......
...@@ -37,7 +37,7 @@ OptrStr gOptrStr[] = { ...@@ -37,7 +37,7 @@ OptrStr gOptrStr[] = {
{TSDB_RELATION_NOT, "not"}, {TSDB_RELATION_NOT, "not"},
{TSDB_RELATION_MATCH, "match"}, {TSDB_RELATION_MATCH, "match"},
{TSDB_RELATION_NMATCH, "nmatch"}, {TSDB_RELATION_NMATCH, "nmatch"},
{TSDB_RELATION_QUESTION, "?"}, {TSDB_RELATION_CONTAINS, "contains"},
}; };
static FORCE_INLINE int32_t filterFieldColDescCompare(const void *desc1, const void *desc2) { static FORCE_INLINE int32_t filterFieldColDescCompare(const void *desc1, const void *desc2) {
...@@ -244,7 +244,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { ...@@ -244,7 +244,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn = 20; comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ } else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparFn = 9; comparFn = 9;
} else if (optr == TSDB_RELATION_QUESTION) { } else if (optr == TSDB_RELATION_CONTAINS) {
comparFn = 21; comparFn = 21;
} else { } else {
comparFn = 22; comparFn = 22;
...@@ -1193,7 +1193,7 @@ static int32_t filterDealJson(SFilterInfo *info, tExprNode* tree, tExprNode** pL ...@@ -1193,7 +1193,7 @@ static int32_t filterDealJson(SFilterInfo *info, tExprNode* tree, tExprNode** pL
uint32_t nullData = TSDB_DATA_JSON_NULL; uint32_t nullData = TSDB_DATA_JSON_NULL;
jsonKeyMd5(&nullData, INT_BYTES, keyMd5); jsonKeyMd5(&nullData, INT_BYTES, keyMd5);
memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN); memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
}else if(tree->_node.optr == TSDB_RELATION_QUESTION){ }else if(tree->_node.optr == TSDB_RELATION_CONTAINS){
SSchema* schema = (*pLeft)->pSchema; SSchema* schema = (*pLeft)->pSchema;
if(tree->_node.pRight->pVal->nLen > TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH; if(tree->_node.pRight->pVal->nLen > TSDB_MAX_JSON_KEY_LEN) return TSDB_CODE_TSC_INVALID_COLUMN_LENGTH;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0}; char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
...@@ -1945,7 +1945,7 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) ...@@ -1945,7 +1945,7 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
case TSDB_RELATION_MATCH: { case TSDB_RELATION_MATCH: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_QUESTION: { case TSDB_RELATION_CONTAINS: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_NMATCH: { case TSDB_RELATION_NMATCH: {
...@@ -2718,7 +2718,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t ...@@ -2718,7 +2718,7 @@ int32_t filterRmUnitByRange(SFilterInfo *info, SDataStatis *pDataStatis, int32_t
if (cunit->optr == TSDB_RELATION_ISNULL || cunit->optr == TSDB_RELATION_NOTNULL if (cunit->optr == TSDB_RELATION_ISNULL || cunit->optr == TSDB_RELATION_NOTNULL
|| cunit->optr == TSDB_RELATION_IN || cunit->optr == TSDB_RELATION_LIKE || cunit->optr == TSDB_RELATION_MATCH || cunit->optr == TSDB_RELATION_IN || cunit->optr == TSDB_RELATION_LIKE || cunit->optr == TSDB_RELATION_MATCH
|| cunit->optr == TSDB_RELATION_NOT_EQUAL || cunit->optr == TSDB_RELATION_QUESTION) { || cunit->optr == TSDB_RELATION_NOT_EQUAL || cunit->optr == TSDB_RELATION_CONTAINS) {
continue; continue;
} }
...@@ -3600,7 +3600,7 @@ int32_t filterIsIndexedColumnQuery(SFilterInfo* info, int32_t idxId, bool *res) ...@@ -3600,7 +3600,7 @@ int32_t filterIsIndexedColumnQuery(SFilterInfo* info, int32_t idxId, bool *res)
int32_t optr = FILTER_UNIT_OPTR(info->units); int32_t optr = FILTER_UNIT_OPTR(info->units);
CHK_JMP(optr == TSDB_RELATION_LIKE || optr == TSDB_RELATION_IN || optr == TSDB_RELATION_MATCH CHK_JMP(optr == TSDB_RELATION_LIKE || optr == TSDB_RELATION_IN || optr == TSDB_RELATION_MATCH
|| optr == TSDB_RELATION_ISNULL || optr == TSDB_RELATION_NOTNULL || optr == TSDB_RELATION_QUESTION); || optr == TSDB_RELATION_ISNULL || optr == TSDB_RELATION_NOTNULL || optr == TSDB_RELATION_CONTAINS);
*res = true; *res = true;
......
...@@ -387,7 +387,7 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) { ...@@ -387,7 +387,7 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pRSub->Expr.paramList = (SArray *)pRight; pRSub->Expr.paramList = (SArray *)pRight;
pExpr->pRight = pRSub; pExpr->pRight = pRSub;
} else if (optrType == TK_ARROW || optrType == TK_QUESTION) { } else if (optrType == TK_ARROW || optrType == TK_CONTAINS) {
pExpr->tokenId = optrType; pExpr->tokenId = optrType;
pExpr->pLeft = pLeft; pExpr->pLeft = pLeft;
pExpr->pRight = pRight; pExpr->pRight = pRight;
......
此差异已折叠。
...@@ -544,7 +544,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -544,7 +544,7 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
comparFn = compareStrRegexCompNMatch; comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ } else if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */
comparFn = compareWStrPatternComp; comparFn = compareWStrPatternComp;
} else if (optr == TSDB_RELATION_QUESTION) { } else if (optr == TSDB_RELATION_CONTAINS) {
comparFn = compareStrContainJson; comparFn = compareStrContainJson;
} else { } else {
comparFn = compareJsonVal; comparFn = compareJsonVal;
......
...@@ -231,7 +231,8 @@ static SKeyword keywordTable[] = { ...@@ -231,7 +231,8 @@ static SKeyword keywordTable[] = {
{"OUTPUTTYPE", TK_OUTPUTTYPE}, {"OUTPUTTYPE", TK_OUTPUTTYPE},
{"AGGREGATE", TK_AGGREGATE}, {"AGGREGATE", TK_AGGREGATE},
{"BUFSIZE", TK_BUFSIZE}, {"BUFSIZE", TK_BUFSIZE},
{"RANGE", TK_RANGE} {"RANGE", TK_RANGE},
{"CONTAINS", TK_CONTAINS}
}; };
static const char isIdChar[] = { static const char isIdChar[] = {
......
...@@ -78,14 +78,13 @@ class TDTestCase: ...@@ -78,14 +78,13 @@ class TDTestCase:
tdSql.error("select * from jsons1 where jtag->''") tdSql.error("select * from jsons1 where jtag->''")
tdSql.error("select * from jsons1 where jtag->''=9") tdSql.error("select * from jsons1 where jtag->''=9")
tdSql.error("select -> from jsons1") tdSql.error("select -> from jsons1")
tdSql.error("select ? from jsons1") tdSql.error("select * from jsons1 where contains")
tdSql.error("select * from jsons1 where ?")
tdSql.error("select * from jsons1 where jtag->") tdSql.error("select * from jsons1 where jtag->")
tdSql.error("select jtag->location from jsons1") tdSql.error("select jtag->location from jsons1")
tdSql.error("select jtag?location from jsons1") tdSql.error("select jtag contains location from jsons1")
tdSql.error("select * from jsons1 where jtag?location") tdSql.error("select * from jsons1 where jtag contains location")
tdSql.error("select * from jsons1 where jtag?''") tdSql.error("select * from jsons1 where jtag contains''")
tdSql.error("select * from jsons1 where jtag?'location'='beijing'") tdSql.error("select * from jsons1 where jtag contains 'location'='beijing'")
# test select normal column # test select normal column
tdSql.query("select dataint from jsons1") tdSql.query("select dataint from jsons1")
...@@ -246,12 +245,12 @@ class TDTestCase: ...@@ -246,12 +245,12 @@ class TDTestCase:
tdSql.query("select * from jsons1 where jtag->'tag3' is not null") tdSql.query("select * from jsons1 where jtag->'tag3' is not null")
tdSql.checkRows(4) tdSql.checkRows(4)
# test ? # test contains
tdSql.query("select * from jsons1 where jtag?'tag1'") tdSql.query("select * from jsons1 where jtag contains 'tag1'")
tdSql.checkRows(8) tdSql.checkRows(8)
tdSql.query("select * from jsons1 where jtag?'tag3'") tdSql.query("select * from jsons1 where jtag contains 'tag3'")
tdSql.checkRows(4) tdSql.checkRows(4)
tdSql.query("select * from jsons1 where jtag?'tag_no_exist'") tdSql.query("select * from jsons1 where jtag contains 'tag_no_exist'")
tdSql.checkRows(0) tdSql.checkRows(0)
# test json tag in where condition with and/or # test json tag in where condition with and/or
...@@ -267,19 +266,19 @@ class TDTestCase: ...@@ -267,19 +266,19 @@ class TDTestCase:
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35") tdSql.query("select * from jsons1 where jtag->'tag1'=13 or jtag->'tag2'>35")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select * from jsons1 where jtag->'tag1' is not null and jtag?'tag3'") tdSql.query("select * from jsons1 where jtag->'tag1' is not null and jtag contains 'tag3'")
tdSql.checkRows(4) tdSql.checkRows(4)
tdSql.query("select * from jsons1 where jtag->'tag1'='femail' and jtag?'tag3'") tdSql.query("select * from jsons1 where jtag->'tag1'='femail' and jtag contains 'tag3'")
tdSql.checkRows(2) tdSql.checkRows(2)
# test with tbname/normal column # test with tbname/normal column
tdSql.query("select * from jsons1 where tbname = 'jsons1_1'") tdSql.query("select * from jsons1 where tbname = 'jsons1_1'")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag?'tag3'") tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3'")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag?'tag3' and dataint=3") tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag?'tag3' and dataint=23") tdSql.query("select * from jsons1 where tbname = 'jsons1_1' and jtag contains 'tag3' and dataint=23")
tdSql.checkRows(1) tdSql.checkRows(1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册