提交 6b818f2c 编写于 作者: X xywang

feat(query): added bitwise operations

上级 a180c499
此差异已折叠。
......@@ -1026,7 +1026,7 @@ static void doSetupSDataBlock(SSqlRes* pRes, SSDataBlock* pBlock, void* pFilterI
int8_t* p = NULL;
//bool all = doFilterDataBlock(pFilterInfo, numOfFilterCols, pBlock->info.rows, p);
bool all = filterExecute(pFilterInfo, pBlock->info.rows, &p, NULL, 0);
bool all = filterExecute(pFilterInfo, pBlock->info.rows, &p, NULL, (int16_t)taosArrayGetSize(pBlock->pDataBlock));
if (!all) {
if (p) {
doCompactSDataBlock(pBlock, pBlock->info.rows, p);
......
此差异已折叠。
......@@ -109,7 +109,6 @@ int32_t exprTreeValidateFunctionNode(char* msgbuf, tExprNode *pExpr) {
int32_t exprTreeValidateExprNode(tExprNode *pExpr) {
int16_t leftType = pExpr->_node.pLeft->resultType;
int16_t rightType = pExpr->_node.pRight->resultType;
int16_t resultType = leftType;
if (pExpr->_node.optr == TSDB_BINARY_OP_ADD || pExpr->_node.optr == TSDB_BINARY_OP_SUBTRACT ||
pExpr->_node.optr == TSDB_BINARY_OP_MULTIPLY || pExpr->_node.optr == TSDB_BINARY_OP_DIVIDE ||
......@@ -135,171 +134,31 @@ int32_t exprTreeValidateExprNode(tExprNode *pExpr) {
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
}
return TSDB_CODE_SUCCESS;
} else if (pExpr->_node.optr == TSDB_BINARY_OP_BITAND) {
if ((leftType != TSDB_DATA_TYPE_BOOL && !IS_SIGNED_NUMERIC_TYPE(leftType) && !IS_UNSIGNED_NUMERIC_TYPE(leftType)) ||
(rightType != TSDB_DATA_TYPE_BOOL && !IS_SIGNED_NUMERIC_TYPE(rightType) && !IS_UNSIGNED_NUMERIC_TYPE(rightType)))
{
} else if (pExpr->_node.optr == TSDB_BINARY_OP_BITAND || pExpr->_node.optr == TSDB_BINARY_OP_BITOR ||
pExpr->_node.optr == TSDB_BINARY_OP_BITXOR || pExpr->_node.optr == TSDB_BINARY_OP_LSHIFT ||
pExpr->_node.optr == TSDB_BINARY_OP_RSHIFT)
{
if (!IS_NUMERIC_TYPE(leftType) || !IS_NUMERIC_TYPE(rightType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
uint8_t schemaType;
// now leftType and rightType are both numeric
if (pExpr->_node.pLeft->nodeType == TSQL_NODE_COL && pExpr->_node.pRight->nodeType == TSQL_NODE_COL) {
if (leftType != rightType) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
} else if (pExpr->_node.pLeft->nodeType == TSQL_NODE_COL) {
if (pExpr->_node.pRight->nodeType != TSQL_NODE_VALUE) {
return TSDB_CODE_TSC_INVALID_OPERATION;
} else {
schemaType = pExpr->_node.pLeft->pSchema->type;
int64_t sVal = pExpr->_node.pRight->pVal->i64;
uint64_t uVal = pExpr->_node.pRight->pVal->u64;
switch (schemaType) {
case TSDB_DATA_TYPE_BOOL:
if ((pExpr->_node.pRight->pVal->nType != TSDB_DATA_TYPE_BOOL) ||
(pExpr->_node.pRight->pVal->i64 != 0 &&
pExpr->_node.pRight->pVal->i64 != 1 &&
pExpr->_node.pRight->pVal->i64 != TSDB_DATA_BOOL_NULL))
{
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_TINYINT:
if (sVal < -128 || sVal > 127) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_SMALLINT:
if (sVal < -32768 || sVal > 32767) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_INT:
if (sVal < INT32_MIN || sVal > INT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_BIGINT:
if (sVal < INT64_MIN || sVal > INT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_UTINYINT:
if (uVal > 255) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_USMALLINT:
if (uVal > 65535) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_UINT:
if (uVal > UINT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
case TSDB_DATA_TYPE_UBIGINT:
if (uVal > UINT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
}
pExpr->_node.pRight->pSchema->type = schemaType;
pExpr->_node.pRight->pVal->nType = schemaType;
pExpr->_node.pRight->resultType = schemaType;
pExpr->_node.pRight->resultBytes = tDataTypes[schemaType].bytes;
}
} else {
if (pExpr->_node.pLeft->nodeType != TSQL_NODE_VALUE) {
return TSDB_CODE_TSC_INVALID_OPERATION;
} else {
schemaType = pExpr->_node.pRight->pSchema->type;
int64_t sVal = pExpr->_node.pLeft->pVal->i64;
uint64_t uVal = pExpr->_node.pLeft->pVal->u64;
switch (schemaType) {
case TSDB_DATA_TYPE_BOOL:
if ((pExpr->_node.pLeft->pVal->nType != TSDB_DATA_TYPE_BOOL) ||
(pExpr->_node.pLeft->pVal->i64 != 0 &&
pExpr->_node.pLeft->pVal->i64 != 1 &&
pExpr->_node.pLeft->pVal->i64 != TSDB_DATA_BOOL_NULL))
{
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 1;
break;
case TSDB_DATA_TYPE_TINYINT:
if (sVal < -128 || sVal > 127) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 1;
break;
case TSDB_DATA_TYPE_SMALLINT:
if (sVal < -32768 || sVal > 32767) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 2;
break;
case TSDB_DATA_TYPE_INT:
if (sVal < INT32_MIN || sVal > INT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 4;
break;
case TSDB_DATA_TYPE_BIGINT:
if (sVal < INT64_MIN || sVal > INT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 8;
break;
case TSDB_DATA_TYPE_UTINYINT:
if (uVal > 255) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 1;
break;
case TSDB_DATA_TYPE_USMALLINT:
if (uVal > 65535) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 2;
break;
case TSDB_DATA_TYPE_UINT:
if (uVal > UINT32_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 4;
break;
case TSDB_DATA_TYPE_UBIGINT:
if (uVal > UINT64_MAX) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->_node.pLeft->pVal->nLen = 8;
break;
}
pExpr->_node.pLeft->pSchema->type = schemaType;
pExpr->_node.pLeft->pVal->nType = schemaType;
pExpr->_node.pLeft->resultType = schemaType;
pExpr->_node.pLeft->resultBytes = tDataTypes[schemaType].bytes;
}
resultType = schemaType;
if (IS_FLOAT_TYPE(leftType) || IS_FLOAT_TYPE(rightType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if (resultType == TSDB_DATA_TYPE_BOOL) {
pExpr->resultType = TSDB_DATA_TYPE_BOOL;
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
if (pExpr->_node.optr == TSDB_BINARY_OP_LSHIFT || pExpr->_node.optr == TSDB_BINARY_OP_RSHIFT) {
pExpr->resultType = leftType;
pExpr->resultBytes = tDataTypes[leftType].bytes;
} else {
pExpr->resultType = resultType;
pExpr->resultBytes = tDataTypes[resultType].bytes;
pExpr->resultType = TSDB_DATA_TYPE_BIGINT;
pExpr->resultBytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes;
}
return TSDB_CODE_SUCCESS;
} else if (pExpr->_node.optr == TSDB_BINARY_OP_BITNOT) {
if (!IS_NUMERIC_TYPE(leftType) || IS_FLOAT_TYPE(leftType)) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
pExpr->resultType = leftType;
pExpr->resultBytes = tDataTypes[leftType].bytes;
return TSDB_CODE_SUCCESS;
} else {
return TSDB_CODE_SUCCESS;
}
......@@ -689,6 +548,9 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
rightType = pRight->pSchema->type;
rightNum = numOfRows;
} else if (pRight->nodeType == TSQL_NODE_DUMMY) {
/* BITNOT */
rightNum = 0;
} else {
assert(pRight->nodeType == TSQL_NODE_VALUE);
rightIn = (char *)&pRight->pVal->i64;
......@@ -703,7 +565,10 @@ void exprTreeExprNodeTraverse(tExprNode *pExpr, int32_t numOfRows, tExprOperandI
if(leftType == TSDB_DATA_TYPE_TIMESTAMP || rightType == TSDB_DATA_TYPE_TIMESTAMP) {
output->type = TSDB_DATA_TYPE_BIGINT;
} else {
if (pExpr->_node.optr == TSDB_BINARY_OP_BITAND) {
if (pExpr->_node.optr == TSDB_BINARY_OP_BITAND || pExpr->_node.optr == TSDB_BINARY_OP_BITOR ||
pExpr->_node.optr == TSDB_BINARY_OP_BITXOR || pExpr->_node.optr == TSDB_BINARY_OP_BITNOT ||
pExpr->_node.optr == TSDB_BINARY_OP_LSHIFT || pExpr->_node.optr == TSDB_BINARY_OP_RSHIFT)
{
output->type = leftType; // rightType must be the same as leftType
} else {
output->type = TSDB_DATA_TYPE_DOUBLE;
......
......@@ -184,10 +184,15 @@ do { \
#define TSDB_BINARY_OP_DIVIDE 33
#define TSDB_BINARY_OP_REMAINDER 34
#define TSDB_BINARY_OP_BITAND 35
#define TSDB_BINARY_OP_BITOR 36
#define TSDB_BINARY_OP_BITXOR 37
#define TSDB_BINARY_OP_BITNOT 38
#define TSDB_BINARY_OP_LSHIFT 39
#define TSDB_BINARY_OP_RSHIFT 40
#define IS_RELATION_OPTR(op) (((op) >= TSDB_RELATION_LESS) && ((op) < TSDB_RELATION_IN))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_BITAND))
#define IS_ARITHMETIC_OPTR(op) (((op) >= TSDB_BINARY_OP_ADD) && ((op) <= TSDB_BINARY_OP_RSHIFT))
#define TS_PATH_DELIMITER_LEN 1
......
......@@ -50,177 +50,177 @@
#define TK_LE 32
#define TK_BITAND 33
#define TK_BITOR 34
#define TK_LSHIFT 35
#define TK_RSHIFT 36
#define TK_PLUS 37
#define TK_MINUS 38
#define TK_DIVIDE 39
#define TK_TIMES 40
#define TK_STAR 41
#define TK_SLASH 42
#define TK_REM 43
#define TK_UMINUS 44
#define TK_UPLUS 45
#define TK_BITNOT 46
#define TK_ARROW 47
#define TK_SHOW 48
#define TK_DATABASES 49
#define TK_TOPICS 50
#define TK_FUNCTIONS 51
#define TK_MNODES 52
#define TK_DNODES 53
#define TK_ACCOUNTS 54
#define TK_USERS 55
#define TK_MODULES 56
#define TK_QUERIES 57
#define TK_CONNECTIONS 58
#define TK_STREAMS 59
#define TK_VARIABLES 60
#define TK_SCORES 61
#define TK_GRANTS 62
#define TK_VNODES 63
#define TK_DOT 64
#define TK_CREATE 65
#define TK_TABLE 66
#define TK_STABLE 67
#define TK_DATABASE 68
#define TK_TABLES 69
#define TK_STABLES 70
#define TK_VGROUPS 71
#define TK_DROP 72
#define TK_TOPIC 73
#define TK_FUNCTION 74
#define TK_DNODE 75
#define TK_USER 76
#define TK_ACCOUNT 77
#define TK_USE 78
#define TK_DESCRIBE 79
#define TK_DESC 80
#define TK_ALTER 81
#define TK_PASS 82
#define TK_PRIVILEGE 83
#define TK_LOCAL 84
#define TK_COMPACT 85
#define TK_LP 86
#define TK_RP 87
#define TK_IF 88
#define TK_EXISTS 89
#define TK_AS 90
#define TK_OUTPUTTYPE 91
#define TK_AGGREGATE 92
#define TK_BUFSIZE 93
#define TK_PPS 94
#define TK_TSERIES 95
#define TK_DBS 96
#define TK_STORAGE 97
#define TK_QTIME 98
#define TK_CONNS 99
#define TK_STATE 100
#define TK_COMMA 101
#define TK_KEEP 102
#define TK_CACHE 103
#define TK_REPLICA 104
#define TK_QUORUM 105
#define TK_DAYS 106
#define TK_MINROWS 107
#define TK_MAXROWS 108
#define TK_BLOCKS 109
#define TK_CTIME 110
#define TK_WAL 111
#define TK_FSYNC 112
#define TK_COMP 113
#define TK_PRECISION 114
#define TK_UPDATE 115
#define TK_CACHELAST 116
#define TK_PARTITIONS 117
#define TK_UNSIGNED 118
#define TK_TAGS 119
#define TK_USING 120
#define TK_TO 121
#define TK_SPLIT 122
#define TK_NULL 123
#define TK_NOW 124
#define TK_VARIABLE 125
#define TK_SELECT 126
#define TK_UNION 127
#define TK_ALL 128
#define TK_DISTINCT 129
#define TK_FROM 130
#define TK_RANGE 131
#define TK_INTERVAL 132
#define TK_EVERY 133
#define TK_SESSION 134
#define TK_STATE_WINDOW 135
#define TK_FILL 136
#define TK_SLIDING 137
#define TK_ORDER 138
#define TK_BY 139
#define TK_ASC 140
#define TK_GROUP 141
#define TK_HAVING 142
#define TK_LIMIT 143
#define TK_OFFSET 144
#define TK_SLIMIT 145
#define TK_SOFFSET 146
#define TK_WHERE 147
#define TK_TODAY 148
#define TK_RESET 149
#define TK_QUERY 150
#define TK_SYNCDB 151
#define TK_ADD 152
#define TK_COLUMN 153
#define TK_MODIFY 154
#define TK_TAG 155
#define TK_CHANGE 156
#define TK_SET 157
#define TK_KILL 158
#define TK_CONNECTION 159
#define TK_STREAM 160
#define TK_COLON 161
#define TK_DELETE 162
#define TK_ABORT 163
#define TK_AFTER 164
#define TK_ATTACH 165
#define TK_BEFORE 166
#define TK_BEGIN 167
#define TK_CASCADE 168
#define TK_CLUSTER 169
#define TK_CONFLICT 170
#define TK_COPY 171
#define TK_DEFERRED 172
#define TK_DELIMITERS 173
#define TK_DETACH 174
#define TK_EACH 175
#define TK_END 176
#define TK_EXPLAIN 177
#define TK_FAIL 178
#define TK_FOR 179
#define TK_IGNORE 180
#define TK_IMMEDIATE 181
#define TK_INITIALLY 182
#define TK_INSTEAD 183
#define TK_KEY 184
#define TK_OF 185
#define TK_RAISE 186
#define TK_REPLACE 187
#define TK_RESTRICT 188
#define TK_ROW 189
#define TK_STATEMENT 190
#define TK_TRIGGER 191
#define TK_VIEW 192
#define TK_IPTOKEN 193
#define TK_SEMI 194
#define TK_NONE 195
#define TK_PREV 196
#define TK_LINEAR 197
#define TK_IMPORT 198
#define TK_TBNAME 199
#define TK_JOIN 200
#define TK_INSERT 201
#define TK_INTO 202
#define TK_VALUES 203
#define TK_FILE 204
#define TK_BITXOR 35
#define TK_LSHIFT 36
#define TK_RSHIFT 37
#define TK_PLUS 38
#define TK_MINUS 39
#define TK_DIVIDE 40
#define TK_TIMES 41
#define TK_STAR 42
#define TK_SLASH 43
#define TK_REM 44
#define TK_UMINUS 45
#define TK_UPLUS 46
#define TK_BITNOT 47
#define TK_ARROW 48
#define TK_SHOW 49
#define TK_DATABASES 50
#define TK_TOPICS 51
#define TK_FUNCTIONS 52
#define TK_MNODES 53
#define TK_DNODES 54
#define TK_ACCOUNTS 55
#define TK_USERS 56
#define TK_MODULES 57
#define TK_QUERIES 58
#define TK_CONNECTIONS 59
#define TK_STREAMS 60
#define TK_VARIABLES 61
#define TK_SCORES 62
#define TK_GRANTS 63
#define TK_VNODES 64
#define TK_DOT 65
#define TK_CREATE 66
#define TK_TABLE 67
#define TK_STABLE 68
#define TK_DATABASE 69
#define TK_TABLES 70
#define TK_STABLES 71
#define TK_VGROUPS 72
#define TK_DROP 73
#define TK_TOPIC 74
#define TK_FUNCTION 75
#define TK_DNODE 76
#define TK_USER 77
#define TK_ACCOUNT 78
#define TK_USE 79
#define TK_DESCRIBE 80
#define TK_DESC 81
#define TK_ALTER 82
#define TK_PASS 83
#define TK_PRIVILEGE 84
#define TK_LOCAL 85
#define TK_COMPACT 86
#define TK_LP 87
#define TK_RP 88
#define TK_IF 89
#define TK_EXISTS 90
#define TK_AS 91
#define TK_OUTPUTTYPE 92
#define TK_AGGREGATE 93
#define TK_BUFSIZE 94
#define TK_PPS 95
#define TK_TSERIES 96
#define TK_DBS 97
#define TK_STORAGE 98
#define TK_QTIME 99
#define TK_CONNS 100
#define TK_STATE 101
#define TK_COMMA 102
#define TK_KEEP 103
#define TK_CACHE 104
#define TK_REPLICA 105
#define TK_QUORUM 106
#define TK_DAYS 107
#define TK_MINROWS 108
#define TK_MAXROWS 109
#define TK_BLOCKS 110
#define TK_CTIME 111
#define TK_WAL 112
#define TK_FSYNC 113
#define TK_COMP 114
#define TK_PRECISION 115
#define TK_UPDATE 116
#define TK_CACHELAST 117
#define TK_PARTITIONS 118
#define TK_UNSIGNED 119
#define TK_TAGS 120
#define TK_USING 121
#define TK_TO 122
#define TK_SPLIT 123
#define TK_NULL 124
#define TK_NOW 125
#define TK_VARIABLE 126
#define TK_SELECT 127
#define TK_UNION 128
#define TK_ALL 129
#define TK_DISTINCT 130
#define TK_FROM 131
#define TK_RANGE 132
#define TK_INTERVAL 133
#define TK_EVERY 134
#define TK_SESSION 135
#define TK_STATE_WINDOW 136
#define TK_FILL 137
#define TK_SLIDING 138
#define TK_ORDER 139
#define TK_BY 140
#define TK_ASC 141
#define TK_GROUP 142
#define TK_HAVING 143
#define TK_LIMIT 144
#define TK_OFFSET 145
#define TK_SLIMIT 146
#define TK_SOFFSET 147
#define TK_WHERE 148
#define TK_TODAY 149
#define TK_RESET 150
#define TK_QUERY 151
#define TK_SYNCDB 152
#define TK_ADD 153
#define TK_COLUMN 154
#define TK_MODIFY 155
#define TK_TAG 156
#define TK_CHANGE 157
#define TK_SET 158
#define TK_KILL 159
#define TK_CONNECTION 160
#define TK_STREAM 161
#define TK_COLON 162
#define TK_DELETE 163
#define TK_ABORT 164
#define TK_AFTER 165
#define TK_ATTACH 166
#define TK_BEFORE 167
#define TK_BEGIN 168
#define TK_CASCADE 169
#define TK_CLUSTER 170
#define TK_CONFLICT 171
#define TK_COPY 172
#define TK_DEFERRED 173
#define TK_DELIMITERS 174
#define TK_DETACH 175
#define TK_EACH 176
#define TK_END 177
#define TK_EXPLAIN 178
#define TK_FAIL 179
#define TK_FOR 180
#define TK_IGNORE 181
#define TK_IMMEDIATE 182
#define TK_INITIALLY 183
#define TK_INSTEAD 184
#define TK_KEY 185
#define TK_OF 186
#define TK_RAISE 187
#define TK_REPLACE 188
#define TK_RESTRICT 189
#define TK_ROW 190
#define TK_STATEMENT 191
#define TK_TRIGGER 192
#define TK_VIEW 193
#define TK_IPTOKEN 194
#define TK_SEMI 195
#define TK_NONE 196
#define TK_PREV 197
#define TK_LINEAR 198
#define TK_IMPORT 199
#define TK_TBNAME 200
#define TK_JOIN 201
#define TK_INSERT 202
#define TK_INTO 203
#define TK_VALUES 204
#define TK_FILE 205
#define TK_SPACE 300
#define TK_COMMENT 301
......
......@@ -293,6 +293,7 @@ int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bo
#define SET_DOUBLE_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_DOUBLE_NULL)
#define SET_TIMESTAMP_NULL(v) (*(uint64_t *)(v) = TSDB_DATA_TIMESTAMP_NULL)
#define SET_BIGINT_NULL(v) (*(int64_t *)(v) = TSDB_DATA_BIGINT_NULL)
#ifdef __cplusplus
}
......
......@@ -244,22 +244,34 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
int64_t st, et;
wordexp_t full_path;
char * sptr = NULL;
char * tmp = NULL;
char * cptr = NULL;
char * fname = NULL;
bool printMode = false;
if ((sptr = tstrstr(command, ">>", true)) != NULL) {
cptr = tstrstr(command, ";", true);
if (cptr != NULL) {
*cptr = '\0';
}
sptr = command;
while ((sptr = tstrstr(sptr, ">>", true)) != NULL) {
// find the last ">>" if any
tmp = sptr;
sptr += 2;
}
if (wordexp(sptr + 2, &full_path, 0) != 0) {
fprintf(stderr, "ERROR: invalid filename: %s\n", sptr + 2);
return;
sptr = tmp;
if (sptr != NULL) {
if (regex_match(sptr + 2, "^\\s*[0-9]+\\s*[\\>|\\<|\\<=|\\>=|=|!=]\\s*.*;\\s*$", REG_EXTENDED | REG_ICASE) == 0) {
cptr = tstrstr(command, ";", true);
if (cptr != NULL) {
*cptr = '\0';
}
if (wordexp(sptr + 2, &full_path, 0) != 0) {
fprintf(stderr, "ERROR: invalid filename: %s\n", sptr + 2);
return;
}
*sptr = '\0';
fname = full_path.we_wordv[0];
}
*sptr = '\0';
fname = full_path.we_wordv[0];
}
if ((sptr = tstrstr(command, "\\G", true)) != NULL) {
......
......@@ -38,11 +38,12 @@ extern "C" {
enum {
FLD_TYPE_COLUMN = 1,
FLD_TYPE_VALUE = 2,
FLD_TYPE_MAX = 3,
FLD_DESC_NO_FREE = 4,
FLD_DATA_NO_FREE = 8,
FLD_DATA_IS_HASH = 16,
FLD_TYPE_VALUE = 2,
FLD_TYPE_EXPR = 3,
FLD_TYPE_MAX = 4,
FLD_DESC_NO_FREE = 16,
FLD_DATA_NO_FREE = 32,
FLD_DATA_IS_HASH = 64
};
enum {
......@@ -182,6 +183,7 @@ typedef struct SFilterGroupCtx {
uint32_t colNum;
uint32_t *colIdx;
SFilterColInfo *colInfo;
bool hasExpr;
} SFilterGroupCtx;
typedef struct SFilterColCtx {
......@@ -206,6 +208,8 @@ typedef struct SFilterComUnit {
void *colData;
void *valData;
void *valData2;
void *expr;
void *exprData;
uint16_t colId;
uint16_t dataSize;
uint8_t dataType;
......@@ -289,7 +293,10 @@ typedef struct SFilterInfo {
#define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType)
#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data)
#define FILTER_GET_JSON_VAL_FIELD_DATA(fi) ((char *)(fi)->desc)
#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX)
#define FILTER_GET_TYPE(fl) ((fl) & 0xF)
#define FILTER_GET_FIELD_DESC(fi) ((fi)->desc)
#define FILTER_GET_EXPR_TYPE(i, id) (((tExprNode*)(FILTER_GET_FIELD_DESC(FILTER_GET_FIELD(i, id))))->resultType)
#define FILTER_GET_EXPR_SIZE(i, id) (((tExprNode*)(FILTER_GET_FIELD_DESC(FILTER_GET_FIELD(i, id))))->resultBytes)
#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid])
#define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left)
......
......@@ -13,7 +13,7 @@
%right NOT.
%left EQ NE ISNULL NOTNULL IS LIKE MATCH NMATCH CONTAINS GLOB BETWEEN IN.
%left GT GE LT LE.
%left BITAND BITOR LSHIFT RSHIFT.
%left BITAND BITOR BITXOR LSHIFT RSHIFT.
%left PLUS MINUS.
%left DIVIDE TIMES.
%left STAR SLASH REM.
......@@ -802,6 +802,11 @@ expr(A) ::= expr(X) STAR expr(Y). {A = tSqlExprCreate(X, Y, TK_STAR); }
expr(A) ::= expr(X) SLASH expr(Y). {A = tSqlExprCreate(X, Y, TK_DIVIDE);}
expr(A) ::= expr(X) REM expr(Y). {A = tSqlExprCreate(X, Y, TK_REM); }
expr(A) ::= expr(X) BITAND expr(Y). {A = tSqlExprCreate(X, Y, TK_BITAND);}
expr(A) ::= expr(X) BITOR expr(Y). {A = tSqlExprCreate(X, Y, TK_BITOR); }
expr(A) ::= expr(X) BITXOR expr(Y). {A = tSqlExprCreate(X, Y, TK_BITXOR);}
expr(A) ::= BITNOT expr(X). {A = tSqlExprCreate(X, NULL, TK_BITNOT);}
expr(A) ::= expr(X) LSHIFT expr(Y). {A = tSqlExprCreate(X, Y, TK_LSHIFT);}
expr(A) ::= expr(X) RSHIFT expr(Y). {A = tSqlExprCreate(X, Y, TK_RSHIFT);}
// like expression
expr(A) ::= expr(X) LIKE expr(Y). {A = tSqlExprCreate(X, Y, TK_LIKE); }
......@@ -997,4 +1002,4 @@ cmd ::= DELETE FROM ifexists(Y) ids(X) cpxName(Z) where_opt(W). {
%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
LIKE MATCH NMATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
NOW TODAY IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES FILE.
\ No newline at end of file
NOW TODAY IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES FILE.
......@@ -3164,6 +3164,10 @@ void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFi
FORCE_INLINE int32_t getColumnDataFromId(void *param, int32_t id, void **data) {
int32_t numOfCols = ((SColumnDataParam *)param)->numOfCols;
SArray* pDataBlock = ((SColumnDataParam *)param)->pDataBlock;
if (id == INT32_MAX) {
*data = pDataBlock;
return TSDB_CODE_SUCCESS;
}
for (int32_t j = 0; j < numOfCols; ++j) {
SColumnInfoData* pColInfo = taosArrayGet(pDataBlock, j);
......
......@@ -54,11 +54,16 @@ static FORCE_INLINE int32_t filterFieldValDescCompare(const void *desc1, const v
return tVariantCompare(val1, val2);
}
static FORCE_INLINE int32_t filterExprCompare(const void *desc1, const void *desc2) {
return -1;
}
filter_desc_compare_func gDescCompare [FLD_TYPE_MAX] = {
NULL,
filterFieldColDescCompare,
filterFieldValDescCompare
filterFieldValDescCompare,
filterExprCompare
};
bool filterRangeCompGi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) {
......@@ -834,7 +839,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type,
info->fields[type].fields[idx].desc = desc;
info->fields[type].fields[idx].data = data ? *data : NULL;
if (type == FLD_TYPE_COLUMN) {
if (type == FLD_TYPE_COLUMN || type == FLD_TYPE_EXPR) {
FILTER_SET_FLAG(info->fields[type].fields[idx].flag, FLD_DATA_NO_FREE);
}
......@@ -874,7 +879,8 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte
int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) {
CHK_LRET(node == NULL, TSDB_CODE_QRY_APP_ERROR, "empty node");
CHK_RET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR);
CHK_RET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE
&&node->nodeType != TSQL_NODE_EXPR, TSDB_CODE_QRY_APP_ERROR);
int32_t type;
void *v;
......@@ -883,6 +889,9 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldI
type = FLD_TYPE_COLUMN;
v = node->pSchema;
node->pSchema = NULL;
} else if (node->nodeType == TSQL_NODE_EXPR) {
type = FLD_TYPE_EXPR;
v = node;
} else {
type = FLD_TYPE_VALUE;
v = node->pVal;
......@@ -934,9 +943,11 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi
}
SFilterField *col = FILTER_UNIT_LEFT_FIELD(info, u);
assert(FILTER_GET_FLAG(col->flag, FLD_TYPE_COLUMN));
info->units[info->unitNum].compare.type = FILTER_GET_COL_FIELD_TYPE(col);
if (FILTER_GET_TYPE(col->flag) == FLD_TYPE_COLUMN) {
info->units[info->unitNum].compare.type = FILTER_GET_COL_FIELD_TYPE(col);
} else {
info->units[info->unitNum].compare.type = (uint8_t)FILTER_GET_EXPR_TYPE(info, u->left);
}
*uidx = info->unitNum;
......@@ -1189,7 +1200,7 @@ static int32_t filterDealJson(SFilterInfo *info, tExprNode* tree, tExprNode** pL
jsonKeyMd5((*pLeft)->_node.pRight->pVal->pz, (*pLeft)->_node.pRight->pVal->nLen, keyMd5);
memcpy(schema->name, keyMd5, TSDB_MAX_JSON_KEY_MD5_LEN);
(*pLeft) = (*pLeft)->_node.pLeft; // -> operation use left as input
}else if(((*pLeft)->pSchema->type == TSDB_DATA_TYPE_JSON) &&
}else if((*pLeft)->nodeType == TSQL_NODE_COL && ((*pLeft)->pSchema->type == TSDB_DATA_TYPE_JSON) &&
(tree->_node.optr == TSDB_RELATION_ISNULL || tree->_node.optr == TSDB_RELATION_NOTNULL)){
SSchema* schema = (*pLeft)->pSchema;
char keyMd5[TSDB_MAX_JSON_KEY_MD5_LEN] = {0};
......@@ -1213,7 +1224,16 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g
if((ret = filterDealJson(info, tree, &pLeft)) != TSDB_CODE_SUCCESS) return ret;
SFilterFieldId left = {0}, right = {0};
filterAddFieldFromNode(info, pLeft, &left);
uint8_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left));
if (pLeft->nodeType != TSQL_NODE_VALUE && pLeft->nodeType != TSQL_NODE_COL) {
tree->_node.pLeft = NULL;
}
uint8_t type;
if (left.type == FLD_TYPE_EXPR) {
type = (uint8_t)FILTER_GET_EXPR_TYPE(info, left);
} else {
type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left));
}
int32_t len = 0;
uint32_t uidx = 0;
......@@ -1577,6 +1597,9 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
char str[512] = {0};
SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit);
if (FILTER_GET_TYPE(left->flag) == FLD_TYPE_EXPR) {
continue;
}
SSchema *sch = left->desc;
if (unit->compare.optr >= TSDB_RELATION_INVALID && unit->compare.optr <= TSDB_RELATION_CONTAINS){
len = sprintf(str, "UNIT[%d] => [%d][%s] %s [", i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str);
......@@ -1752,6 +1775,9 @@ void filterFreeField(SFilterField* field, int32_t type) {
if (!FILTER_GET_FLAG(field->flag, FLD_DESC_NO_FREE)) {
if (type == FLD_TYPE_VALUE) {
tVariantDestroy(field->desc);
} else if (type == FLD_TYPE_EXPR) {
tExprTreeDestroy(field->desc, NULL);
field->desc = NULL;
}
tfree(field->desc);
......@@ -2101,20 +2127,30 @@ _return:
int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) {
bool empty = false;
if (info->fields[FLD_TYPE_COLUMN].num == 0) {
return TSDB_CODE_SUCCESS;
}
uint32_t *colIdx = malloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t));
uint32_t colIdxi = 0;
uint32_t gResIdx = 0;
bool hasExpr = false;
for (uint32_t i = 0; i < info->groupNum; ++i) {
SFilterGroup* g = info->groups + i;
gRes[gResIdx] = calloc(1, sizeof(SFilterGroupCtx));
gRes[gResIdx]->colInfo = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo));
gRes[gResIdx]->hasExpr = false;
colIdxi = 0;
empty = false;
for (uint32_t j = 0; j < g->unitNum; ++j) {
SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j);
if(u->left.type == FLD_TYPE_EXPR) {
gRes[gResIdx]->hasExpr = true;
hasExpr = true;
continue;
}
uint32_t cidx = FILTER_UNIT_COL_IDX(u);
if (gRes[gResIdx]->colInfo[cidx].info == NULL) {
......@@ -2161,6 +2197,9 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
++gResIdx;
}
if (hasExpr) {
FILTER_CLR_FLAG(info->status, FI_STATUS_REWRITE);
}
tfree(colIdx);
*gResNum = gResIdx;
......@@ -2175,6 +2214,10 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t
void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) {
uint32_t idx1 = 0, idx2 = 0, m = 0, n = 0;
bool equal = false;
if (gRes1->hasExpr || gRes2->hasExpr) {
*conflict = true;
return;
}
for (; m < gRes1->colNum; ++m) {
idx1 = gRes1->colIdx[m];
......@@ -2647,7 +2690,12 @@ int32_t filterGenerateComInfo(SFilterInfo *info) {
info->cunits[i].rfunc = filterGetRangeCompFuncFromOptrs(unit->compare.optr, unit->compare.optr2);
info->cunits[i].optr = FILTER_UNIT_OPTR(unit);
info->cunits[i].colData = NULL;
info->cunits[i].colId = FILTER_UNIT_COL_ID(info, unit);
info->cunits[i].expr = NULL;
if (unit->left.type == FLD_TYPE_COLUMN) {
info->cunits[i].colId = FILTER_UNIT_COL_ID(info, unit);
} else if (unit->left.type == FLD_TYPE_EXPR) {
info->cunits[i].expr = FILTER_GET_FIELD_DESC(FILTER_GET_FIELD(info, unit->left));
}
if (unit->right.type == FLD_TYPE_VALUE) {
if(FILTER_UNIT_DATA_TYPE(unit) == TSDB_DATA_TYPE_JSON){ // json value is tVariant
......@@ -2663,8 +2711,12 @@ int32_t filterGenerateComInfo(SFilterInfo *info) {
} else {
info->cunits[i].valData2 = info->cunits[i].valData;
}
info->cunits[i].dataSize = FILTER_UNIT_COL_SIZE(info, unit);
if (unit->left.type == FLD_TYPE_COLUMN) {
info->cunits[i].dataSize = FILTER_UNIT_COL_SIZE(info, unit);
} else {
info->cunits[i].dataSize = FILTER_GET_EXPR_SIZE(info, unit->left);
}
info->cunits[i].dataType = FILTER_UNIT_DATA_TYPE(unit);
}
......@@ -2674,8 +2726,14 @@ int32_t filterGenerateComInfo(SFilterInfo *info) {
int32_t filterUpdateComUnits(SFilterInfo *info) {
for (uint32_t i = 0; i < info->unitNum; ++i) {
SFilterUnit *unit = &info->units[i];
info->cunits[i].colData = FILTER_UNIT_COL_DATA(info, unit, 0);
if (unit->left.type == FLD_TYPE_EXPR) {
SFilterField *t = FILTER_UNIT_LEFT_FIELD(info, unit);
info->cunits[i].colData = NULL;
info->cunits[i].exprData = t->data;
} else {
info->cunits[i].colData = FILTER_UNIT_COL_DATA(info, unit, 0);
info->cunits[i].exprData = NULL;
}
}
return TSDB_CODE_SUCCESS;
......@@ -2924,6 +2982,11 @@ bool filterExecuteBasedOnStatisImpl(void *pinfo, int32_t numOfRows, int8_t** p,
int32_t filterExecuteBasedOnStatis(SFilterInfo *info, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols, bool* all) {
for (uint32_t i = 0; i < info->unitNum; ++i) {
if(info->cunits[i].expr) {
return 1;
}
}
if (statis && numOfRows >= FILTER_RM_UNIT_MIN_ROWS) {
info->blkFlag = 0;
......@@ -2954,6 +3017,20 @@ _return:
return TSDB_CODE_SUCCESS;
}
char *getExprColumnData(void *param, const char* name, int32_t colId) {
void *data = NULL;
getColumnDataFromId(param, colId, &data);
return (char *) data;
}
void* filterExprTraverse (SFilterInfo *info, int32_t numOfRows, int16_t numOfCols) {
tExprOperandInfo output;
output.data = malloc(sizeof(int64_t) * numOfRows);
SSDataBlock* pBlock = (SSDataBlock*) info->cunits[0].exprData;
SColumnDataParam param = {.numOfCols = numOfCols, .pDataBlock = (SArray*)pBlock};
exprTreeNodeTraverse(info->cunits[0].expr, numOfRows, &output, &param, TSDB_ORDER_ASC, getExprColumnData);
return output.data;
}
static FORCE_INLINE bool filterExecuteImplAll(void *info, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols) {
return true;
......@@ -2964,18 +3041,26 @@ static FORCE_INLINE bool filterExecuteImplEmpty(void *info, int32_t numOfRows, i
static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols) {
SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true;
char *exprData = NULL;
uint32_t uidx = info->groups[0].unitIdxs[0];
void *colData = NULL;
if (filterExecuteBasedOnStatis(info, numOfRows, p, statis, numOfCols, &all) == 0) {
return all;
}
if (info->cunits[0].expr) {
exprData = filterExprTraverse(info, numOfRows, numOfCols);
} else {
exprData = info->cunits[uidx].colData;
}
if (*p == NULL) {
*p = calloc(numOfRows, sizeof(int8_t));
}
for (int32_t i = 0; i < numOfRows; ++i) {
uint32_t uidx = info->groups[0].unitIdxs[0];
void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i;
colData = (char *)exprData + info->cunits[uidx].dataSize * i;
if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_JSON){
if (!colData){ // for json->'key' is null
(*p)[i] = 1;
......@@ -2993,23 +3078,35 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
}
}
if (info->cunits[0].expr) {
tfree(exprData);
}
return all;
}
static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols) {
SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true;
char *exprData = NULL;
uint32_t uidx = info->groups[0].unitIdxs[0];
void *colData = NULL;
if (filterExecuteBasedOnStatis(info, numOfRows, p, statis, numOfCols, &all) == 0) {
return all;
}
if (info->cunits[0].expr) {
exprData = filterExprTraverse(info, numOfRows, numOfCols);
} else {
exprData = info->cunits[uidx].colData;
}
if (*p == NULL) {
*p = calloc(numOfRows, sizeof(int8_t));
}
for (int32_t i = 0; i < numOfRows; ++i) {
uint32_t uidx = info->groups[0].unitIdxs[0];
void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i;
colData = (char *)exprData + info->cunits[uidx].dataSize * i;
if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_JSON){
if (!colData) { // for json->'key' is not null
......@@ -3029,6 +3126,10 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows
}
}
if (info->cunits[0].expr) {
tfree(exprData);
}
return all;
}
......@@ -3082,11 +3183,16 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SDataSta
void *valData = info->cunits[0].valData;
void *valData2 = info->cunits[0].valData2;
__compar_fn_t func = gDataCompare[info->cunits[0].func];
char *exprData = NULL;
if (filterExecuteBasedOnStatis(info, numOfRows, p, statis, numOfCols, &all) == 0) {
return all;
}
if (info->cunits[0].expr) {
exprData = colData = filterExprTraverse(info, numOfRows, numOfCols);
}
if (*p == NULL) {
*p = calloc(numOfRows, sizeof(int8_t));
}
......@@ -3106,6 +3212,9 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SDataSta
colData += dataSize;
}
if (info->cunits[0].expr) {
tfree(exprData);
}
return all;
}
......@@ -3113,18 +3222,26 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t** p, SDataSta
bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *statis, int16_t numOfCols) {
SFilterInfo *info = (SFilterInfo *)pinfo;
bool all = true;
char *exprData = NULL;
uint32_t uidx = info->groups[0].unitIdxs[0];
void *colData = NULL;
if (filterExecuteBasedOnStatis(info, numOfRows, p, statis, numOfCols, &all) == 0) {
return all;
}
if (info->cunits[0].expr) {
exprData = filterExprTraverse(info, numOfRows, numOfCols);
} else {
exprData = info->cunits[uidx].colData;
}
if (*p == NULL) {
*p = calloc(numOfRows, sizeof(int8_t));
}
for (int32_t i = 0; i < numOfRows; ++i) {
uint32_t uidx = info->groups[0].unitIdxs[0];
void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i;
colData = (char *)exprData + info->cunits[uidx].dataSize * i;
if (colData == NULL || isNull(colData, info->cunits[uidx].dataType)) {
(*p)[i] = 0;
all = false;
......@@ -3153,6 +3270,10 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SDataStat
}
}
if (info->cunits[0].expr) {
tfree(exprData);
}
return all;
}
......@@ -3168,6 +3289,27 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *
*p = calloc(numOfRows, sizeof(int8_t));
}
SArray* tmpData = NULL;
for (uint32_t g = 0; g < info->groupNum; ++g) {
SFilterGroup *group = &info->groups[g];
for (uint32_t u = 0; u < group->unitNum; ++u) {
uint32_t uidx = group->unitIdxs[u];
SFilterComUnit *cunit = &info->cunits[uidx];
if (cunit->expr) {
if (!tmpData) {
tmpData = taosArrayInit(10, POINTER_BYTES);
}
tExprOperandInfo output;
output.data = malloc(sizeof(int64_t) * numOfRows);
taosArrayPush(tmpData, output.data);
SSDataBlock* pBlock = (SSDataBlock*) cunit->exprData;
SColumnDataParam param = {.numOfCols = numOfCols, .pDataBlock = (SArray*)pBlock};
exprTreeNodeTraverse(cunit->expr, numOfRows, &output, &param, TSDB_ORDER_ASC, getExprColumnData);
cunit->colData = (char *) output.data;
}
}
}
for (int32_t i = 0; i < numOfRows; ++i) {
//FILTER_UNIT_CLR_F(info);
......@@ -3229,6 +3371,9 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t** p, SDataStatis *
}
}
if (tmpData) {
taosArrayDestroy(&tmpData);
}
return all;
}
......@@ -3318,7 +3463,8 @@ _return:
int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from_id fp) {
CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL");
CHK_LRET(info->fields[FLD_TYPE_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds");
CHK_LRET(info->fields[FLD_TYPE_COLUMN].num <= 0 && info->fields[FLD_TYPE_EXPR].num <= 0,
TSDB_CODE_QRY_APP_ERROR, "no column fileds");
if (FILTER_ALL_RES(info) || FILTER_EMPTY_RES(info)) {
return TSDB_CODE_SUCCESS;
......@@ -3331,6 +3477,11 @@ int32_t filterSetColFieldData(SFilterInfo *info, void *param, filer_get_col_from
(*fp)(param, sch->colId, &fi->data);
}
for (uint32_t i = 0; i < info->fields[FLD_TYPE_EXPR].num; ++i) {
SFilterField* fi = &info->fields[FLD_TYPE_EXPR].fields[i];
(*fp)(param, INT32_MAX, &fi->data);
}
filterUpdateComUnits(info);
return TSDB_CODE_SUCCESS;
......
......@@ -345,7 +345,9 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
if ((pLeft != NULL && pRight != NULL) &&
(optrType == TK_PLUS || optrType == TK_MINUS || optrType == TK_STAR || optrType == TK_DIVIDE || optrType == TK_REM ||
optrType == TK_EQ || optrType == TK_NE || optrType == TK_LT || optrType == TK_GT || optrType == TK_LE || optrType == TK_GE ||
optrType == TK_AND || optrType == TK_OR)) {
optrType == TK_AND || optrType == TK_OR || optrType == TK_BITAND || optrType == TK_BITOR || optrType == TK_BITXOR ||
optrType == TK_LSHIFT || optrType == TK_RSHIFT))
{
/*
* if a exprToken is noted as the TK_TIMESTAMP, the time precision is microsecond
* Otherwise, the time precision is adaptive, determined by the time precision from databases.
......@@ -422,6 +424,61 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr->value.i64 = (pLeft->value.i64 || pRight->value.i64) ? 1 : 0;
break;
}
case TK_BITAND: {
if (pLeft->tokenId == TK_BOOL || pRight->tokenId == TK_BOOL ||
pLeft->tokenId == TK_FLOAT || pRight->tokenId == TK_FLOAT ||
pLeft->tokenId == TK_TIMESTAMP || pRight->tokenId == TK_TIMESTAMP)
{
pExpr->value.i64 = TSDB_DATA_BIGINT_NULL;
} else {
pExpr->value.i64 = pLeft->value.i64 & pRight->value.i64;
}
break;
}
case TK_BITOR: {
if (pLeft->tokenId == TK_BOOL || pRight->tokenId == TK_BOOL ||
pLeft->tokenId == TK_FLOAT || pRight->tokenId == TK_FLOAT ||
pLeft->tokenId == TK_TIMESTAMP || pRight->tokenId == TK_TIMESTAMP)
{
pExpr->value.i64 = TSDB_DATA_BIGINT_NULL;
} else {
pExpr->value.i64 = pLeft->value.i64 | pRight->value.i64;
}
break;
}
case TK_BITXOR: {
if (pLeft->tokenId == TK_BOOL || pRight->tokenId == TK_BOOL ||
pLeft->tokenId == TK_FLOAT || pRight->tokenId == TK_FLOAT ||
pLeft->tokenId == TK_TIMESTAMP || pRight->tokenId == TK_TIMESTAMP)
{
pExpr->value.i64 = TSDB_DATA_BIGINT_NULL;
} else {
pExpr->value.i64 = pLeft->value.i64 ^ pRight->value.i64;
}
break;
}
case TK_LSHIFT: {
if (pLeft->tokenId == TK_BOOL || pRight->tokenId == TK_BOOL ||
pLeft->tokenId == TK_FLOAT || pRight->tokenId == TK_FLOAT ||
pLeft->tokenId == TK_TIMESTAMP || pRight->tokenId == TK_TIMESTAMP)
{
pExpr->value.i64 = TSDB_DATA_BIGINT_NULL;
} else {
pExpr->value.i64 = pLeft->value.i64 << pRight->value.i64;
}
break;
}
case TK_RSHIFT: {
if (pLeft->tokenId == TK_BOOL || pRight->tokenId == TK_BOOL ||
pLeft->tokenId == TK_FLOAT || pRight->tokenId == TK_FLOAT ||
pLeft->tokenId == TK_TIMESTAMP || pRight->tokenId == TK_TIMESTAMP)
{
pExpr->value.i64 = TSDB_DATA_BIGINT_NULL;
} else {
pExpr->value.i64 = pLeft->value.i64 >> pRight->value.i64;
}
break;
}
}
tSqlExprDestroy(pLeft);
......@@ -533,6 +590,13 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr->value.i64 = (left || right) ? 1 : 0;
break;
}
case TK_BITAND:
case TK_BITOR:
case TK_BITXOR:
case TK_LSHIFT:
case TK_RSHIFT:
pExpr->value.i64 = TSDB_DATA_DOUBLE_NULL;
break;
}
tSqlExprDestroy(pLeft);
......@@ -566,6 +630,12 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
}
pExpr->pRight = pRight;
if (optrType == TK_BITNOT) {
pExpr->exprToken.z = pLeft->exprToken.z - 1;
pExpr->exprToken.n = pLeft->exprToken.n + 1;
pExpr->exprToken.type = pLeft->exprToken.type;
}
}
return pExpr;
......@@ -1488,4 +1558,4 @@ SDelData* tGetDelData(SStrToken* pTableName, SStrToken* existsCheck, tSqlExpr* p
pDelData->pWhere = pWhere;
return pDelData;
}
\ No newline at end of file
}
此差异已折叠。
......@@ -156,7 +156,7 @@ typedef struct STsdbQueryHandle {
SArray *prev; // previous row which is before than time window
SArray *next; // next row which is after the query time window
SIOCostSummary cost;
// callback
readover_callback readover_cb;
void* param;
......@@ -173,6 +173,11 @@ typedef struct SRange {
int32_t to;
} SRange;
typedef struct STagBlockInfo {
SSkipListNode *pSkipListNode;
SArray *pBlock;
} STagBlockInfo;
static STimeWindow updateLastrowForEachGroup(STableGroupInfo *groupList);
static int32_t checkForCachedLastRow(STsdbQueryHandle* pQueryHandle, STableGroupInfo *groupList);
static int32_t checkForCachedLast(STsdbQueryHandle* pQueryHandle);
......@@ -4333,7 +4338,15 @@ static FORCE_INLINE int32_t tsdbGetTagDataFromId(void *param, int32_t id, void *
return TSDB_CODE_SUCCESS;
}
static FORCE_INLINE int32_t tsdbGetTagData(void *param, int32_t id, void **data) {
STagBlockInfo* pInfo = (STagBlockInfo*) param;
if (id == INT32_MAX) {
*data = pInfo->pBlock;
} else {
return tsdbGetTagDataFromId(pInfo->pSkipListNode, id, data);
}
return TSDB_CODE_SUCCESS;
}
static void queryIndexedColumn(SSkipList* pSkipList, void* filterInfo, SArray* res) {
SSkipListIterator* iter = NULL;
......@@ -4388,26 +4401,77 @@ static void queryIndexedColumn(SSkipList* pSkipList, void* filterInfo, SArray* r
tsdbDebug("filter index column end");
}
static void getAllExprColId(tExprNode* pExpr, SArray* array) {
if (!pExpr) {
return;
}
if (pExpr->nodeType == TSQL_NODE_FUNC) {
for (int32_t i = 0; i < pExpr->_func.numChildren; ++i) {
getAllExprColId(pExpr->_func.pChildren[i], array);
}
} else if (pExpr->nodeType == TSQL_NODE_EXPR) {
getAllExprColId(pExpr->_node.pLeft, array);
getAllExprColId(pExpr->_node.pRight, array);
} else if (pExpr->nodeType == TSQL_NODE_COL) {
taosArrayPush(array, &pExpr->pSchema->colId);
}
}
static void getAllFilterExprColId(SFilterFields* pSf, SArray* array) {
for (uint32_t i = 0; i < pSf->num; ++i) {
SFilterField* fi = &(pSf->fields[i]);
if (FILTER_GET_TYPE(fi->flag) == FLD_TYPE_EXPR) {
getAllExprColId(fi->desc, array);
}
}
taosArraySort(array, getComparFunc(TSDB_DATA_TYPE_SMALLINT, 0));
taosArrayRemoveDuplicate(array, getComparFunc(TSDB_DATA_TYPE_SMALLINT, 0), NULL);
}
static void queryIndexlessColumn(SSkipList* pSkipList, void* filterInfo, SArray* res) {
SSkipListIterator* iter = tSkipListCreateIter(pSkipList);
int8_t *addToResult = NULL;
SFilterInfo *sfInfo = (SFilterInfo *)filterInfo;
SArray *array = NULL;
SArray *pDataBlock = NULL;
if (sfInfo->fields[FLD_TYPE_EXPR].num > 0) {
array = taosArrayInit(10, sizeof(int16_t));
getAllFilterExprColId(&(sfInfo->fields[FLD_TYPE_EXPR]), array);
}
while (tSkipListIterNext(iter)) {
SSkipListNode *pNode = tSkipListIterGet(iter);
filterSetColFieldData(filterInfo, pNode, tsdbGetTagDataFromId);
char *pData = SL_GET_NODE_DATA(pNode);
if (sfInfo->fields[FLD_TYPE_EXPR].num > 0) {
pDataBlock = taosArrayInit(10, sizeof(SColumnInfoData));
size_t num = taosArrayGetSize(array);
for(int32_t i = 0; i < num; ++i) {
int16_t *pColId = taosArrayGet(array, i);
void *data = NULL;
tsdbGetTagDataFromId(pNode, *pColId, &data);
SColumnInfoData colData = {{0}};
colData.pData = data;
colData.info.colId = *pColId;
taosArrayPush(pDataBlock, &colData);
}
}
STagBlockInfo stInfo = {.pSkipListNode = pNode, .pBlock = pDataBlock};
filterSetColFieldData(filterInfo, &stInfo, tsdbGetTagData);
bool all = filterExecute(filterInfo, 1, &addToResult, NULL, 0);
char *pData = SL_GET_NODE_DATA(pNode);
int16_t numOfCols = array ? (int16_t)taosArrayGetSize(array) : 0;
bool all = filterExecute(filterInfo, 1, &addToResult, NULL, numOfCols);
if (all || (addToResult && *addToResult)) {
STableKeyInfo info = {.pTable = (void*)pData, .lastKey = TSKEY_INITIAL_VAL};
taosArrayPush(res, &info);
}
taosArrayDestroy(&pDataBlock);
}
taosArrayDestroy(&array);
tfree(addToResult);
tSkipListDestroyIter(iter);
......@@ -4696,4 +4760,4 @@ void tsdbAddScanCallback(TsdbQueryHandleT* queryHandle, readover_callback callba
int32_t tsdbTableTid(void* pTable) {
STable *p = (STable *)pTable;
return p->tableId.tid;
}
\ No newline at end of file
}
......@@ -58,6 +58,7 @@ static SKeyword keywordTable[] = {
{"IN", TK_IN},
{"BITAND", TK_BITAND},
{"BITOR", TK_BITOR},
{"BITXOR", TK_BITXOR},
{"LSHIFT", TK_LSHIFT},
{"RSHIFT", TK_RSHIFT},
{"PLUS", TK_PLUS},
......@@ -411,6 +412,10 @@ uint32_t tGetToken(char* z, uint32_t* tokenId) {
*tokenId = TK_BITNOT;
return 1;
}
case '^': {
*tokenId = TK_BITXOR;
return 1;
}
case '?': {
*tokenId = TK_QUESTION;
return 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册