commit
574f9d4c74
|
@ -34,8 +34,8 @@ extern "C" {
|
|||
#include "tglobalcfg.h"
|
||||
#include "tlog.h"
|
||||
#include "tscCache.h"
|
||||
#include "tsdb.h"
|
||||
#include "tscSQLParser.h"
|
||||
#include "tsdb.h"
|
||||
#include "tsqlfunction.h"
|
||||
#include "tutil.h"
|
||||
|
||||
|
@ -219,22 +219,22 @@ typedef struct STagCond {
|
|||
} STagCond;
|
||||
|
||||
typedef struct SParamInfo {
|
||||
int32_t idx;
|
||||
char type;
|
||||
uint8_t timePrec;
|
||||
short bytes;
|
||||
int32_t idx;
|
||||
char type;
|
||||
uint8_t timePrec;
|
||||
short bytes;
|
||||
uint32_t offset;
|
||||
} SParamInfo;
|
||||
|
||||
typedef struct STableDataBlocks {
|
||||
char meterId[TSDB_METER_ID_LEN];
|
||||
int8_t tsSource;
|
||||
bool ordered;
|
||||
bool ordered;
|
||||
|
||||
int64_t vgid;
|
||||
int64_t prevTS;
|
||||
|
||||
int32_t numOfMeters;
|
||||
int32_t numOfMeters;
|
||||
|
||||
int32_t rowSize;
|
||||
uint32_t nAllocSize;
|
||||
|
@ -245,9 +245,9 @@ typedef struct STableDataBlocks {
|
|||
};
|
||||
|
||||
// for parameter ('?') binding
|
||||
uint32_t numOfAllocedParams;
|
||||
uint32_t numOfParams;
|
||||
SParamInfo* params;
|
||||
uint32_t numOfAllocedParams;
|
||||
uint32_t numOfParams;
|
||||
SParamInfo *params;
|
||||
} STableDataBlocks;
|
||||
|
||||
typedef struct SDataBlockList {
|
||||
|
@ -262,18 +262,17 @@ typedef struct SDataBlockList {
|
|||
typedef struct {
|
||||
SOrderVal order;
|
||||
int command;
|
||||
|
||||
// TODO refactor
|
||||
int count;
|
||||
int16_t isInsertFromFile; // load data from file or not
|
||||
int count;// TODO refactor
|
||||
|
||||
union {
|
||||
bool existsCheck;
|
||||
int8_t showType;
|
||||
bool existsCheck; // check if the table exists
|
||||
int8_t showType; // show command type
|
||||
int8_t isInsertFromFile; // load data from file or not
|
||||
};
|
||||
|
||||
bool import; // import/insert type
|
||||
char msgType;
|
||||
uint16_t type;
|
||||
uint16_t type; // query type
|
||||
char intervalTimeUnit;
|
||||
int64_t etime, stime;
|
||||
int64_t nAggTimeInterval; // aggregation time interval
|
||||
|
@ -286,20 +285,20 @@ typedef struct {
|
|||
*
|
||||
* In such cases, allocate the memory dynamically, and need to free the memory
|
||||
*/
|
||||
uint32_t allocSize;
|
||||
char * payload;
|
||||
int payloadLen;
|
||||
short numOfCols;
|
||||
uint32_t allocSize;
|
||||
char * payload;
|
||||
int payloadLen;
|
||||
short numOfCols;
|
||||
SColumnBaseInfo colList;
|
||||
SFieldInfo fieldsInfo;
|
||||
SSqlExprInfo exprsInfo;
|
||||
SLimitVal limit;
|
||||
SLimitVal slimit;
|
||||
int64_t globalLimit;
|
||||
STagCond tagCond;
|
||||
int16_t vnodeIdx; // vnode index in pMetricMeta for metric query
|
||||
int16_t interpoType; // interpolate type
|
||||
int16_t numOfTables;
|
||||
SFieldInfo fieldsInfo;
|
||||
SSqlExprInfo exprsInfo;
|
||||
SLimitVal limit;
|
||||
SLimitVal slimit;
|
||||
int64_t globalLimit;
|
||||
STagCond tagCond;
|
||||
int16_t vnodeIdx; // vnode index in pMetricMeta for metric query
|
||||
int16_t interpoType; // interpolate type
|
||||
int16_t numOfTables;
|
||||
|
||||
// submit data blocks branched according to vnode
|
||||
SDataBlockList * pDataBlocks;
|
||||
|
@ -430,11 +429,11 @@ int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion);
|
|||
|
||||
void tscInitMsgs();
|
||||
void *tscProcessMsgFromServer(char *msg, void *ahandle, void *thandle);
|
||||
int tscProcessSql(SSqlObj *pSql);
|
||||
int tscProcessSql(SSqlObj *pSql);
|
||||
|
||||
void tscAsyncInsertMultiVnodesProxy(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
||||
int tscRenewMeterMeta(SSqlObj *pSql, char *meterId);
|
||||
int tscRenewMeterMeta(SSqlObj *pSql, char *meterId);
|
||||
void tscQueueAsyncRes(SSqlObj *pSql);
|
||||
|
||||
void tscQueueAsyncError(void(*fp), void *param);
|
||||
|
@ -448,18 +447,12 @@ int taos_retrieve(TAOS_RES *res);
|
|||
* before send query message to vnode
|
||||
*/
|
||||
int32_t tscTansformSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
||||
void tscRestoreSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
||||
|
||||
/**
|
||||
* release both metric/meter meta information
|
||||
* @param pCmd SSqlCmd object that contains the metric/meter meta info
|
||||
*/
|
||||
void tscClearSqlMetaInfo(SSqlCmd *pCmd);
|
||||
void tscRestoreSQLFunctionForMetricQuery(SSqlCmd *pCmd);
|
||||
|
||||
void tscClearSqlMetaInfoForce(SSqlCmd *pCmd);
|
||||
|
||||
int32_t tscCreateResPointerInfo(SSqlCmd *pCmd, SSqlRes *pRes);
|
||||
void tscDestroyResPointerInfo(SSqlRes *pRes);
|
||||
void tscDestroyResPointerInfo(SSqlRes *pRes);
|
||||
|
||||
void tscFreeSqlCmdData(SSqlCmd *pCmd);
|
||||
|
||||
|
@ -479,12 +472,12 @@ void tscFreeSqlObj(SSqlObj *pObj);
|
|||
|
||||
void tscCloseTscObj(STscObj *pObj);
|
||||
|
||||
void tscProcessMultiVnodesInsert(SSqlObj *pSql);
|
||||
void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql);
|
||||
void tscKillMetricQuery(SSqlObj *pSql);
|
||||
void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen);
|
||||
int32_t tscBuildResultsForEmptyRetrieval(SSqlObj *pSql);
|
||||
bool tscIsUpdateQuery(STscObj *pObj);
|
||||
void tscProcessMultiVnodesInsert(SSqlObj *pSql);
|
||||
void tscProcessMultiVnodesInsertForFile(SSqlObj *pSql);
|
||||
void tscKillMetricQuery(SSqlObj *pSql);
|
||||
void tscInitResObjForLocalQuery(SSqlObj *pObj, int32_t numOfRes, int32_t rowLen);
|
||||
bool tscIsUpdateQuery(STscObj *pObj);
|
||||
int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *sql);
|
||||
|
||||
// transfer SSqlInfo to SqlCmd struct
|
||||
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
|
||||
|
|
|
@ -40,6 +40,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
|
|||
*/
|
||||
static void tscProcessAsyncFetchRowsProxy(void *param, TAOS_RES *tres, int numOfRows);
|
||||
|
||||
// TODO return the correct error code to client in tscQueueAsyncError
|
||||
void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *, int), void *param) {
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
if (pObj == NULL || pObj->signature != pObj) {
|
||||
|
@ -58,14 +59,13 @@ void taos_query_a(TAOS *taos, const char *sqlstr, void (*fp)(void *, TAOS_RES *,
|
|||
|
||||
taosNotePrintTsc(sqlstr);
|
||||
|
||||
SSqlObj *pSql = (SSqlObj *)malloc(sizeof(SSqlObj));
|
||||
SSqlObj *pSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||
if (pSql == NULL) {
|
||||
tscError("failed to malloc sqlObj");
|
||||
tscQueueAsyncError(fp, param);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(pSql, 0, sizeof(SSqlObj));
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
|
||||
|
|
|
@ -34,18 +34,11 @@
|
|||
#include "tstoken.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#define INVALID_SQL_RET_MSG(p, ...) \
|
||||
do { \
|
||||
sprintf(p, __VA_ARGS__); \
|
||||
return TSDB_CODE_INVALID_SQL; \
|
||||
} while (0)
|
||||
|
||||
enum {
|
||||
TSDB_USE_SERVER_TS = 0,
|
||||
TSDB_USE_CLI_TS = 1,
|
||||
};
|
||||
|
||||
static void setErrMsg(char *msg, const char *sql);
|
||||
static int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize);
|
||||
|
||||
static int32_t tscToInteger(SSQLToken *pToken, int64_t *value, char **endPtr) {
|
||||
|
@ -97,7 +90,7 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1
|
|||
} else {
|
||||
// strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
|
||||
if (taosParseTime(pToken->z, time, pToken->n, timePrec) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(error, "invalid timestamp format", pToken->z);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -122,18 +115,21 @@ int tsParseTime(SSQLToken *pToken, int64_t *time, char **next, char *error, int1
|
|||
index = 0;
|
||||
sToken = tStrGetToken(pTokenEnd, &index, false, 0, NULL);
|
||||
pTokenEnd += index;
|
||||
|
||||
if (sToken.type == TK_MINUS || sToken.type == TK_PLUS) {
|
||||
|
||||
index = 0;
|
||||
valueToken = tStrGetToken(pTokenEnd, &index, false, 0, NULL);
|
||||
pTokenEnd += index;
|
||||
|
||||
if (valueToken.n < 2) {
|
||||
strcpy(error, "value is expected");
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(error, "value expected in timestamp", sToken.z);
|
||||
}
|
||||
|
||||
if (getTimestampInUsFromStr(valueToken.z, valueToken.n, &interval) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
if (timePrec == TSDB_TIME_PRECISION_MILLI) {
|
||||
interval /= 1000;
|
||||
}
|
||||
|
@ -156,7 +152,6 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
int64_t iv;
|
||||
int32_t numType;
|
||||
char * endptr = NULL;
|
||||
errno = 0; // reset global error code
|
||||
|
||||
switch (pSchema->type) {
|
||||
case TSDB_DATA_TYPE_BOOL: { // bool
|
||||
|
@ -168,7 +163,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else if (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0) {
|
||||
*(uint8_t *)payload = TSDB_DATA_BOOL_NULL;
|
||||
} else {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "invalid bool data", pToken->z);
|
||||
}
|
||||
} else if (pToken->type == TK_INTEGER) {
|
||||
iv = strtoll(pToken->z, NULL, 10);
|
||||
|
@ -179,7 +174,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else if (pToken->type == TK_NULL) {
|
||||
*(uint8_t *)payload = TSDB_DATA_BOOL_NULL;
|
||||
} else {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "invalid bool data", pToken->z);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -192,12 +187,12 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "invalid tinyint data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT8_MAX || iv <= INT8_MIN) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is overflow");
|
||||
return tscInvalidSQLErrMsg(msg, "tinyint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((int8_t *)payload) = (int8_t)iv;
|
||||
*((int8_t *)payload) = (int8_t) iv;
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -211,9 +206,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "invalid smallint data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT16_MAX || iv <= INT16_MIN) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is overflow");
|
||||
return tscInvalidSQLErrMsg(msg, "smallint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((int16_t *)payload) = (int16_t)iv;
|
||||
|
@ -229,9 +224,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "invalid int data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT32_MAX || iv <= INT32_MIN) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is overflow");
|
||||
return tscInvalidSQLErrMsg(msg, "int data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((int32_t *)payload) = (int32_t)iv;
|
||||
|
@ -248,9 +243,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
numType = tscToInteger(pToken, &iv, &endptr);
|
||||
if (TK_ILLEGAL == numType) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "invalid bigint data", pToken->z);
|
||||
} else if (errno == ERANGE || iv > INT64_MAX || iv <= INT64_MIN) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is overflow");
|
||||
return tscInvalidSQLErrMsg(msg, "bigint data overflow", pToken->z);
|
||||
}
|
||||
|
||||
*((int64_t *)payload) = iv;
|
||||
|
@ -266,12 +261,12 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
double dv;
|
||||
if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "illegal float data", pToken->z);
|
||||
}
|
||||
|
||||
float fv = (float)dv;
|
||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || (fv > FLT_MAX || fv < -FLT_MAX)) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "illegal float data", pToken->z);
|
||||
}
|
||||
|
||||
if (isinf(fv) || isnan(fv)) {
|
||||
|
@ -291,11 +286,11 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
double dv;
|
||||
if (TK_ILLEGAL == tscToDouble(pToken, &dv, &endptr)) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "illegal double data", pToken->z);
|
||||
}
|
||||
|
||||
if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || (dv > DBL_MAX || dv < -DBL_MAX)) {
|
||||
INVALID_SQL_RET_MSG(msg, "data is illegal");
|
||||
return tscInvalidSQLErrMsg(msg, "illegal double data", pToken->z);
|
||||
}
|
||||
|
||||
if (isinf(dv) || isnan(dv)) {
|
||||
|
@ -310,11 +305,11 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
// binary data cannot be null-terminated char string, otherwise the last char of the string is lost
|
||||
if (pToken->type == TK_NULL) {
|
||||
*payload = TSDB_DATA_BINARY_NULL;
|
||||
} else {
|
||||
// too long values will return invalid sql, not be truncated automatically
|
||||
} else { // too long values will return invalid sql, not be truncated automatically
|
||||
if (pToken->n > pSchema->bytes) {
|
||||
INVALID_SQL_RET_MSG(msg, "value too long");
|
||||
return tscInvalidSQLErrMsg(msg, "string data overflow", pToken->z);
|
||||
}
|
||||
|
||||
strncpy(payload, pToken->z, pToken->n);
|
||||
}
|
||||
|
||||
|
@ -326,8 +321,10 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
// if the converted output len is over than pSchema->bytes, return error: 'Argument list too long'
|
||||
if (!taosMbsToUcs4(pToken->z, pToken->n, payload, pSchema->bytes)) {
|
||||
sprintf(msg, "%s", strerror(errno));
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
char buf[512] = {0};
|
||||
snprintf(buf, 512, "%s", strerror(errno));
|
||||
|
||||
return tscInvalidSQLErrMsg(msg, buf, pToken->z);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -342,8 +339,9 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
} else {
|
||||
int64_t temp;
|
||||
if (tsParseTime(pToken, &temp, str, msg, timePrec) != TSDB_CODE_SUCCESS) {
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(msg, "invalid timestamp", pToken->z);
|
||||
}
|
||||
|
||||
*((int64_t *)payload) = temp;
|
||||
}
|
||||
|
||||
|
@ -351,18 +349,7 @@ int32_t tsParseOneColumnData(SSchema *pSchema, SSQLToken *pToken, char *payload,
|
|||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// todo merge the error msg function with tSQLParser
|
||||
static void setErrMsg(char *msg, const char *sql) {
|
||||
const char * msgFormat = "near \"%s\" syntax error";
|
||||
const int32_t BACKWARD_CHAR_STEP = 15;
|
||||
|
||||
// only extract part of sql string,avoid too long sql string cause stack over flow
|
||||
char buf[64] = {0};
|
||||
strncpy(buf, (sql - BACKWARD_CHAR_STEP), tListLen(buf) - 1);
|
||||
sprintf(msg, msgFormat, buf);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -385,7 +372,8 @@ static int32_t tsCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start
|
|||
}
|
||||
} else {
|
||||
if (pDataBlocks->tsSource == TSDB_USE_SERVER_TS) {
|
||||
return -1;
|
||||
return -1; // client time/server time can not be mixed
|
||||
|
||||
} else if (pDataBlocks->tsSource == -1) {
|
||||
pDataBlocks->tsSource = TSDB_USE_CLI_TS;
|
||||
}
|
||||
|
@ -403,7 +391,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
|
|||
int16_t timePrec) {
|
||||
int32_t index = 0;
|
||||
bool isPrevOptr;
|
||||
SSQLToken sToken;
|
||||
SSQLToken sToken = {0};
|
||||
char * payload = pDataBlocks->pData + pDataBlocks->size;
|
||||
|
||||
// 1. set the parsed value from sql string
|
||||
|
@ -424,6 +412,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
|
|||
if (tscAddParamToDataBlock(pDataBlocks, pSchema->type, (uint8_t)timePrec, pSchema->bytes, offset) != NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
strcpy(error, "client out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
@ -431,7 +420,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
|
|||
if (((sToken.type != TK_NOW) && (sToken.type != TK_INTEGER) && (sToken.type != TK_STRING) &&
|
||||
(sToken.type != TK_FLOAT) && (sToken.type != TK_BOOL) && (sToken.type != TK_NULL)) ||
|
||||
(sToken.n == 0) || (sToken.type == TK_RP)) {
|
||||
setErrMsg(error, *str);
|
||||
tscInvalidSQLErrMsg(error, "invalid data or symbol", sToken.z);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -448,6 +437,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
|
|||
}
|
||||
|
||||
if (isPrimaryKey && tsCheckTimestamp(pDataBlocks, start) != TSDB_CODE_SUCCESS) {
|
||||
tscInvalidSQLErrMsg(error, "client time/server time can not be mixed up", sToken.z);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -457,8 +447,7 @@ int tsParseOneRowData(char **str, STableDataBlocks *pDataBlocks, SSchema schema[
|
|||
char *ptr = payload;
|
||||
|
||||
for (int32_t i = 0; i < spd->numOfCols; ++i) {
|
||||
if (!spd->hasVal[i]) {
|
||||
// current column do not have any value to insert, set it to null
|
||||
if (!spd->hasVal[i]) { // current column do not have any value to insert, set it to null
|
||||
setNull(ptr, schema[i].type, schema[i].bytes);
|
||||
}
|
||||
|
||||
|
@ -513,8 +502,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, SMeterMeta *pMeterMe
|
|||
}
|
||||
|
||||
int32_t len = tsParseOneRowData(str, pDataBlock, pSchema, spd, error, precision);
|
||||
if (len <= 0) {
|
||||
setErrMsg(error, *str);
|
||||
if (len <= 0) { // error message has been set in tsParseOneRowData
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -524,7 +512,7 @@ int tsParseValues(char **str, STableDataBlocks *pDataBlock, SMeterMeta *pMeterMe
|
|||
sToken = tStrGetToken(*str, &index, false, 0, NULL);
|
||||
*str += index;
|
||||
if (sToken.n == 0 || sToken.type != TK_RP) {
|
||||
setErrMsg(error, *str);
|
||||
tscInvalidSQLErrMsg(error, ") expected", *str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -719,8 +707,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
|
|||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
if (sToken.type == TK_USING) {
|
||||
// create table if not exists
|
||||
if (sToken.type == TK_USING) { // create table if not exists
|
||||
index = 0;
|
||||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||
sql += index;
|
||||
|
@ -736,8 +723,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
|
|||
}
|
||||
|
||||
if (!UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||
strcpy(pCmd->payload, "create table only from super table is allowed");
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "create table only from super table is allowed", sToken.z);
|
||||
}
|
||||
|
||||
char * tagVal = pTag->data;
|
||||
|
@ -747,8 +733,7 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
|
|||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||
sql += index;
|
||||
if (sToken.type != TK_TAGS) {
|
||||
setErrMsg(pCmd->payload, sql);
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sql);
|
||||
}
|
||||
|
||||
int32_t numOfTagValues = 0;
|
||||
|
@ -773,28 +758,23 @@ static int32_t tscParseSqlForCreateTableOnDemand(char **sqlstr, SSqlObj *pSql) {
|
|||
code = tsParseOneColumnData(&pTagSchema[numOfTagValues], &sToken, tagVal, pCmd->payload, &sql, false,
|
||||
pMeterMetaInfo->pMeterMeta->precision);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
setErrMsg(pCmd->payload, sql);
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return code;
|
||||
}
|
||||
|
||||
if ((pTagSchema[numOfTagValues].type == TSDB_DATA_TYPE_BINARY ||
|
||||
pTagSchema[numOfTagValues].type == TSDB_DATA_TYPE_NCHAR) &&
|
||||
sToken.n > pTagSchema[numOfTagValues].bytes) {
|
||||
strcpy(pCmd->payload, "tag value too long");
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
pTagSchema[numOfTagValues].type == TSDB_DATA_TYPE_NCHAR) && sToken.n > pTagSchema[numOfTagValues].bytes) {
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "string too long", sToken.z);
|
||||
}
|
||||
|
||||
tagVal += pTagSchema[numOfTagValues++].bytes;
|
||||
}
|
||||
|
||||
if (numOfTagValues != pMeterMetaInfo->pMeterMeta->numOfTags) {
|
||||
setErrMsg(pCmd->payload, sql);
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "number of tags mismatch", sql);
|
||||
}
|
||||
|
||||
if (tscValidateName(&tableToken) != TSDB_CODE_SUCCESS) {
|
||||
setErrMsg(pCmd->payload, sql);
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "invalid table name", sql);
|
||||
}
|
||||
|
||||
int32_t ret = setMeterID(pSql, &tableToken, 0);
|
||||
|
@ -844,25 +824,19 @@ int validateTableName(char *tblName, int len) {
|
|||
* @param pSql
|
||||
* @return
|
||||
*/
|
||||
int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
||||
int doParserInsertSql(SSqlObj *pSql, char *str) {
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
pCmd->command = TSDB_SQL_INSERT;
|
||||
pCmd->isInsertFromFile = -1;
|
||||
pCmd->count = 0;
|
||||
|
||||
pSql->res.numOfRows = 0;
|
||||
int32_t code = TSDB_CODE_INVALID_SQL;
|
||||
int32_t totalNum = 0;
|
||||
|
||||
int code = TSDB_CODE_INVALID_SQL;
|
||||
|
||||
SMeterMetaInfo *pMeterMetaInfo = tscAddEmptyMeterMetaInfo(pCmd);
|
||||
|
||||
if ((code = tscAllocPayload(pCmd, TSDB_PAYLOAD_SIZE)) != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
void *pTableHashList = taosInitIntHash(128, sizeof(void *), taosHashInt);
|
||||
void *pTableHashList = taosInitIntHash(128, POINTER_BYTES, taosHashInt);
|
||||
|
||||
pSql->cmd.pDataBlocks = tscCreateBlockArrayList();
|
||||
tscTrace("%p create data block list for submit data, %p", pSql, pSql->cmd.pDataBlocks);
|
||||
|
@ -885,11 +859,11 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
|
||||
// Check if the table name available or not
|
||||
if (validateTableName(sToken.z, sToken.n) != TSDB_CODE_SUCCESS) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "table name is invalid");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "table name invalid", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
//TODO refactor
|
||||
if ((code = setMeterID(pSql, &sToken, 0)) != TSDB_CODE_SUCCESS) {
|
||||
goto _error_clean;
|
||||
}
|
||||
|
@ -909,8 +883,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
}
|
||||
|
||||
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "insert data into metric is not supported");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "insert data into super table is not supported", NULL);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -918,8 +891,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
sToken = tStrGetToken(str, &index, false, 0, NULL);
|
||||
str += index;
|
||||
if (sToken.n == 0) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "keyword VALUES or FILE are required");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES or FILE are required", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -933,8 +905,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
pCmd->isInsertFromFile = 0;
|
||||
} else {
|
||||
if (pCmd->isInsertFromFile == 1) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "keyword VALUES and FILE are not allowed to mix up");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES and FILE are not allowed to mix up", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
}
|
||||
|
@ -953,8 +924,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
pCmd->isInsertFromFile = 1;
|
||||
} else {
|
||||
if (pCmd->isInsertFromFile == 0) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "keyword VALUES and FILE are not allowed to mix up");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES and FILE are not allowed to mix up", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
}
|
||||
|
@ -963,8 +933,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
sToken = tStrGetToken(str, &index, false, 0, NULL);
|
||||
str += index;
|
||||
if (sToken.n == 0) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "file path is required following keyword FILE");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "file path is required following keyword FILE", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -974,8 +943,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
|
||||
wordexp_t full_path;
|
||||
if (wordexp(fname, &full_path, 0) != 0) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "invalid filename");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "invalid filename", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
strcpy(fname, full_path.we_wordv[0]);
|
||||
|
@ -994,8 +962,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
if (pCmd->isInsertFromFile == -1) {
|
||||
pCmd->isInsertFromFile = 0;
|
||||
} else if (pCmd->isInsertFromFile == 1) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "keyword VALUES and FILE are not allowed to mix up");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES and FILE are not allowed to mix up", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -1032,8 +999,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
pElem->colIndex = t;
|
||||
|
||||
if (spd.hasVal[t] == true) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "duplicated column name");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "duplicated column name", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -1044,15 +1010,13 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
}
|
||||
|
||||
if (!findColumnIndex) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "invalid column name");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "invalid column name", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
}
|
||||
|
||||
if (spd.numOfAssignedCols == 0 || spd.numOfAssignedCols > pMeterMeta->numOfColumns) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "column name expected");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "column name expected", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -1061,8 +1025,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
str += index;
|
||||
|
||||
if (sToken.type != TK_VALUES) {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "keyword VALUES is expected");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES is expected", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
|
||||
|
@ -1071,8 +1034,7 @@ int tsParseInsertStatement(SSqlObj *pSql, char *str, char *acct, char *db) {
|
|||
goto _error_clean;
|
||||
}
|
||||
} else {
|
||||
code = TSDB_CODE_INVALID_SQL;
|
||||
sprintf(pCmd->payload, "keyword VALUES or FILE are required");
|
||||
code = tscInvalidSQLErrMsg(pCmd->payload, "keyword VALUES or FILE are required", sToken.z);
|
||||
goto _error_clean;
|
||||
}
|
||||
}
|
||||
|
@ -1116,29 +1078,25 @@ int tsParseInsertSql(SSqlObj *pSql, char *sql, char *acct, char *db) {
|
|||
return TSDB_CODE_NO_RIGHTS;
|
||||
}
|
||||
|
||||
int32_t index = 0;
|
||||
int32_t index = 0;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
||||
SSQLToken sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||
if (sToken.type == TK_IMPORT) {
|
||||
pCmd->order.order = TSQL_SO_ASC;
|
||||
} else if (sToken.type != TK_INSERT) {
|
||||
if (sToken.n) {
|
||||
sToken.z[sToken.n] = 0;
|
||||
sprintf(pCmd->payload, "invalid keyword:%s", sToken.z);
|
||||
} else {
|
||||
strcpy(pCmd->payload, "no any keywords");
|
||||
}
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
assert(sToken.type == TK_INSERT || sToken.type == TK_IMPORT);
|
||||
pCmd->import = (sToken.type == TK_IMPORT);
|
||||
|
||||
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||
if (sToken.type != TK_INTO) {
|
||||
strcpy(pCmd->payload, "keyword INTO is expected");
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
return tscInvalidSQLErrMsg(pCmd->payload, "keyword INTO is expected", sToken.z);
|
||||
}
|
||||
|
||||
return tsParseInsertStatement(pSql, sql + index, acct, db);
|
||||
pCmd->count = 0;
|
||||
pCmd->command = TSDB_SQL_INSERT;
|
||||
pCmd->isInsertFromFile = -1;
|
||||
pSql->res.numOfRows = 0;
|
||||
|
||||
return doParserInsertSql(pSql, sql + index);
|
||||
}
|
||||
|
||||
int tsParseSql(SSqlObj *pSql, char *acct, char *db, bool multiVnodeInsertion) {
|
||||
|
@ -1259,6 +1217,7 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp) {
|
|||
pSql->res.code = TSDB_CODE_INVALID_SQL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pTableDataBlock->size += len;
|
||||
|
||||
count++;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -123,6 +123,7 @@ bool tsMeterMetaIdentical(SMeterMeta* p1, SMeterMeta* p2) {
|
|||
return memcmp(p1, p2, size) == 0;
|
||||
}
|
||||
|
||||
//todo refactor
|
||||
static FORCE_INLINE char* skipSegments(char* input, char delimiter, int32_t num) {
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
while (*input != 0 && *input++ != delimiter) {
|
||||
|
|
|
@ -1415,7 +1415,7 @@ int tscBuildSubmitMsg(SSqlObj *pSql) {
|
|||
pMsg = pStart;
|
||||
|
||||
pShellMsg = (SShellSubmitMsg *)pMsg;
|
||||
pShellMsg->import = pSql->cmd.order.order;
|
||||
pShellMsg->import = pSql->cmd.import;
|
||||
pShellMsg->vnode = htons(pMeterMeta->vpeerDesc[pMeterMeta->index].vnode);
|
||||
pShellMsg->numOfSid = htonl(pSql->cmd.count); // number of meters to be inserted
|
||||
|
||||
|
@ -3453,31 +3453,6 @@ int tscProcessQueryRsp(SSqlObj *pSql) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void doDecompressPayload(SSqlCmd *pCmd, SSqlRes *pRes, int16_t compressed) {
|
||||
if (compressed && pRes->numOfRows > 0) {
|
||||
SRetrieveMeterRsp *pRetrieve = (SRetrieveMeterRsp *)pRes->pRsp;
|
||||
|
||||
int32_t numOfTotalCols = pCmd->fieldsInfo.numOfOutputCols + pCmd->fieldsInfo.numOfHiddenCols;
|
||||
int32_t rowSize = pCmd->fieldsInfo.pOffset[numOfTotalCols - 1] + pCmd->fieldsInfo.pFields[numOfTotalCols - 1].bytes;
|
||||
|
||||
// TODO handle the OOM problem
|
||||
char * buf = malloc(rowSize * pRes->numOfRows);
|
||||
|
||||
int32_t payloadSize = pRes->rspLen - 1 - sizeof(SRetrieveMeterRsp);
|
||||
assert(payloadSize > 0);
|
||||
|
||||
int32_t decompressedSize = tsDecompressString(pRetrieve->data, payloadSize, 1, buf, rowSize * pRes->numOfRows, 0, 0, 0);
|
||||
assert(decompressedSize == rowSize * pRes->numOfRows);
|
||||
|
||||
pRes->pRsp = realloc(pRes->pRsp, pRes->rspLen - payloadSize + decompressedSize);
|
||||
memcpy(pRes->pRsp + sizeof(SRetrieveMeterRsp), buf, decompressedSize);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
pRes->data = ((SRetrieveMeterRsp *)pRes->pRsp)->data;
|
||||
}
|
||||
|
||||
int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
||||
SSqlRes *pRes = &pSql->res;
|
||||
SSqlCmd *pCmd = &pSql->cmd;
|
||||
|
@ -3490,9 +3465,7 @@ int tscProcessRetrieveRspFromVnode(SSqlObj *pSql) {
|
|||
pRes->offset = htobe64(pRetrieve->offset);
|
||||
|
||||
pRes->useconds = htobe64(pRetrieve->useconds);
|
||||
pRetrieve->compress = htons(pRetrieve->compress);
|
||||
|
||||
doDecompressPayload(pCmd, pRes, pRetrieve->compress);
|
||||
pRes->data = pRetrieve->data;
|
||||
|
||||
tscSetResultPointer(pCmd, pRes);
|
||||
pRes->row = 0;
|
||||
|
|
|
@ -246,7 +246,12 @@ int taos_query_imp(STscObj* pObj, SSqlObj* pSql) {
|
|||
tscDoQuery(pSql);
|
||||
}
|
||||
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj);
|
||||
if (pRes->code == TSDB_CODE_SUCCESS) {
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj);
|
||||
} else {
|
||||
tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(pObj), pObj);
|
||||
}
|
||||
|
||||
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||
tscFreeSqlObjPartial(pSql);
|
||||
}
|
||||
|
@ -266,8 +271,9 @@ int taos_query(TAOS *taos, const char *sqlstr) {
|
|||
|
||||
size_t sqlLen = strlen(sqlstr);
|
||||
if (sqlLen > TSDB_MAX_SQL_LEN) {
|
||||
tscError("%p sql too long", pSql);
|
||||
pRes->code = TSDB_CODE_INVALID_SQL;
|
||||
pRes->code = tscInvalidSQLErrMsg(pSql->cmd.payload, "sql too long", NULL); // set the additional error msg for invalid sql
|
||||
tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
@ -276,8 +282,9 @@ int taos_query(TAOS *taos, const char *sqlstr) {
|
|||
void *sql = realloc(pSql->sqlstr, sqlLen + 1);
|
||||
if (sql == NULL) {
|
||||
pRes->code = TSDB_CODE_CLI_OUT_OF_MEMORY;
|
||||
tscError("%p failed to malloc sql string buffer", pSql);
|
||||
tscTrace("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
tscError("%p failed to malloc sql string buffer, reason:%s", pSql, strerror(errno));
|
||||
|
||||
tscError("%p SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj);
|
||||
return pRes->code;
|
||||
}
|
||||
|
||||
|
@ -777,9 +784,9 @@ int taos_errno(TAOS *taos) {
|
|||
}
|
||||
|
||||
char *taos_errstr(TAOS *taos) {
|
||||
STscObj * pObj = (STscObj *)taos;
|
||||
unsigned char code;
|
||||
char temp[256] = {0};
|
||||
STscObj *pObj = (STscObj *)taos;
|
||||
uint8_t code;
|
||||
// char temp[256] = {0};
|
||||
|
||||
if (pObj == NULL || pObj->signature != pObj) return tsError[globalCode];
|
||||
|
||||
|
@ -788,9 +795,10 @@ char *taos_errstr(TAOS *taos) {
|
|||
else
|
||||
code = pObj->pSql->res.code;
|
||||
|
||||
// for invalid sql, additional information is attached to explain why the sql is invalid
|
||||
if (code == TSDB_CODE_INVALID_SQL) {
|
||||
snprintf(temp, tListLen(temp), "invalid SQL: %s", pObj->pSql->cmd.payload);
|
||||
strcpy(pObj->pSql->cmd.payload, temp);
|
||||
// snprintf(temp, tListLen(temp), "invalid SQL: %s", pObj->pSql->cmd.payload);
|
||||
// strcpy(pObj->pSql->cmd.payload, temp);
|
||||
return pObj->pSql->cmd.payload;
|
||||
} else {
|
||||
return tsError[code];
|
||||
|
|
|
@ -1294,8 +1294,7 @@ int32_t tscValidateName(SSQLToken* pToken) {
|
|||
|
||||
// re-build the whole name string
|
||||
if (pStr[firstPartLen] == TS_PATH_DELIMITER[0]) {
|
||||
// first part do not have quote
|
||||
// do nothing
|
||||
// first part do not have quote do nothing
|
||||
} else {
|
||||
pStr[firstPartLen] = TS_PATH_DELIMITER[0];
|
||||
memmove(&pStr[firstPartLen + 1], pToken->z, pToken->n);
|
||||
|
@ -1842,5 +1841,30 @@ bool tscIsUpdateQuery(STscObj* pObj) {
|
|||
SSqlCmd* pCmd = &pObj->pSql->cmd;
|
||||
return ((pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) ||
|
||||
TSDB_SQL_USE_DB == pCmd->command) ? 1 : 0;
|
||||
|
||||
}
|
||||
|
||||
int32_t tscInvalidSQLErrMsg(char *msg, const char *additionalInfo, const char *sql) {
|
||||
const char *msgFormat1 = "invalid SQL: %s";
|
||||
const char *msgFormat2 = "invalid SQL: syntax error near \"%s\" (%s)";
|
||||
const char *msgFormat3 = "invalid SQL: syntax error near \"%s\"";
|
||||
|
||||
const int32_t BACKWARD_CHAR_STEP = 0;
|
||||
|
||||
if (sql == NULL) {
|
||||
assert(additionalInfo != NULL);
|
||||
sprintf(msg, msgFormat1, additionalInfo);
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
char buf[64] = {0}; // only extract part of sql string
|
||||
strncpy(buf, (sql - BACKWARD_CHAR_STEP), tListLen(buf) - 1);
|
||||
|
||||
if (additionalInfo != NULL) {
|
||||
sprintf(msg, msgFormat2, buf, additionalInfo);
|
||||
} else {
|
||||
sprintf(msg, msgFormat3, buf); // no additional information for invalid sql error
|
||||
}
|
||||
|
||||
return TSDB_CODE_INVALID_SQL;
|
||||
}
|
||||
|
||||
|
|
|
@ -568,7 +568,6 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t numOfRows;
|
||||
int16_t precision;
|
||||
int16_t compress;
|
||||
int64_t offset; // updated offset value for multi-vnode projection query
|
||||
int64_t useconds;
|
||||
char data[];
|
||||
|
|
|
@ -353,7 +353,7 @@ bool vnodeIsValidVnodeCfg(SVnodeCfg *pCfg);
|
|||
|
||||
int32_t vnodeGetResultSize(void *handle, int32_t *numOfRows);
|
||||
|
||||
int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, int32_t *size);
|
||||
int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows);
|
||||
|
||||
int64_t vnodeGetOffsetVal(void *thandle);
|
||||
|
||||
|
|
|
@ -6943,36 +6943,18 @@ static int32_t resultInterpolate(SQInfo *pQInfo, tFilePage **data, tFilePage **p
|
|||
return numOfRes;
|
||||
}
|
||||
|
||||
static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data, int32_t *size) {
|
||||
static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data) {
|
||||
SMeterObj *pObj = pQInfo->pObj;
|
||||
SQuery * pQuery = &pQInfo->query;
|
||||
|
||||
int tnumOfRows = vnodeList[pObj->vnode].cfg.rowsInFileBlock;
|
||||
int32_t dataSize = pQInfo->query.rowSize * numOfRows;
|
||||
int tnumOfRows = vnodeList[pObj->vnode].cfg.rowsInFileBlock;
|
||||
|
||||
if (dataSize >= tsCompressMsgSize && tsCompressMsgSize > 0) {
|
||||
char *compBuf = malloc((size_t)dataSize);
|
||||
// for metric query, bufIndex always be 0.
|
||||
for (int32_t col = 0; col < pQuery->numOfOutputCols; ++col) { // pQInfo->bufIndex == 0
|
||||
int32_t bytes = pQuery->pSelectExpr[col].resBytes;
|
||||
|
||||
// for metric query, bufIndex always be 0.
|
||||
char *d = compBuf;
|
||||
for (int32_t col = 0; col < pQuery->numOfOutputCols; ++col) { // pQInfo->bufIndex == 0
|
||||
int32_t bytes = pQuery->pSelectExpr[col].resBytes;
|
||||
|
||||
memmove(d, pQuery->sdata[col]->data + bytes * tnumOfRows * pQInfo->bufIndex, bytes * numOfRows);
|
||||
d += bytes * numOfRows;
|
||||
}
|
||||
|
||||
*size = tsCompressString(compBuf, dataSize, 1, data, dataSize + EXTRA_BYTES, 0, 0, 0);
|
||||
|
||||
dTrace("QInfo:%p compress rsp msg, before:%d, after:%d", pQInfo, dataSize, *size);
|
||||
free(compBuf);
|
||||
} else { // for metric query, bufIndex always be 0.
|
||||
for (int32_t col = 0; col < pQuery->numOfOutputCols; ++col) { // pQInfo->bufIndex == 0
|
||||
int32_t bytes = pQuery->pSelectExpr[col].resBytes;
|
||||
|
||||
memmove(data, pQuery->sdata[col]->data + bytes * tnumOfRows * pQInfo->bufIndex, bytes * numOfRows);
|
||||
data += bytes * numOfRows;
|
||||
}
|
||||
memmove(data, pQuery->sdata[col]->data + bytes * tnumOfRows * pQInfo->bufIndex, bytes * numOfRows);
|
||||
data += bytes * numOfRows;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6987,7 +6969,7 @@ static void doCopyQueryResultToMsg(SQInfo *pQInfo, int32_t numOfRows, char *data
|
|||
* @param numOfRows the number of rows that are not returned in current retrieve
|
||||
* @return
|
||||
*/
|
||||
int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, int32_t *size) {
|
||||
int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows) {
|
||||
SQInfo *pQInfo = (SQInfo *)handle;
|
||||
SQuery *pQuery = &pQInfo->query;
|
||||
|
||||
|
@ -7000,7 +6982,7 @@ int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, i
|
|||
// make sure file exist
|
||||
if (VALIDFD(fd)) {
|
||||
size_t s = lseek(fd, 0, SEEK_END);
|
||||
dTrace("QInfo:%p ts comp data return, file:%s, size:%ld", pQInfo, pQuery->sdata[0]->data, size);
|
||||
dTrace("QInfo:%p ts comp data return, file:%s, size:%lld", pQInfo, pQuery->sdata[0]->data, s);
|
||||
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
read(fd, data, s);
|
||||
|
@ -7012,7 +6994,7 @@ int32_t vnodeCopyQueryResultToMsg(void *handle, char *data, int32_t numOfRows, i
|
|||
pQuery->sdata[0]->data, strerror(errno));
|
||||
}
|
||||
} else {
|
||||
doCopyQueryResultToMsg(pQInfo, numOfRows, data, size);
|
||||
doCopyQueryResultToMsg(pQInfo, numOfRows, data);
|
||||
}
|
||||
|
||||
return numOfRows;
|
||||
|
|
|
@ -850,7 +850,7 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
|
|||
// the remained number of retrieved rows, not the interpolated result
|
||||
int numOfRows = pQInfo->pointsRead - pQInfo->pointsReturned;
|
||||
|
||||
int32_t numOfFinal = vnodeCopyQueryResultToMsg(pQInfo, data, numOfRows, size);
|
||||
int32_t numOfFinal = vnodeCopyQueryResultToMsg(pQInfo, data, numOfRows);
|
||||
pQInfo->pointsReturned += numOfFinal;
|
||||
|
||||
dTrace("QInfo:%p %d are returned, totalReturned:%d totalRead:%d", pQInfo, numOfFinal, pQInfo->pointsReturned,
|
||||
|
@ -862,12 +862,9 @@ int vnodeSaveQueryResult(void *handle, char *data, int32_t *size) {
|
|||
uint64_t oldSignature = TSDB_QINFO_SET_QUERY_FLAG(pQInfo);
|
||||
|
||||
/*
|
||||
* If SQInfo has been released, the value of signature cannot be equalled to
|
||||
* the address of pQInfo, since in release function, the original value has
|
||||
* been
|
||||
* destroyed. However, this memory area may be reused by another function.
|
||||
* It may be 0 or any value, but it is rarely still be equalled to the address
|
||||
* of SQInfo.
|
||||
* If SQInfo has been released, the value of signature cannot be equalled to the address of pQInfo,
|
||||
* since in release function, the original value has been destroyed. However, this memory area may be reused
|
||||
* by another function. It may be 0 or any value, but it is rarely still be equalled to the address of SQInfo.
|
||||
*/
|
||||
if (oldSignature == 0 || oldSignature != (uint64_t)pQInfo) {
|
||||
dTrace("%p freed or killed, old sig:%p abort query", pQInfo, oldSignature);
|
||||
|
|
|
@ -452,11 +452,7 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
|
|||
pMsg = pRsp->data;
|
||||
|
||||
if (numOfRows > 0 && code == TSDB_CODE_SUCCESS) {
|
||||
int32_t oldSize = size;
|
||||
vnodeSaveQueryResult((void *)(pRetrieve->qhandle), pRsp->data, &size);
|
||||
if (oldSize > size) {
|
||||
pRsp->compress = htons(1); // denote that the response msg is compressed
|
||||
}
|
||||
}
|
||||
|
||||
pMsg += size;
|
||||
|
@ -573,6 +569,7 @@ int vnodeProcessShellSubmitRequest(char *pMsg, int msgLen, SShellObj *pObj) {
|
|||
int sversion = htonl(pBlocks->sversion);
|
||||
|
||||
if (pSubmit->import) {
|
||||
dTrace("start to import data");
|
||||
code = vnodeImportPoints(pMeterObj, (char *) &(pBlocks->numOfRows), subMsgLen, TSDB_DATA_SOURCE_SHELL, pObj,
|
||||
sversion, &numOfPoints, now);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue