提交 18da95ad 编写于 作者: S slguan

Merge branch 'develop' of https://github.com/taosdata/TDengine into develop

......@@ -132,7 +132,6 @@ void tscFieldInfoSetExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlExpr* pExpr)
void tscFieldInfoSetBinExpr(SFieldInfo* pFieldInfo, int32_t index, SSqlFunctionExpr* pExpr);
void tscFieldInfoCalOffset(SQueryInfo* pQueryInfo);
void tscFieldInfoUpdateOffsetForInterResult(SQueryInfo* pQueryInfo);
void tscFieldInfoCopy(SFieldInfo* src, SFieldInfo* dst, const int32_t* indexList, int32_t size);
void tscFieldInfoCopyAll(SFieldInfo* dst, SFieldInfo* src);
......
......@@ -369,7 +369,7 @@ void tscQueueAsyncRes(SSqlObj *pSql) {
tscTrace("%p SqlObj is freed, not add into queue async res", pSql);
return;
} else {
tscError("%p add into queued async res, code:%d", pSql, pSql->res.code);
tscError("%p add into queued async res, code:%s", pSql, tstrerror(pSql->res.code));
}
SSchedMsg schedMsg;
......@@ -410,7 +410,6 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
pSql->fp = NULL;
if (code != 0) {
code = abs(code);
pRes->code = code;
tscTrace("%p failed to renew tableMeta", pSql);
tsem_post(&pSql->rspSem);
......@@ -432,8 +431,8 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) {
return;
}
if (code != 0) {
pRes->code = (uint8_t)abs(code);
if (code != TSDB_CODE_SUCCESS) {
pRes->code = code;
tscQueueAsyncRes(pSql);
return;
}
......
......@@ -1213,11 +1213,11 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
int32_t ret = tSQLBinaryExprCreateFromSqlExpr(&pNode, pItem->pNode, &pBinExprInfo->numOfCols, &pColIndex, &pQueryInfo->exprsInfo);
if (ret != TSDB_CODE_SUCCESS) {
tSQLBinaryExprDestroy(&pNode->pExpr, NULL);
tSQLBinaryExprDestroy(&pNode, NULL);
return invalidSqlErrMsg(pQueryInfo->msg, "invalid expression in select clause");
}
pBinExprInfo->pBinExpr = pNode->pExpr;
pBinExprInfo->pBinExpr = pNode;
pBinExprInfo->pReqColumns = pColIndex;
for(int32_t k = 0; k < pBinExprInfo->numOfCols; ++k) {
......@@ -5850,28 +5850,21 @@ static int32_t tSQLBinaryExprCreateFromSqlExpr(tSQLSyntaxNode **pExpr, tSQLExpr*
return TSDB_CODE_SUCCESS;
}
(*pExpr)->colId = -1;
*pColIndex = realloc(*pColIndex, (++(*num)) * sizeof(SColIndexEx));
memset(&(*pColIndex)[(*num) - 1], 0, sizeof(SColIndexEx));
strncpy((*pColIndex)[(*num) - 1].name, pAst->operand.z, pAst->operand.n);
} else {
tSQLBinaryExpr *pBinExpr = (tSQLBinaryExpr *)calloc(1, sizeof(tSQLBinaryExpr));
pBinExpr->filterOnPrimaryKey = false;
pBinExpr->pLeft = pLeft;
pBinExpr->pRight = pRight;
*pExpr = (tSQLSyntaxNode *)calloc(1, sizeof(tSQLSyntaxNode));
(*pExpr)->_node.hasPK = false;
(*pExpr)->_node.pLeft = pLeft;
(*pExpr)->_node.pRight = pRight;
SSQLToken t = {.type = pAst->nSQLOptr};
pBinExpr->nSQLBinaryOptr = getBinaryExprOptr(&t);
assert(pBinExpr->nSQLBinaryOptr != 0);
(*pExpr)->_node.optr = getBinaryExprOptr(&t);
(*pExpr) = malloc(sizeof(tSQLSyntaxNode));
(*pExpr)->nodeType = TSQL_NODE_EXPR;
(*pExpr)->pExpr = pBinExpr;
(*pExpr)->colId = -1;
assert((*pExpr)->_node.optr != 0);
if (pBinExpr->nSQLBinaryOptr == TSDB_BINARY_OP_DIVIDE) {
if ((*pExpr)->_node.optr == TSDB_BINARY_OP_DIVIDE) {
if (pRight->nodeType == TSQL_NODE_VALUE) {
if (pRight->pVal->nType == TSDB_DATA_TYPE_INT && pRight->pVal->i64Key == 0) {
return TSDB_CODE_INVALID_SQL;
......
......@@ -325,7 +325,7 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) {
if (rpcMsg->code != TSDB_CODE_ACTION_IN_PROGRESS) {
void *taosres = tscKeepConn[pCmd->command] ? pSql : NULL;
rpcMsg->code = pRes->code ? -pRes->code : pRes->numOfRows;
rpcMsg->code = pRes->code ? pRes->code : pRes->numOfRows;
tscTrace("%p Async SQL result:%s res:%p", pSql, tstrerror(pRes->code), taosres);
......
......@@ -867,7 +867,7 @@ int taos_errno(TAOS *taos) {
return code;
}
static bool validErrorCode(int32_t code) { return code >= TSDB_CODE_SUCCESS && code < TSDB_CODE_MAX_ERROR_CODE; }
//static bool validErrorCode(int32_t code) { return code >= TSDB_CODE_SUCCESS && code < TSDB_CODE_MAX_ERROR_CODE; }
/*
* In case of invalid sql error, additional information is attached to explain
......@@ -890,23 +890,15 @@ static bool hasAdditionalErrorInfo(int32_t code, SSqlCmd *pCmd) {
char *taos_errstr(TAOS *taos) {
STscObj *pObj = (STscObj *)taos;
uint8_t code;
if (pObj == NULL || pObj->signature != pObj)
return (char*)tstrerror(globalCode);
SSqlObj *pSql = pObj->pSql;
if (validErrorCode(pSql->res.code)) {
code = pSql->res.code;
} else {
code = TSDB_CODE_OTHERS; // unknown error
}
if (hasAdditionalErrorInfo(code, &pSql->cmd)) {
if (hasAdditionalErrorInfo(pSql->res.code, &pSql->cmd)) {
return pSql->cmd.payload;
} else {
return (char*)tstrerror(code);
return (char*)tstrerror(pSql->res.code);
}
}
......
......@@ -80,7 +80,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TABLE_ALREADY_EXIST, 0, 34, "table already ex
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_USER, 0, 35, "invalid user")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_ACCT, 0, 36, "invalid account")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_PASS, 0, 37, "invalid password")
TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 38, "do not selected")
TAOS_DEFINE_ERROR(TSDB_CODE_DB_NOT_SELECTED, 0, 38, "db not selected")
TAOS_DEFINE_ERROR(TSDB_CODE_MEMORY_CORRUPTED, 0, 39, "memory corrupted")
TAOS_DEFINE_ERROR(TSDB_CODE_USER_ALREADY_EXIST, 0, 40, "user already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_NO_RIGHTS, 0, 41, "no rights")
......@@ -118,7 +118,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MONITOR_DB_FORBIDDEN, 0, 72, "monitor db forbi
TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISK_PERMISSIONS, 0, 73, "no disk permissions")
TAOS_DEFINE_ERROR(TSDB_CODE_VG_INIT_FAILED, 0, 74, "vg init failed")
TAOS_DEFINE_ERROR(TSDB_CODE_DATA_ALREADY_IMPORTED, 0, 75, "data already imported")
TAOS_DEFINE_ERROR(TSDB_CODE_OPS_NOT_SUPPORT, 0, 76, "ops not support")
TAOS_DEFINE_ERROR(TSDB_CODE_OPS_NOT_SUPPORT, 0, 76, "operations not support")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_QUERY_ID, 0, 77, "invalid query id")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_STREAM_ID, 0, 78, "invalid stream id")
TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_CONNECTION, 0, 79, "invalid connection")
......
......@@ -50,6 +50,7 @@ static void mgmtProcessShowMsg(SQueuedMsg *queuedMsg);
static void mgmtProcessRetrieveMsg(SQueuedMsg *queuedMsg);
static void mgmtProcessHeartBeatMsg(SQueuedMsg *queuedMsg);
static void mgmtProcessConnectMsg(SQueuedMsg *queuedMsg);
static void mgmtProcessUseMsg(SQueuedMsg *queuedMsg);
static void *tsMgmtShellRpc = NULL;
static void *tsMgmtTranQhandle = NULL;
......@@ -62,6 +63,7 @@ int32_t mgmtInitShell() {
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_RETRIEVE, mgmtProcessRetrieveMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_HEARTBEAT, mgmtProcessHeartBeatMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mgmtProcessConnectMsg);
mgmtAddShellMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mgmtProcessUseMsg);
tsMgmtTranQhandle = taosInitScheduler(tsMaxShellConns, 1, "mnodeT");
......@@ -435,6 +437,23 @@ connect_over:
rpcSendResponse(&rpcRsp);
}
static void mgmtProcessUseMsg(SQueuedMsg *pMsg) {
SRpcMsg rpcRsp = {.handle = pMsg->thandle, .pCont = NULL, .contLen = 0, .code = 0, .msgType = 0};
SCMUseDbMsg *pUseDbMsg = pMsg->pCont;
// todo check for priority of current user
SDbObj* pDbObj = mgmtGetDb(pUseDbMsg->db);
int32_t code = TSDB_CODE_SUCCESS;
if (pDbObj == NULL) {
code = TSDB_CODE_INVALID_DB;
}
rpcRsp.code = code;
rpcSendResponse(&rpcRsp);
}
/**
* check if we need to add mgmtProcessTableMetaMsg into tranQueue, which will be executed one-by-one.
*/
......
......@@ -27,7 +27,7 @@ extern "C" {
#include "taosdef.h"
#include "tvariant.h"
struct tSQLBinaryExpr;
struct tSQLSyntaxNode;
struct SSchema;
struct tSkipList;
struct tSkipListNode;
......@@ -62,44 +62,38 @@ typedef struct SBinaryFilterSupp {
typedef struct tSQLSyntaxNode {
uint8_t nodeType;
int16_t colId; // for schema, the id of column
union {
struct tSQLBinaryExpr *pExpr;
struct SSchema * pSchema;
struct {
uint8_t optr; // filter operator
uint8_t hasPK; // 0: do not contain primary filter, 1: contain
void * info; // support filter operation on this expression only available for leaf node
struct tSQLSyntaxNode *pLeft; // left child pointer
struct tSQLSyntaxNode *pRight; // right child pointer
} _node;
struct SSchema *pSchema;
tVariant * pVal;
};
} tSQLSyntaxNode;
typedef struct tSQLBinaryExpr {
uint8_t nSQLBinaryOptr; // filter operator
uint8_t filterOnPrimaryKey; // 0: do not contain primary filter, 1: contain
/*
* provide the information to support filter operation on this expression
* only available for leaf node
*/
void * info;
tSQLSyntaxNode *pLeft; // left child pointer
tSQLSyntaxNode *pRight; // right child pointer
} tSQLBinaryExpr;
typedef struct tQueryResultset {
void ** pRes;
int64_t num;
} tQueryResultset;
void tSQLBinaryExprFromString(tSQLBinaryExpr **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len);
void tSQLBinaryExprFromString(tSQLSyntaxNode **pExpr, SSchema *pSchema, int32_t numOfCols, char *src, int32_t len);
void tSQLBinaryExprToString(tSQLBinaryExpr *pExpr, char *dst, int32_t *len);
void tSQLBinaryExprToString(tSQLSyntaxNode *pExpr, char *dst, int32_t *len);
void tSQLBinaryExprDestroy(tSQLBinaryExpr **pExprs, void (*fp)(void*));
void tSQLBinaryExprDestroy(tSQLSyntaxNode **pExprs, void (*fp)(void*));
void tSQLBinaryExprTraverse(tSQLBinaryExpr *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param);
void tSQLBinaryExprTraverse(tSQLSyntaxNode *pExpr, SSkipList *pSkipList, SArray *result, SBinaryFilterSupp *param);
void tSQLBinaryExprCalcTraverse(tSQLBinaryExpr *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
void tSQLBinaryExprCalcTraverse(tSQLSyntaxNode *pExprs, int32_t numOfRows, char *pOutput, void *param, int32_t order,
char *(*cb)(void *, char *, int32_t));
void tSQLBinaryExprTrv(tSQLBinaryExpr *pExprs, int32_t *val, int16_t *ids);
void tSQLBinaryExprTrv(tSQLSyntaxNode *pExprs, int32_t *val, int16_t *ids);
void tQueryResultClean(tQueryResultset *pRes);
uint8_t getBinaryExprOptr(SSQLToken *pToken);
......
......@@ -20,6 +20,7 @@
extern "C" {
#endif
#include <tstrbuild.h>
#include "taos.h"
#include "taosmsg.h"
#include "tstoken.h"
......@@ -187,38 +188,19 @@ typedef struct SSqlInfo {
} SSqlInfo;
typedef struct tSQLExpr {
/*
* for single operand:
* TK_ALL
* TK_ID
* TK_SUM
* TK_AVG
* TK_MIN
* TK_MAX
* TK_FIRST
* TK_LAST
* TK_BOTTOM
* TK_TOP
* TK_STDDEV
* TK_PERCENTILE
*
* for binary operand:
* TK_LESS
* TK_LARGE
* TK_EQUAL etc...
*/
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
// TK_FUNCTION: sql function, TK_LE: less than(binary expr)
uint32_t nSQLOptr;
// the full sql string of function(col, param), which is actually the raw
// field name, since the function name is kept in nSQLOptr already
SSQLToken operand;
struct tSQLExprList *pParam; // function parameters
SSQLToken colInfo; // field id
tVariant val; // value only for string, float, int
struct tSQLExpr *pLeft; // left child
struct tSQLExpr *pRight; // right child
struct tSQLExprList *pParam; // function parameters
} tSQLExpr;
// used in select clause. select <tSQLExprList> from xxx
......@@ -326,9 +308,11 @@ void tSQLSetColumnInfo(TAOS_FIELD *pField, SSQLToken *pName, TAOS_FIELD *pType);
void tSQLSetColumnType(TAOS_FIELD *pField, SSQLToken *pToken);
void *ParseAlloc(void *(*mallocProc)(size_t));
// convert the sql filter expression into binary data
int32_t tSQLExprToBinary(tSQLExpr* pExpr, SStringBuilder* sb);
enum {
TSQL_NODE_TYPE_EXPR = 0x1,
TSQL_NODE_TYPE_ID = 0x2,
......
此差异已折叠。
......@@ -13,17 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qsqltype.h>
#include "os.h"
#include "qsqlparser.h"
#include "taosdef.h"
#include "taosmsg.h"
#include "tglobalcfg.h"
#include "tlog.h"
#include "tstoken.h"
#include "ttime.h"
#include "ttokendef.h"
#include "taosdef.h"
#include "tutil.h"
#include "qsqltype.h"
#include "tstrbuild.h"
int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) {
void *pParser = ParseAlloc(malloc);
......@@ -900,3 +901,173 @@ void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) {
memset(&pDBInfo->precision, 0, sizeof(SSQLToken));
}
static bool isExprLeafNode(tSQLExpr* pExpr) {
return (pExpr->pRight == NULL && pExpr->pLeft == NULL) &&
(pExpr->nSQLOptr == TK_ID || (pExpr->nSQLOptr >= TK_BOOL && pExpr->nSQLOptr <= TK_NCHAR) ||
pExpr->nSQLOptr == TK_SET);
}
static bool isExprParentOfLeafNode(tSQLExpr* pExpr) {
return (pExpr->pLeft != NULL && pExpr->pRight != NULL) &&
(isExprLeafNode(pExpr->pLeft) && isExprLeafNode(pExpr->pRight));
}
static int32_t tSQLExprNodeToString(tSQLExpr* pExpr, SStringBuilder* pBuilder) {
if (pExpr->nSQLOptr == TK_ID) { // column name
// strncpy(*str, pExpr->colInfo.z, pExpr->colInfo.n);
// *str += pExpr->colInfo.n;
} else if (pExpr->nSQLOptr >= TK_BOOL && pExpr->nSQLOptr <= TK_STRING) { // value
// *str += tVariantToString(&pExpr->val, *str);
// taosStringBuilderAppendStringLen()
} else if (pExpr->nSQLOptr >= TK_COUNT && pExpr->nSQLOptr <= TK_AVG_IRATE) {
taosStringBuilderAppendStringLen(pBuilder, pExpr->operand.z, pExpr->operand.n);
} else { // not supported operation
assert(false);
}
return TSDB_CODE_SUCCESS;
}
static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
const char* le = "<=";
const char* ge = ">=";
const char* ne = "<>";
const char* likeOptr = "LIKE";
switch (pExpr->nSQLOptr) {
case TK_LE: {
*(int16_t*)(*exprString) = *(int16_t*)le;
*exprString += 1;
break;
}
case TK_GE: {
*(int16_t*)(*exprString) = *(int16_t*)ge;
*exprString += 1;
break;
}
case TK_NE: {
*(int16_t*)(*exprString) = *(int16_t*)ne;
*exprString += 1;
break;
}
case TK_LT:
*(*exprString) = '<';
break;
case TK_GT:
*(*exprString) = '>';
break;
case TK_EQ:
*(*exprString) = '=';
break;
case TK_PLUS:
*(*exprString) = '+';
break;
case TK_MINUS:
*(*exprString) = '-';
break;
case TK_STAR:
*(*exprString) = '*';
break;
case TK_DIVIDE:
*(*exprString) = '/';
break;
case TK_REM:
*(*exprString) = '%';
break;
case TK_LIKE: {
int32_t len = sprintf(*exprString, " %s ", likeOptr);
*exprString += (len - 1);
break;
}
default:
return TSDB_CODE_INVALID_SQL;
}
*exprString += 1;
return TSDB_CODE_SUCCESS;
}
static int32_t tSQLExprLeafToBinary(tSQLExpr* pExpr, SStringBuilder* pBuilder) {
if (!isExprParentOfLeafNode(pExpr)) {
return TSDB_CODE_INVALID_SQL;
}
tSQLExpr* pLeft = pExpr->pLeft;
tSQLExpr* pRight = pExpr->pRight;
// if (addParentheses) {
// *(*output) = '(';
// *output += 1;
// }
tSQLExprNodeToString(pLeft, pBuilder);
tSQLExprNodeToString(pRight, pBuilder);
if (optrToString(pExpr, pBuilder) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL;
}
// if (addParentheses) {
// *(*output) = ')';
// *output += 1;
// }
return TSDB_CODE_SUCCESS;
}
static void relToString(tSQLExpr* pExpr, SStringBuilder* pBuilder) {
assert(pExpr->nSQLOptr == TK_AND || pExpr->nSQLOptr == TK_OR);
const char* or = "OR";
const char*and = "AND";
// if (pQueryInfo->tagCond.relType == TSQL_STABLE_QTYPE_COND) {
// if (pExpr->nSQLOptr == TK_AND) {
// strcpy(*str, and);
// *str += strlen(and);
// } else {
// strcpy(*str, or);
// *str += strlen(or);
// }
}
static int32_t doSQLExprToBinary(tSQLExpr* pExpr, SStringBuilder* pBuilder) {
if (pExpr == NULL) {
return TSDB_CODE_SUCCESS;
}
if (!isExprParentOfLeafNode(pExpr)) {
// *(*str) = '(';
// *str += 1;
int32_t ret = doSQLExprToBinary(pExpr->pLeft, pBuilder);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
}
ret = doSQLExprToBinary(pExpr->pRight, pBuilder);
if (ret != TSDB_CODE_SUCCESS) {
return ret;
}
relToString(pExpr, pBuilder);
// *(*str) = ')';
// *str += 1;
return ret;
}
return tSQLExprLeafToBinary(pExpr, pBuilder);
}
// post order seralize to binary data
int32_t tSQLExprToBinary(tSQLExpr* pExpr, SStringBuilder* pBuilder) {
assert(pExpr != NULL && pBuilder != NULL);
}
\ No newline at end of file
......@@ -2603,8 +2603,8 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) {
static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
SQuery *pQuery = pRuntimeEnv->pQuery;
int64_t cnt = 0;
dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", lastkey:%" PRId64 ", order:%d",
GET_QINFO_ADDR(pRuntimeEnv), pQuery->window.skey, pQuery->window.ekey, pQuery->lastKey, pQuery->order.order);
......@@ -3595,8 +3595,8 @@ void scanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
pQuery->window.ekey = ekey;
STimeWindow win = {.skey = pQuery->window.skey, .ekey = pQuery->window.ekey};
tsdbResetQuery(pRuntimeEnv->pQueryHandle, &win, current, pQuery->order.order);
tsdbNextDataBlock(pRuntimeEnv->pQueryHandle);
// tsdbResetQuery(pRuntimeEnv->pQueryHandle, &win, current, pQuery->order.order);
// tsdbNextDataBlock(pRuntimeEnv->pQueryHandle);
}
void doFinalizeResult(SQueryRuntimeEnv *pRuntimeEnv) {
......@@ -5461,7 +5461,7 @@ static int32_t buildAirthmeticExprFromMsg(SSqlFunctionExpr *pExpr, SQueryTableMs
SSqlBinaryExprInfo *pBinaryExprInfo = &pExpr->binExprInfo;
SColumnInfo * pColMsg = pQueryMsg->colList;
#if 0
tSQLBinaryExpr* pBinExpr = NULL;
tSQLSyntaxNode* pBinExpr = NULL;
SSchema* pSchema = toSchema(pQueryMsg, pColMsg, pQueryMsg->numOfCols);
dTrace("qmsg:%p create binary expr from string:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz);
......
......@@ -21,7 +21,6 @@
#include "ttime.h"
#include "qinterpolation.h"
//#include "tscJoinProcess.h"
#include "ttime.h"
#include "queryExecutor.h"
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册