提交 a09cfdfa 编写于 作者: S shenglian zhou

support nmatch relation between binary/nchar tbname/tag/col and posix regular expression

上级 ab24035c
...@@ -281,6 +281,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) { ...@@ -281,6 +281,8 @@ static uint8_t convertRelationalOperator(SStrToken *pToken) {
return TSDB_RELATION_LIKE; return TSDB_RELATION_LIKE;
case TK_MATCH: case TK_MATCH:
return TSDB_RELATION_MATCH; return TSDB_RELATION_MATCH;
case TK_NMATCH:
return TSDB_RELATION_NMATCH;
case TK_ISNULL: case TK_ISNULL:
return TSDB_RELATION_ISNULL; return TSDB_RELATION_ISNULL;
case TK_NOTNULL: case TK_NOTNULL:
...@@ -3782,6 +3784,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, ...@@ -3782,6 +3784,9 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
case TK_MATCH: case TK_MATCH:
pColumnFilter->lowerRelOptr = TSDB_RELATION_MATCH; pColumnFilter->lowerRelOptr = TSDB_RELATION_MATCH;
break; break;
case TK_NMATCH:
pColumnFilter->lowerRelOptr = TSDB_RELATION_NMATCH;
break;
case TK_ISNULL: case TK_ISNULL:
pColumnFilter->lowerRelOptr = TSDB_RELATION_ISNULL; pColumnFilter->lowerRelOptr = TSDB_RELATION_ISNULL;
break; break;
...@@ -3846,15 +3851,17 @@ static int32_t tablenameListToString(tSqlExpr* pExpr, SStringBuilder* sb) { ...@@ -3846,15 +3851,17 @@ static int32_t tablenameListToString(tSqlExpr* pExpr, SStringBuilder* sb) {
} }
static int32_t tablenameCondToString(tSqlExpr* pExpr, uint32_t opToken, SStringBuilder* sb) { static int32_t tablenameCondToString(tSqlExpr* pExpr, uint32_t opToken, SStringBuilder* sb) {
assert(opToken == TK_LIKE || opToken == TK_MATCH); assert(opToken == TK_LIKE || opToken == TK_MATCH || opToken == TK_NMATCH);
if (opToken == TK_LIKE) { if (opToken == TK_LIKE) {
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN); taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN);
taosStringBuilderAppendString(sb, pExpr->value.pz); taosStringBuilderAppendString(sb, pExpr->value.pz);
} else if (opToken == TK_MATCH) { } else if (opToken == TK_MATCH) {
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN); taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_MATCH, QUERY_COND_REL_PREFIX_MATCH_LEN);
taosStringBuilderAppendString(sb, pExpr->value.pz); taosStringBuilderAppendString(sb, pExpr->value.pz);
} else if (opToken == TK_NMATCH) {
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN);
taosStringBuilderAppendString(sb, pExpr->value.pz);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -3903,12 +3910,13 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol ...@@ -3903,12 +3910,13 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol
&& pExpr->tokenId != TK_NOTNULL && pExpr->tokenId != TK_NOTNULL
&& pExpr->tokenId != TK_LIKE && pExpr->tokenId != TK_LIKE
&& pExpr->tokenId != TK_MATCH && pExpr->tokenId != TK_MATCH
&& pExpr->tokenId != TK_NMATCH
&& pExpr->tokenId != TK_IN) { && pExpr->tokenId != TK_IN) {
ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
goto _err_ret; goto _err_ret;
} }
} else { } else {
if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH) { if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_NMATCH) {
ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
goto _err_ret; goto _err_ret;
} }
...@@ -3956,7 +3964,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* ...@@ -3956,7 +3964,7 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
if (pTableCond->tokenId == TK_IN) { if (pTableCond->tokenId == TK_IN) {
ret = tablenameListToString(pRight, sb); ret = tablenameListToString(pRight, sb);
} else if (pTableCond->tokenId == TK_LIKE || pTableCond->tokenId == TK_MATCH) { } else if (pTableCond->tokenId == TK_LIKE || pTableCond->tokenId == TK_MATCH || pTableCond->tokenId == TK_NMATCH) {
if (pRight->tokenId != TK_STRING) { if (pRight->tokenId != TK_STRING) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
...@@ -4410,7 +4418,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr ...@@ -4410,7 +4418,7 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
} }
static bool validTableNameOptr(tSqlExpr* pExpr) { static bool validTableNameOptr(tSqlExpr* pExpr) {
const char nameFilterOptr[] = {TK_IN, TK_LIKE, TK_MATCH}; const char nameFilterOptr[] = {TK_IN, TK_LIKE, TK_MATCH, TK_NMATCH};
for (int32_t i = 0; i < tListLen(nameFilterOptr); ++i) { for (int32_t i = 0; i < tListLen(nameFilterOptr); ++i) {
if (pExpr->tokenId == nameFilterOptr[i]) { if (pExpr->tokenId == nameFilterOptr[i]) {
...@@ -4511,7 +4519,7 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_ ...@@ -4511,7 +4519,7 @@ static int32_t validateMatchExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_
tSqlExpr* pLeft = pExpr->pLeft; tSqlExpr* pLeft = pExpr->pLeft;
tSqlExpr* pRight = pExpr->pRight; tSqlExpr* pRight = pExpr->pRight;
if (pExpr->tokenId == TK_MATCH) { if (pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_NMATCH) {
if (pRight->value.nLen > tsMaxRegexStringLen) { if (pRight->value.nLen > tsMaxRegexStringLen) {
char tmp[64] = {0}; char tmp[64] = {0};
sprintf(tmp, msg1, tsMaxRegexStringLen); sprintf(tmp, msg1, tsMaxRegexStringLen);
...@@ -4925,9 +4933,12 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, ...@@ -4925,9 +4933,12 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
STagCond* pTagCond = &pQueryInfo->tagCond; STagCond* pTagCond = &pQueryInfo->tagCond;
pTagCond->tbnameCond.uid = pTableMetaInfo->pTableMeta->id.uid; pTagCond->tbnameCond.uid = pTableMetaInfo->pTableMeta->id.uid;
assert(pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_IN); assert(pExpr->tokenId == TK_LIKE
|| pExpr->tokenId == TK_MATCH
|| pExpr->tokenId == TK_NMATCH
|| pExpr->tokenId == TK_IN);
if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH) { if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_NMATCH) {
char* str = taosStringBuilderGetResult(sb, NULL); char* str = taosStringBuilderGetResult(sb, NULL);
pQueryInfo->tagCond.tbnameCond.cond = strdup(str); pQueryInfo->tagCond.tbnameCond.cond = strdup(str);
pQueryInfo->tagCond.tbnameCond.len = (int32_t) strlen(str); pQueryInfo->tagCond.tbnameCond.len = (int32_t) strlen(str);
...@@ -8224,11 +8235,12 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, S ...@@ -8224,11 +8235,12 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, S
&& pExpr->tokenId != TK_NOTNULL && pExpr->tokenId != TK_NOTNULL
&& pExpr->tokenId != TK_LIKE && pExpr->tokenId != TK_LIKE
&& pExpr->tokenId != TK_MATCH && pExpr->tokenId != TK_MATCH
&& pExpr->tokenId != TK_NMATCH
) { ) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2);
} }
} else { } else {
if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH) { if (pExpr->tokenId == TK_LIKE || pExpr->tokenId == TK_MATCH || pExpr->tokenId == TK_NMATCH) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
} }
......
...@@ -34,10 +34,12 @@ struct SSchema; ...@@ -34,10 +34,12 @@ struct SSchema;
#define QUERY_COND_REL_PREFIX_IN "IN|" #define QUERY_COND_REL_PREFIX_IN "IN|"
#define QUERY_COND_REL_PREFIX_LIKE "LIKE|" #define QUERY_COND_REL_PREFIX_LIKE "LIKE|"
#define QUERY_COND_REL_PREFIX_MATCH "MATCH|" #define QUERY_COND_REL_PREFIX_MATCH "MATCH|"
#define QUERY_COND_REL_PREFIX_NMATCH "NMATCH|"
#define QUERY_COND_REL_PREFIX_IN_LEN 3 #define QUERY_COND_REL_PREFIX_IN_LEN 3
#define QUERY_COND_REL_PREFIX_LIKE_LEN 5 #define QUERY_COND_REL_PREFIX_LIKE_LEN 5
#define QUERY_COND_REL_PREFIX_MATCH_LEN 6 #define QUERY_COND_REL_PREFIX_MATCH_LEN 6
#define QUERY_COND_REL_PREFIX_NMATCH_LEN 7
typedef bool (*__result_filter_fn_t)(const void *, void *); typedef bool (*__result_filter_fn_t)(const void *, void *);
typedef void (*__do_filter_suppl_fn_t)(void *, void *); typedef void (*__do_filter_suppl_fn_t)(void *, void *);
......
...@@ -440,7 +440,16 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { ...@@ -440,7 +440,16 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN, len); memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_MATCH_LEN, len);
pVal->nType = TSDB_DATA_TYPE_BINARY; pVal->nType = TSDB_DATA_TYPE_BINARY;
pVal->nLen = (int32_t)len; pVal->nLen = (int32_t)len;
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_NMATCH, QUERY_COND_REL_PREFIX_NMATCH_LEN) == 0) {
right->nodeType = TSQL_NODE_VALUE;
expr->_node.optr = TSDB_RELATION_NMATCH;
tVariant* pVal = exception_calloc(1, sizeof(tVariant));
right->pVal = pVal;
size_t len = strlen(tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN) + 1;
pVal->pz = exception_malloc(len);
memcpy(pVal->pz, tbnameCond + QUERY_COND_REL_PREFIX_NMATCH_LEN, len);
pVal->nType = TSDB_DATA_TYPE_BINARY;
pVal->nLen = (int32_t)len;
} else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) { } else if (strncmp(tbnameCond, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN) == 0) {
right->nodeType = TSQL_NODE_VALUE; right->nodeType = TSQL_NODE_VALUE;
expr->_node.optr = TSDB_RELATION_IN; expr->_node.optr = TSDB_RELATION_IN;
......
...@@ -165,6 +165,7 @@ do { \ ...@@ -165,6 +165,7 @@ do { \
#define TSDB_RELATION_NOT 13 #define TSDB_RELATION_NOT 13
#define TSDB_RELATION_MATCH 14 #define TSDB_RELATION_MATCH 14
#define TSDB_RELATION_NMATCH 15
#define TSDB_BINARY_OP_ADD 30 #define TSDB_BINARY_OP_ADD 30
#define TSDB_BINARY_OP_SUBTRACT 31 #define TSDB_BINARY_OP_SUBTRACT 31
......
...@@ -38,179 +38,180 @@ ...@@ -38,179 +38,180 @@
#define TK_IS 20 #define TK_IS 20
#define TK_LIKE 21 #define TK_LIKE 21
#define TK_MATCH 22 #define TK_MATCH 22
#define TK_GLOB 23 #define TK_NMATCH 23
#define TK_BETWEEN 24 #define TK_GLOB 24
#define TK_IN 25 #define TK_BETWEEN 25
#define TK_GT 26 #define TK_IN 26
#define TK_GE 27 #define TK_GT 27
#define TK_LT 28 #define TK_GE 28
#define TK_LE 29 #define TK_LT 29
#define TK_BITAND 30 #define TK_LE 30
#define TK_BITOR 31 #define TK_BITAND 31
#define TK_LSHIFT 32 #define TK_BITOR 32
#define TK_RSHIFT 33 #define TK_LSHIFT 33
#define TK_PLUS 34 #define TK_RSHIFT 34
#define TK_MINUS 35 #define TK_PLUS 35
#define TK_DIVIDE 36 #define TK_MINUS 36
#define TK_TIMES 37 #define TK_DIVIDE 37
#define TK_STAR 38 #define TK_TIMES 38
#define TK_SLASH 39 #define TK_STAR 39
#define TK_REM 40 #define TK_SLASH 40
#define TK_CONCAT 41 #define TK_REM 41
#define TK_UMINUS 42 #define TK_CONCAT 42
#define TK_UPLUS 43 #define TK_UMINUS 43
#define TK_BITNOT 44 #define TK_UPLUS 44
#define TK_SHOW 45 #define TK_BITNOT 45
#define TK_DATABASES 46 #define TK_SHOW 46
#define TK_TOPICS 47 #define TK_DATABASES 47
#define TK_FUNCTIONS 48 #define TK_TOPICS 48
#define TK_MNODES 49 #define TK_FUNCTIONS 49
#define TK_DNODES 50 #define TK_MNODES 50
#define TK_ACCOUNTS 51 #define TK_DNODES 51
#define TK_USERS 52 #define TK_ACCOUNTS 52
#define TK_MODULES 53 #define TK_USERS 53
#define TK_QUERIES 54 #define TK_MODULES 54
#define TK_CONNECTIONS 55 #define TK_QUERIES 55
#define TK_STREAMS 56 #define TK_CONNECTIONS 56
#define TK_VARIABLES 57 #define TK_STREAMS 57
#define TK_SCORES 58 #define TK_VARIABLES 58
#define TK_GRANTS 59 #define TK_SCORES 59
#define TK_VNODES 60 #define TK_GRANTS 60
#define TK_DOT 61 #define TK_VNODES 61
#define TK_CREATE 62 #define TK_DOT 62
#define TK_TABLE 63 #define TK_CREATE 63
#define TK_STABLE 64 #define TK_TABLE 64
#define TK_DATABASE 65 #define TK_STABLE 65
#define TK_TABLES 66 #define TK_DATABASE 66
#define TK_STABLES 67 #define TK_TABLES 67
#define TK_VGROUPS 68 #define TK_STABLES 68
#define TK_DROP 69 #define TK_VGROUPS 69
#define TK_TOPIC 70 #define TK_DROP 70
#define TK_FUNCTION 71 #define TK_TOPIC 71
#define TK_DNODE 72 #define TK_FUNCTION 72
#define TK_USER 73 #define TK_DNODE 73
#define TK_ACCOUNT 74 #define TK_USER 74
#define TK_USE 75 #define TK_ACCOUNT 75
#define TK_DESCRIBE 76 #define TK_USE 76
#define TK_DESC 77 #define TK_DESCRIBE 77
#define TK_ALTER 78 #define TK_DESC 78
#define TK_PASS 79 #define TK_ALTER 79
#define TK_PRIVILEGE 80 #define TK_PASS 80
#define TK_LOCAL 81 #define TK_PRIVILEGE 81
#define TK_COMPACT 82 #define TK_LOCAL 82
#define TK_LP 83 #define TK_COMPACT 83
#define TK_RP 84 #define TK_LP 84
#define TK_IF 85 #define TK_RP 85
#define TK_EXISTS 86 #define TK_IF 86
#define TK_AS 87 #define TK_EXISTS 87
#define TK_OUTPUTTYPE 88 #define TK_AS 88
#define TK_AGGREGATE 89 #define TK_OUTPUTTYPE 89
#define TK_BUFSIZE 90 #define TK_AGGREGATE 90
#define TK_PPS 91 #define TK_BUFSIZE 91
#define TK_TSERIES 92 #define TK_PPS 92
#define TK_DBS 93 #define TK_TSERIES 93
#define TK_STORAGE 94 #define TK_DBS 94
#define TK_QTIME 95 #define TK_STORAGE 95
#define TK_CONNS 96 #define TK_QTIME 96
#define TK_STATE 97 #define TK_CONNS 97
#define TK_COMMA 98 #define TK_STATE 98
#define TK_KEEP 99 #define TK_COMMA 99
#define TK_CACHE 100 #define TK_KEEP 100
#define TK_REPLICA 101 #define TK_CACHE 101
#define TK_QUORUM 102 #define TK_REPLICA 102
#define TK_DAYS 103 #define TK_QUORUM 103
#define TK_MINROWS 104 #define TK_DAYS 104
#define TK_MAXROWS 105 #define TK_MINROWS 105
#define TK_BLOCKS 106 #define TK_MAXROWS 106
#define TK_CTIME 107 #define TK_BLOCKS 107
#define TK_WAL 108 #define TK_CTIME 108
#define TK_FSYNC 109 #define TK_WAL 109
#define TK_COMP 110 #define TK_FSYNC 110
#define TK_PRECISION 111 #define TK_COMP 111
#define TK_UPDATE 112 #define TK_PRECISION 112
#define TK_CACHELAST 113 #define TK_UPDATE 113
#define TK_PARTITIONS 114 #define TK_CACHELAST 114
#define TK_UNSIGNED 115 #define TK_PARTITIONS 115
#define TK_TAGS 116 #define TK_UNSIGNED 116
#define TK_USING 117 #define TK_TAGS 117
#define TK_NULL 118 #define TK_USING 118
#define TK_NOW 119 #define TK_NULL 119
#define TK_SELECT 120 #define TK_NOW 120
#define TK_UNION 121 #define TK_SELECT 121
#define TK_ALL 122 #define TK_UNION 122
#define TK_DISTINCT 123 #define TK_ALL 123
#define TK_FROM 124 #define TK_DISTINCT 124
#define TK_VARIABLE 125 #define TK_FROM 125
#define TK_INTERVAL 126 #define TK_VARIABLE 126
#define TK_EVERY 127 #define TK_INTERVAL 127
#define TK_SESSION 128 #define TK_EVERY 128
#define TK_STATE_WINDOW 129 #define TK_SESSION 129
#define TK_FILL 130 #define TK_STATE_WINDOW 130
#define TK_SLIDING 131 #define TK_FILL 131
#define TK_ORDER 132 #define TK_SLIDING 132
#define TK_BY 133 #define TK_ORDER 133
#define TK_ASC 134 #define TK_BY 134
#define TK_GROUP 135 #define TK_ASC 135
#define TK_HAVING 136 #define TK_GROUP 136
#define TK_LIMIT 137 #define TK_HAVING 137
#define TK_OFFSET 138 #define TK_LIMIT 138
#define TK_SLIMIT 139 #define TK_OFFSET 139
#define TK_SOFFSET 140 #define TK_SLIMIT 140
#define TK_WHERE 141 #define TK_SOFFSET 141
#define TK_RESET 142 #define TK_WHERE 142
#define TK_QUERY 143 #define TK_RESET 143
#define TK_SYNCDB 144 #define TK_QUERY 144
#define TK_ADD 145 #define TK_SYNCDB 145
#define TK_COLUMN 146 #define TK_ADD 146
#define TK_MODIFY 147 #define TK_COLUMN 147
#define TK_TAG 148 #define TK_MODIFY 148
#define TK_CHANGE 149 #define TK_TAG 149
#define TK_SET 150 #define TK_CHANGE 150
#define TK_KILL 151 #define TK_SET 151
#define TK_CONNECTION 152 #define TK_KILL 152
#define TK_STREAM 153 #define TK_CONNECTION 153
#define TK_COLON 154 #define TK_STREAM 154
#define TK_ABORT 155 #define TK_COLON 155
#define TK_AFTER 156 #define TK_ABORT 156
#define TK_ATTACH 157 #define TK_AFTER 157
#define TK_BEFORE 158 #define TK_ATTACH 158
#define TK_BEGIN 159 #define TK_BEFORE 159
#define TK_CASCADE 160 #define TK_BEGIN 160
#define TK_CLUSTER 161 #define TK_CASCADE 161
#define TK_CONFLICT 162 #define TK_CLUSTER 162
#define TK_COPY 163 #define TK_CONFLICT 163
#define TK_DEFERRED 164 #define TK_COPY 164
#define TK_DELIMITERS 165 #define TK_DEFERRED 165
#define TK_DETACH 166 #define TK_DELIMITERS 166
#define TK_EACH 167 #define TK_DETACH 167
#define TK_END 168 #define TK_EACH 168
#define TK_EXPLAIN 169 #define TK_END 169
#define TK_FAIL 170 #define TK_EXPLAIN 170
#define TK_FOR 171 #define TK_FAIL 171
#define TK_IGNORE 172 #define TK_FOR 172
#define TK_IMMEDIATE 173 #define TK_IGNORE 173
#define TK_INITIALLY 174 #define TK_IMMEDIATE 174
#define TK_INSTEAD 175 #define TK_INITIALLY 175
#define TK_KEY 176 #define TK_INSTEAD 176
#define TK_OF 177 #define TK_KEY 177
#define TK_RAISE 178 #define TK_OF 178
#define TK_REPLACE 179 #define TK_RAISE 179
#define TK_RESTRICT 180 #define TK_REPLACE 180
#define TK_ROW 181 #define TK_RESTRICT 181
#define TK_STATEMENT 182 #define TK_ROW 182
#define TK_TRIGGER 183 #define TK_STATEMENT 183
#define TK_VIEW 184 #define TK_TRIGGER 184
#define TK_IPTOKEN 185 #define TK_VIEW 185
#define TK_SEMI 186 #define TK_IPTOKEN 186
#define TK_NONE 187 #define TK_SEMI 187
#define TK_PREV 188 #define TK_NONE 188
#define TK_LINEAR 189 #define TK_PREV 189
#define TK_IMPORT 190 #define TK_LINEAR 190
#define TK_TBNAME 191 #define TK_IMPORT 191
#define TK_JOIN 192 #define TK_TBNAME 192
#define TK_INSERT 193 #define TK_JOIN 193
#define TK_INTO 194 #define TK_INSERT 194
#define TK_VALUES 195 #define TK_INTO 195
#define TK_VALUES 196
#define TK_SPACE 300 #define TK_SPACE 300
......
...@@ -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 GLOB BETWEEN IN. %left EQ NE ISNULL NOTNULL IS LIKE MATCH NMATCH 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.
...@@ -753,6 +753,7 @@ expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); } ...@@ -753,6 +753,7 @@ expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
// match expression // match expression
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); }
//in expression //in expression
expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSqlExpr*)Y, TK_IN); } expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSqlExpr*)Y, TK_IN); }
...@@ -919,5 +920,5 @@ cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); s ...@@ -919,5 +920,5 @@ cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y). {X.n += (Z.n + Y.n); s
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED %fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED
DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
LIKE MATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL LIKE MATCH NMATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES. NOW IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES.
...@@ -29,6 +29,7 @@ OptrStr gOptrStr[] = { ...@@ -29,6 +29,7 @@ OptrStr gOptrStr[] = {
{TSDB_RELATION_NOT_EQUAL, "!="}, {TSDB_RELATION_NOT_EQUAL, "!="},
{TSDB_RELATION_LIKE, "like"}, {TSDB_RELATION_LIKE, "like"},
{TSDB_RELATION_MATCH, "match"}, {TSDB_RELATION_MATCH, "match"},
{TSDB_RELATION_MATCH, "nmatch"},
{TSDB_RELATION_ISNULL, "is null"}, {TSDB_RELATION_ISNULL, "is null"},
{TSDB_RELATION_NOTNULL, "not null"}, {TSDB_RELATION_NOTNULL, "not null"},
{TSDB_RELATION_IN, "in"}, {TSDB_RELATION_IN, "in"},
...@@ -157,7 +158,7 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { ...@@ -157,7 +158,7 @@ int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) {
__compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal, __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal,
compareDoubleVal, compareLenPrefixedStr, compareStrPatternComp, compareFindItemInSet, compareWStrPatternComp, compareDoubleVal, compareLenPrefixedStr, compareStrPatternComp, compareFindItemInSet, compareWStrPatternComp,
compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val,
setCompareBytes1, setCompareBytes2, setCompareBytes4, setCompareBytes8, compareStrRegexComp, setCompareBytes1, setCompareBytes2, setCompareBytes4, setCompareBytes8, compareStrRegexCompMatch, compareStrRegexCompNMatch
}; };
int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
...@@ -198,6 +199,8 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { ...@@ -198,6 +199,8 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == TSDB_RELATION_MATCH) { if (optr == TSDB_RELATION_MATCH) {
comparFn = 19; comparFn = 19;
} else if (optr == TSDB_RELATION_NMATCH) {
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 = 7; comparFn = 7;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
...@@ -212,6 +215,8 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { ...@@ -212,6 +215,8 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
if (optr == TSDB_RELATION_MATCH) { if (optr == TSDB_RELATION_MATCH) {
comparFn = 19; comparFn = 19;
} else if (optr == TSDB_RELATION_NMATCH) {
comparFn = 20;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == TSDB_RELATION_LIKE) {
comparFn = 9; comparFn = 9;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
...@@ -1879,6 +1884,9 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) ...@@ -1879,6 +1884,9 @@ 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_NMATCH: {
return ret == 0;
}
case TSDB_RELATION_IN: { case TSDB_RELATION_IN: {
return ret == 1; return ret == 1;
} }
......
此差异已折叠。
...@@ -3712,6 +3712,9 @@ static bool tableFilterFp(const void* pNode, void* param) { ...@@ -3712,6 +3712,9 @@ static bool tableFilterFp(const void* pNode, void* param) {
case TSDB_RELATION_MATCH: { case TSDB_RELATION_MATCH: {
return ret == 0; return ret == 0;
} }
case TSDB_RELATION_NMATCH: {
return ret == 0;
}
case TSDB_RELATION_IN: { case TSDB_RELATION_IN: {
return ret == 1; return ret == 1;
} }
...@@ -4047,6 +4050,8 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) { ...@@ -4047,6 +4050,8 @@ static int32_t setQueryCond(tQueryInfo *queryColInfo, SQueryCond* pCond) {
assert(0); assert(0);
} else if (optr == TSDB_RELATION_MATCH) { } else if (optr == TSDB_RELATION_MATCH) {
assert(0); assert(0);
} else if (optr == TSDB_RELATION_NMATCH) {
assert(0);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -4204,7 +4209,9 @@ static void queryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, S ...@@ -4204,7 +4209,9 @@ static void queryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo, S
if (pQueryInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) { if (pQueryInfo->sch.colId == TSDB_TBNAME_COLUMN_INDEX) {
if (pQueryInfo->optr == TSDB_RELATION_IN) { if (pQueryInfo->optr == TSDB_RELATION_IN) {
addToResult = pQueryInfo->compare(name, pQueryInfo->q); addToResult = pQueryInfo->compare(name, pQueryInfo->q);
} else if (pQueryInfo->optr == TSDB_RELATION_LIKE || pQueryInfo->optr == TSDB_RELATION_MATCH) { } else if (pQueryInfo->optr == TSDB_RELATION_LIKE ||
pQueryInfo->optr == TSDB_RELATION_MATCH ||
pQueryInfo->optr == TSDB_RELATION_NMATCH) {
addToResult = !pQueryInfo->compare(name, pQueryInfo->q); addToResult = !pQueryInfo->compare(name, pQueryInfo->q);
} }
} else { } else {
...@@ -4236,7 +4243,8 @@ void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *re ...@@ -4236,7 +4243,8 @@ void getTableListfromSkipList(tExprNode *pExpr, SSkipList *pSkipList, SArray *re
param->setupInfoFn(pExpr, param->pExtInfo); param->setupInfoFn(pExpr, param->pExtInfo);
tQueryInfo *pQueryInfo = pExpr->_node.info; tQueryInfo *pQueryInfo = pExpr->_node.info;
if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE && pQueryInfo->optr != TSDB_RELATION_MATCH if (pQueryInfo->indexed && (pQueryInfo->optr != TSDB_RELATION_LIKE
&& pQueryInfo->optr != TSDB_RELATION_MATCH && pQueryInfo->optr != TSDB_RELATION_NMATCH
&& pQueryInfo->optr != TSDB_RELATION_IN)) { && pQueryInfo->optr != TSDB_RELATION_IN)) {
queryIndexedColumn(pSkipList, pQueryInfo, result); queryIndexedColumn(pSkipList, pQueryInfo, result);
} else { } else {
......
...@@ -84,6 +84,8 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight); ...@@ -84,6 +84,8 @@ int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight);
int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight); int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight);
int32_t compareStrPatternComp(const void* pLeft, const void* pRight); int32_t compareStrPatternComp(const void* pLeft, const void* pRight);
int32_t compareStrRegexComp(const void* pLeft, const void* pRight); int32_t compareStrRegexComp(const void* pLeft, const void* pRight);
int32_t compareStrRegexCompMatch(const void* pLeft, const void* pRight);
int32_t compareStrRegexCompNMatch(const void* pLeft, const void* pRight);
int32_t compareFindItemInSet(const void *pLeft, const void* pRight); int32_t compareFindItemInSet(const void *pLeft, const void* pRight);
int32_t compareWStrPatternComp(const void* pLeft, const void* pRight); int32_t compareWStrPatternComp(const void* pLeft, const void* pRight);
......
...@@ -350,6 +350,14 @@ int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { ...@@ -350,6 +350,14 @@ int32_t compareStrPatternComp(const void* pLeft, const void* pRight) {
return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; return (ret == TSDB_PATTERN_MATCH) ? 0 : 1;
} }
int32_t compareStrRegexCompMatch(const void* pLeft, const void* pRight) {
return compareStrRegexComp(pLeft, pRight);
}
int32_t compareStrRegexCompNMatch(const void* pLeft, const void* pRight) {
return compareStrRegexComp(pLeft, pRight) ? 0 : 1;
}
int32_t compareStrRegexComp(const void* pLeft, const void* pRight) { int32_t compareStrRegexComp(const void* pLeft, const void* pRight) {
size_t sz = varDataLen(pRight); size_t sz = varDataLen(pRight);
char *pattern = malloc(sz + 1); char *pattern = malloc(sz + 1);
...@@ -449,7 +457,9 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -449,7 +457,9 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_DOUBLE: comparFn = compareDoubleVal; break; case TSDB_DATA_TYPE_DOUBLE: comparFn = compareDoubleVal; break;
case TSDB_DATA_TYPE_BINARY: { case TSDB_DATA_TYPE_BINARY: {
if (optr == TSDB_RELATION_MATCH) { if (optr == TSDB_RELATION_MATCH) {
comparFn = compareStrRegexComp; comparFn = compareStrRegexCompMatch;
} else if (optr == TSDB_RELATION_NMATCH) {
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 = compareStrPatternComp; comparFn = compareStrPatternComp;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
...@@ -463,7 +473,9 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { ...@@ -463,7 +473,9 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) {
case TSDB_DATA_TYPE_NCHAR: { case TSDB_DATA_TYPE_NCHAR: {
if (optr == TSDB_RELATION_MATCH) { if (optr == TSDB_RELATION_MATCH) {
comparFn = compareStrRegexComp; comparFn = compareStrRegexCompMatch;
} else if (optr == TSDB_RELATION_NMATCH) {
comparFn = compareStrRegexCompNMatch;
} else if (optr == TSDB_RELATION_LIKE) { } else if (optr == TSDB_RELATION_LIKE) {
comparFn = compareWStrPatternComp; comparFn = compareWStrPatternComp;
} else if (optr == TSDB_RELATION_IN) { } else if (optr == TSDB_RELATION_IN) {
......
...@@ -195,6 +195,7 @@ static SKeyword keywordTable[] = { ...@@ -195,6 +195,7 @@ static SKeyword keywordTable[] = {
{"INITIALLY", TK_INITIALLY}, {"INITIALLY", TK_INITIALLY},
{"INSTEAD", TK_INSTEAD}, {"INSTEAD", TK_INSTEAD},
{"MATCH", TK_MATCH}, {"MATCH", TK_MATCH},
{"NMATCH", TK_NMATCH},
{"KEY", TK_KEY}, {"KEY", TK_KEY},
{"OF", TK_OF}, {"OF", TK_OF},
{"RAISE", TK_RAISE}, {"RAISE", TK_RAISE},
......
...@@ -29,13 +29,22 @@ endi ...@@ -29,13 +29,22 @@ endi
sql select tbname from $st_name where tbname match '^ct[[:digit:]]' sql select tbname from $st_name where tbname match '^ct[[:digit:]]'
if $rows != 2 then if $rows != 2 then
return -1 return -1
endi endi
sql select tbname from $st_name where tbname nmatch '^ct[[:digit:]]'
if $rows != 1 then
return -1
endi
sql select tbname from $st_name where tbname match '.*' sql select tbname from $st_name where tbname match '.*'
if $rows !=3 then if $rows != 3 then
return -1
endi
sql select tbname from $st_name where tbname nmatch '.*'
if $rows != 0 then
return -1 return -1
endi endi
...@@ -44,6 +53,11 @@ if $rows != 2 then ...@@ -44,6 +53,11 @@ if $rows != 2 then
return -1 return -1
endi endi
sql select tbname from $st_name where t1b nmatch '[[:lower:]]+'
if $rows != 1 then
return -1
endi
sql insert into $ct1_name values(now, 'this is engine') sql insert into $ct1_name values(now, 'this is engine')
sql insert into $ct2_name values(now, 'this is app egnine') sql insert into $ct2_name values(now, 'this is app egnine')
...@@ -56,6 +70,14 @@ if $rows != 1 then ...@@ -56,6 +70,14 @@ if $rows != 1 then
return -1 return -1
endi endi
sql select c1b from $st_name where c1b nmatch 'engine'
if $data00 != @this is app egnine@ then
return -1
endi
if $rows != 1 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册