Merge branch 'develop' into feature/slguan
This commit is contained in:
commit
b96fdff863
|
@ -23,24 +23,10 @@ extern "C" {
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tsqldef.h"
|
#include "tsqldef.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
#define TK_SPACE 200
|
|
||||||
#define TK_COMMENT 201
|
|
||||||
#define TK_ILLEGAL 202
|
|
||||||
#define TK_HEX 203 // hex number 0x123
|
|
||||||
#define TK_OCT 204 // oct number
|
|
||||||
#define TK_BIN 205 // bin format data 0b111
|
|
||||||
#define TK_FILE 206
|
|
||||||
#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query
|
|
||||||
|
|
||||||
#define TSQL_SO_ASC 1
|
|
||||||
#define TSQL_SO_DESC 0
|
|
||||||
|
|
||||||
#define MAX_TOKEN_LEN 30
|
#define MAX_TOKEN_LEN 30
|
||||||
|
|
||||||
#define TSQL_TBNAME "TBNAME"
|
|
||||||
#define TSQL_TBNAME_L "tbname"
|
|
||||||
|
|
||||||
// token type
|
// token type
|
||||||
enum {
|
enum {
|
||||||
TSQL_NODE_TYPE_EXPR = 0x1,
|
TSQL_NODE_TYPE_EXPR = 0x1,
|
||||||
|
@ -278,8 +264,7 @@ typedef struct tSQLExpr {
|
||||||
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
|
uint32_t nSQLOptr; // TK_FUNCTION: sql function, TK_LE: less than(binary expr)
|
||||||
|
|
||||||
// the full sql string of function(col, param), which is actually the raw
|
// the full sql string of function(col, param), which is actually the raw
|
||||||
// field name,
|
// field name, since the function name is kept in nSQLOptr already
|
||||||
// since the function name is kept in nSQLOptr already
|
|
||||||
SSQLToken operand;
|
SSQLToken operand;
|
||||||
struct tSQLExprList *pParam; // function parameters
|
struct tSQLExprList *pParam; // function parameters
|
||||||
|
|
||||||
|
@ -346,8 +331,6 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SSQLToken
|
||||||
|
|
||||||
void tSQLExprListDestroy(tSQLExprList *pList);
|
void tSQLExprListDestroy(tSQLExprList *pList);
|
||||||
|
|
||||||
int32_t tSQLSyntaxNodeToString(tSQLExpr *pNode, char *dst);
|
|
||||||
|
|
||||||
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
|
SQuerySQL *tSetQuerySQLElems(SSQLToken *pSelectToken, tSQLExprList *pSelection, tVariantList *pFrom, tSQLExpr *pWhere,
|
||||||
tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval,
|
tVariantList *pGroupby, tVariantList *pSortOrder, SSQLToken *pInterval,
|
||||||
SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
SSQLToken *pSliding, tVariantList *pFill, SLimitVal *pLimit, SLimitVal *pGLimit);
|
||||||
|
@ -379,6 +362,7 @@ tDCLSQL *tTokenListAppend(tDCLSQL *pTokenList, SSQLToken *pToken);
|
||||||
void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists);
|
void setCreateDBSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pToken, SCreateDBInfo *pDB, SSQLToken *pIgExists);
|
||||||
|
|
||||||
void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo);
|
void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken *pPwd, SCreateAcctSQL *pAcctInfo);
|
||||||
|
void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo);
|
||||||
|
|
||||||
// prefix show db.tables;
|
// prefix show db.tables;
|
||||||
void setDBName(SSQLToken *pCpxName, SSQLToken *pDB);
|
void setDBName(SSQLToken *pCpxName, SSQLToken *pDB);
|
|
@ -35,7 +35,7 @@ extern "C" {
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tscCache.h"
|
#include "tscCache.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
/**************** End of %include directives **********************************/
|
/**************** End of %include directives **********************************/
|
||||||
/* These constants specify the various numeric values for terminal symbols
|
/* These constants specify the various numeric values for terminal symbols
|
||||||
|
@ -2146,7 +2146,7 @@ static void yy_reduce(
|
||||||
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
|
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
|
||||||
break;
|
break;
|
||||||
case 79: /* db_optr ::= */
|
case 79: /* db_optr ::= */
|
||||||
{memset(&yymsp[1].minor.yy398, 0, sizeof(SCreateDBInfo));}
|
{setDefaultCreateDbOption(&yymsp[1].minor.yy398);}
|
||||||
break;
|
break;
|
||||||
case 80: /* db_optr ::= db_optr tables */
|
case 80: /* db_optr ::= db_optr tables */
|
||||||
case 94: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==94);
|
case 94: /* alter_db_optr ::= alter_db_optr tables */ yytestcase(yyruleno==94);
|
||||||
|
@ -2199,7 +2199,7 @@ static void yy_reduce(
|
||||||
yymsp[-1].minor.yy398 = yylhsminor.yy398;
|
yymsp[-1].minor.yy398 = yylhsminor.yy398;
|
||||||
break;
|
break;
|
||||||
case 92: /* alter_db_optr ::= */
|
case 92: /* alter_db_optr ::= */
|
||||||
{ memset(&yymsp[1].minor.yy398, 0, sizeof(SCreateDBInfo));}
|
{ setDefaultCreateDbOption(&yymsp[1].minor.yy398);}
|
||||||
break;
|
break;
|
||||||
case 95: /* typename ::= ids */
|
case 95: /* typename ::= ids */
|
||||||
{ tSQLSetColumnType (&yylhsminor.yy223, &yymsp[0].minor.yy0); }
|
{ tSQLSetColumnType (&yylhsminor.yy223, &yymsp[0].minor.yy0); }
|
|
@ -21,8 +21,12 @@
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
|
#include "tsqldef.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
#include "ttypes.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "tscSQLParser.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -37,10 +41,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken);
|
static tSQLSyntaxNode *tSQLSyntaxNodeCreate(SSchema *pSchema, int32_t numOfCols, SSQLToken *pToken);
|
||||||
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *));
|
static void tSQLSyntaxNodeDestroy(tSQLSyntaxNode *pNode, void (*fp)(void *));
|
||||||
|
|
||||||
static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i);
|
static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *str, int32_t *i);
|
||||||
static void destroySyntaxTree(tSQLSyntaxNode *);
|
static void destroySyntaxTree(tSQLSyntaxNode *);
|
||||||
|
|
||||||
static uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode *pLeft,
|
static uint8_t isQueryOnPrimaryKey(const char *primaryColumnName, const tSQLSyntaxNode *pLeft,
|
||||||
const tSQLSyntaxNode *pRight);
|
const tSQLSyntaxNode *pRight);
|
||||||
|
@ -255,7 +259,7 @@ static tSQLSyntaxNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, cha
|
||||||
|
|
||||||
t0 = tStrGetToken(str, i, false, 0, NULL);
|
t0 = tStrGetToken(str, i, false, 0, NULL);
|
||||||
if (t0.n == 0 || t0.type == TK_RP) {
|
if (t0.n == 0 || t0.type == TK_RP) {
|
||||||
if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr
|
if (pLeft->nodeType != TSQL_NODE_EXPR) { // if left is not the expr, it is not a legal expr
|
||||||
tSQLSyntaxNodeDestroy(pLeft, NULL);
|
tSQLSyntaxNodeDestroy(pLeft, NULL);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tnote.h"
|
#include "tnote.h"
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
|
|
@ -25,7 +25,8 @@
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
|
|
||||||
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
||||||
|
@ -48,18 +49,15 @@ typedef struct SColumnIdListRes {
|
||||||
SColumnList list;
|
SColumnList list;
|
||||||
} SColumnIdListRes;
|
} SColumnIdListRes;
|
||||||
|
|
||||||
static SSqlExpr* doAddProjectCol(SSqlCmd* pCmd, int32_t fieldIDInResult, int32_t colIdx, int32_t tableIndex);
|
static SSqlExpr* doAddProjectCol(SSqlCmd* pCmd, int32_t outputIndex, int32_t colIdx, int32_t tableIndex);
|
||||||
|
|
||||||
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
|
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
|
||||||
|
|
||||||
static bool has(tFieldList* pFieldList, int32_t offset, char* name);
|
|
||||||
|
|
||||||
static char* getAccountId(SSqlObj* pSql);
|
static char* getAccountId(SSqlObj* pSql);
|
||||||
|
|
||||||
|
static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name);
|
||||||
static void getCurrentDBName(SSqlObj* pSql, SSQLToken* pDBToken);
|
static void getCurrentDBName(SSqlObj* pSql, SSQLToken* pDBToken);
|
||||||
static bool hasSpecifyDB(SSQLToken* pTableName);
|
static bool hasSpecifyDB(SSQLToken* pTableName);
|
||||||
static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd);
|
static bool validateTableColumnInfo(tFieldList* pFieldList, SSqlCmd* pCmd);
|
||||||
|
|
||||||
static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSqlCmd* pCmd);
|
static bool validateTagParams(tFieldList* pTagsList, tFieldList* pFieldList, SSqlCmd* pCmd);
|
||||||
|
|
||||||
static int32_t setObjFullName(char* fullName, char* account, SSQLToken* pDB, SSQLToken* tableName, int32_t* len);
|
static int32_t setObjFullName(char* fullName, char* account, SSQLToken* pDB, SSQLToken* tableName, int32_t* len);
|
||||||
|
@ -68,20 +66,18 @@ static void getColumnName(tSQLExprItem* pItem, char* resultFieldName, int32_t nL
|
||||||
static void getRevisedName(char* resultFieldName, int32_t functionId, int32_t maxLen, char* columnName);
|
static void getRevisedName(char* resultFieldName, int32_t functionId, int32_t maxLen, char* columnName);
|
||||||
|
|
||||||
static int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem);
|
static int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem);
|
||||||
|
|
||||||
static int32_t insertResultField(SSqlCmd* pCmd, int32_t fieldIDInResult, SColumnList* pIdList, int16_t bytes,
|
static int32_t insertResultField(SSqlCmd* pCmd, int32_t fieldIDInResult, SColumnList* pIdList, int16_t bytes,
|
||||||
int8_t type, char* fieldName);
|
int8_t type, char* fieldName);
|
||||||
static int32_t changeFunctionID(int32_t optr, int16_t* functionId);
|
static int32_t changeFunctionID(int32_t optr, int16_t* functionId);
|
||||||
|
static int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric);
|
||||||
|
|
||||||
static void setErrMsg(SSqlCmd* pCmd, const char* pzErrMsg);
|
static void setErrMsg(SSqlCmd* pCmd, const char* pzErrMsg);
|
||||||
|
|
||||||
static int32_t parseSelectClause(SSqlCmd* pCmd, tSQLExprList* pSelection, bool isMetric);
|
|
||||||
|
|
||||||
static bool validateIpAddress(char* ip);
|
static bool validateIpAddress(char* ip);
|
||||||
static bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd);
|
static bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd);
|
||||||
static bool functionCompatibleCheck(SSqlCmd* pCmd);
|
static bool functionCompatibleCheck(SSqlCmd* pCmd);
|
||||||
|
static void setColumnOffsetValueInResultset(SSqlCmd* pCmd);
|
||||||
|
|
||||||
static void setColumnOffsetValueInResultset(SSqlCmd* pCmd);
|
|
||||||
static int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList);
|
static int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList);
|
||||||
|
|
||||||
static int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql);
|
static int32_t parseIntervalClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql);
|
||||||
|
@ -94,7 +90,6 @@ static int32_t parseFillClause(SSqlCmd* pCmd, SQuerySQL* pQuerySQL);
|
||||||
static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema, int32_t numOfCols);
|
static int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema, int32_t numOfCols);
|
||||||
|
|
||||||
static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd);
|
static int32_t tsRewriteFieldNameIfNecessary(SSqlCmd* pCmd);
|
||||||
static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
|
|
||||||
static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
||||||
static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd);
|
static int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd);
|
||||||
static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString);
|
static int32_t buildArithmeticExprString(tSQLExpr* pExpr, char** exprString);
|
||||||
|
@ -105,19 +100,22 @@ static int32_t validateLocalConfig(tDCLSQL* pOptions);
|
||||||
static int32_t validateColumnName(char* name);
|
static int32_t validateColumnName(char* name);
|
||||||
static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
static int32_t setKillInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
|
||||||
|
|
||||||
static bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd);
|
static bool validateOneTags(SSqlCmd* pCmd, TAOS_FIELD* pTagField);
|
||||||
static void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex);
|
static bool hasTimestampForPointInterpQuery(SSqlCmd* pCmd);
|
||||||
static int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql);
|
static void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex);
|
||||||
|
|
||||||
static int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd);
|
static int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql);
|
||||||
|
static int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql);
|
||||||
static int32_t getColumnIndexByNameEx(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
|
static int32_t getColumnIndexByNameEx(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
|
||||||
static int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
|
static int32_t getTableIndexByName(SSQLToken* pToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
|
||||||
static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
|
static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
|
||||||
|
|
||||||
|
static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
|
||||||
|
static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql);
|
||||||
|
static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd);
|
||||||
|
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate);
|
||||||
|
|
||||||
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
|
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
|
||||||
static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
|
|
||||||
static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql);
|
|
||||||
static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd);
|
|
||||||
|
|
||||||
static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) {
|
static int32_t tscQueryOnlyMetricTags(SSqlCmd* pCmd, bool* queryOnMetricTags) {
|
||||||
assert(QUERY_IS_STABLE_QUERY(pCmd->type));
|
assert(QUERY_IS_STABLE_QUERY(pCmd->type));
|
||||||
|
@ -321,7 +319,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parseCreateDBOptions(pCreateDB, pCmd) != TSDB_CODE_SUCCESS) {
|
if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -906,7 +904,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
*/
|
*/
|
||||||
if (pQuerySql->from == NULL) {
|
if (pQuerySql->from == NULL) {
|
||||||
assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL &&
|
assert(pQuerySql->fillType == NULL && pQuerySql->pGroupby == NULL && pQuerySql->pWhere == NULL &&
|
||||||
pQuerySql->pSortOrder == NULL);
|
pQuerySql->pSortOrder == NULL);
|
||||||
return doLocalQueryProcess(pQuerySql, pCmd);
|
return doLocalQueryProcess(pQuerySql, pCmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1511,7 +1509,7 @@ bool validateOneColumn(SSqlCmd* pCmd, TAOS_FIELD* pColField) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is contained in pFieldList or not */
|
/* is contained in pFieldList or not */
|
||||||
static bool has(tFieldList* pFieldList, int32_t startIdx, char* name) {
|
static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name) {
|
||||||
for (int32_t j = startIdx; j < pFieldList->nField; ++j) {
|
for (int32_t j = startIdx; j < pFieldList->nField; ++j) {
|
||||||
if (strncasecmp(name, pFieldList->p[j].name, TSDB_COL_NAME_LEN) == 0) return true;
|
if (strncasecmp(name, pFieldList->p[j].name, TSDB_COL_NAME_LEN) == 0) return true;
|
||||||
}
|
}
|
||||||
|
@ -4958,7 +4956,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
|
||||||
// projection query on primary timestamp, the selectivity function needs to be present.
|
// projection query on primary timestamp, the selectivity function needs to be present.
|
||||||
if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
if (pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||||
bool hasSelectivity = false;
|
bool hasSelectivity = false;
|
||||||
for(int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
for (int32_t j = 0; j < pCmd->fieldsInfo.numOfOutputCols; ++j) {
|
||||||
SSqlExpr* pEx = tscSqlExprGet(pCmd, j);
|
SSqlExpr* pEx = tscSqlExprGet(pCmd, j);
|
||||||
if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) {
|
if ((aAggs[pEx->functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == TSDB_FUNCSTATE_SELECTIVITY) {
|
||||||
hasSelectivity = true;
|
hasSelectivity = true;
|
||||||
|
@ -4972,7 +4970,7 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pExpr->functionId == TSDB_FUNC_PRJ || pExpr->functionId == TSDB_FUNC_DIFF ||
|
if (pExpr->functionId == TSDB_FUNC_PRJ || pExpr->functionId == TSDB_FUNC_DIFF ||
|
||||||
pExpr->functionId == TSDB_FUNC_ARITHM) {
|
pExpr->functionId == TSDB_FUNC_ARITHM) {
|
||||||
isProjectionFunction = true;
|
isProjectionFunction = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4985,8 +4983,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct SDNodeDynConfOption {
|
typedef struct SDNodeDynConfOption {
|
||||||
char* name; // command name
|
char* name; // command name
|
||||||
int32_t len; // name string length
|
int32_t len; // name string length
|
||||||
} SDNodeDynConfOption;
|
} SDNodeDynConfOption;
|
||||||
|
|
||||||
int32_t validateDNodeConfig(tDCLSQL* pOptions) {
|
int32_t validateDNodeConfig(tDCLSQL* pOptions) {
|
||||||
|
@ -5045,10 +5043,8 @@ int32_t validateLocalConfig(tDCLSQL* pOptions) {
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {
|
SDNodeDynConfOption LOCAL_DYNAMIC_CFG_OPTIONS[6] = {{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12},
|
||||||
{"resetLog", 8}, {"rpcDebugFlag", 12}, {"tmrDebugFlag", 12},
|
{"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}};
|
||||||
{"cDebugFlag", 10}, {"uDebugFlag", 10}, {"debugFlag", 9}
|
|
||||||
};
|
|
||||||
|
|
||||||
SSQLToken* pOptionToken = &pOptions->a[0];
|
SSQLToken* pOptionToken = &pOptions->a[0];
|
||||||
|
|
||||||
|
@ -5145,7 +5141,7 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
if (UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
|
||||||
bool queryOnTags = false;
|
bool queryOnTags = false;
|
||||||
if (tscQueryOnlyMetricTags(pCmd, &queryOnTags) != TSDB_CODE_SUCCESS) {
|
if (tscQueryOnlyMetricTags(pCmd, &queryOnTags) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
@ -5203,57 +5199,46 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
||||||
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
|
const char* msg = "invalid number of options";
|
||||||
|
|
||||||
pMsg->daysToKeep = htonl(-1);
|
pMsg->daysToKeep = htonl(-1);
|
||||||
pMsg->daysToKeep1 = htonl(-1);
|
pMsg->daysToKeep1 = htonl(-1);
|
||||||
pMsg->daysToKeep2 = htonl(-1);
|
pMsg->daysToKeep2 = htonl(-1);
|
||||||
|
|
||||||
pMsg->blocksPerMeter = (pCreateDb->numOfBlocksPerTable == 0) ? htons(-1) : htons(pCreateDb->numOfBlocksPerTable);
|
tVariantList* pKeep = pCreateDb->keep;
|
||||||
pMsg->compression = (pCreateDb->compressionLevel == 0) ? -1 : pCreateDb->compressionLevel;
|
if (pKeep != NULL) {
|
||||||
|
switch (pKeep->nExpr) {
|
||||||
pMsg->commitLog = (pCreateDb->commitLog == 0) ? -1 : pCreateDb->commitLog;
|
|
||||||
pMsg->commitTime = (pCreateDb->commitTime == 0) ? htonl(-1) : htonl(pCreateDb->commitTime);
|
|
||||||
pMsg->maxSessions = (pCreateDb->tablesPerVnode == 0) ? htonl(-1) : htonl(pCreateDb->tablesPerVnode);
|
|
||||||
pMsg->cacheNumOfBlocks.fraction = (pCreateDb->numOfAvgCacheBlocks == 0) ? -1 : pCreateDb->numOfAvgCacheBlocks;
|
|
||||||
pMsg->cacheBlockSize = (pCreateDb->cacheBlockSize == 0) ? htonl(-1) : htonl(pCreateDb->cacheBlockSize);
|
|
||||||
pMsg->rowsInFileBlock = (pCreateDb->rowPerFileBlock == 0) ? htonl(-1) : htonl(pCreateDb->rowPerFileBlock);
|
|
||||||
pMsg->daysPerFile = (pCreateDb->daysPerFile == 0) ? htonl(-1) : htonl(pCreateDb->daysPerFile);
|
|
||||||
pMsg->replications = (pCreateDb->replica == 0) ? -1 : pCreateDb->replica;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd) {
|
|
||||||
const char* msg0 = "invalid number of options";
|
|
||||||
const char* msg1 = "invalid time precision";
|
|
||||||
|
|
||||||
SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead));
|
|
||||||
setCreateDBOption(pMsg, pCreateDbSql);
|
|
||||||
|
|
||||||
if (pCreateDbSql->keep != NULL) {
|
|
||||||
switch (pCreateDbSql->keep->nExpr) {
|
|
||||||
case 1:
|
case 1:
|
||||||
pMsg->daysToKeep = htonl(pCreateDbSql->keep->a[0].pVar.i64Key);
|
pMsg->daysToKeep = htonl(pKeep->a[0].pVar.i64Key);
|
||||||
break;
|
break;
|
||||||
case 2: {
|
case 2: {
|
||||||
pMsg->daysToKeep = htonl(pCreateDbSql->keep->a[0].pVar.i64Key);
|
pMsg->daysToKeep = htonl(pKeep->a[0].pVar.i64Key);
|
||||||
pMsg->daysToKeep1 = htonl(pCreateDbSql->keep->a[1].pVar.i64Key);
|
pMsg->daysToKeep1 = htonl(pKeep->a[1].pVar.i64Key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
pMsg->daysToKeep = htonl(pCreateDbSql->keep->a[0].pVar.i64Key);
|
pMsg->daysToKeep = htonl(pKeep->a[0].pVar.i64Key);
|
||||||
pMsg->daysToKeep1 = htonl(pCreateDbSql->keep->a[1].pVar.i64Key);
|
pMsg->daysToKeep1 = htonl(pKeep->a[1].pVar.i64Key);
|
||||||
pMsg->daysToKeep2 = htonl(pCreateDbSql->keep->a[2].pVar.i64Key);
|
pMsg->daysToKeep2 = htonl(pKeep->a[2].pVar.i64Key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
setErrMsg(pCmd, msg0);
|
setErrMsg(pCmd, msg);
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SSQLToken* pToken = &pCreateDbSql->precision;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t setTimePrecisionOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDbInfo) {
|
||||||
|
const char* msg = "invalid time precision";
|
||||||
|
|
||||||
|
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
|
||||||
|
|
||||||
|
SSQLToken* pToken = &pCreateDbInfo->precision;
|
||||||
if (pToken->n > 0) {
|
if (pToken->n > 0) {
|
||||||
pToken->n = strdequote(pToken->z);
|
pToken->n = strdequote(pToken->z);
|
||||||
|
|
||||||
|
@ -5262,10 +5247,10 @@ int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd) {
|
||||||
// time precision for this db: million second
|
// time precision for this db: million second
|
||||||
pMsg->precision = TSDB_TIME_PRECISION_MILLI;
|
pMsg->precision = TSDB_TIME_PRECISION_MILLI;
|
||||||
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 &&
|
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 &&
|
||||||
strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) {
|
strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) {
|
||||||
pMsg->precision = TSDB_TIME_PRECISION_MICRO;
|
pMsg->precision = TSDB_TIME_PRECISION_MICRO;
|
||||||
} else {
|
} else {
|
||||||
setErrMsg(pCmd, msg1);
|
setErrMsg(pCmd, msg);
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5273,6 +5258,39 @@ int32_t parseCreateDBOptions(SCreateDBInfo* pCreateDbSql, SSqlCmd* pCmd) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
|
||||||
|
pMsg->blocksPerMeter = htons(pCreateDb->numOfBlocksPerTable);
|
||||||
|
pMsg->compression = pCreateDb->compressionLevel;
|
||||||
|
|
||||||
|
pMsg->commitLog = (char) pCreateDb->commitLog;
|
||||||
|
pMsg->commitTime = htonl(pCreateDb->commitTime);
|
||||||
|
pMsg->maxSessions = htonl(pCreateDb->tablesPerVnode);
|
||||||
|
pMsg->cacheNumOfBlocks.fraction = pCreateDb->numOfAvgCacheBlocks;
|
||||||
|
pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize);
|
||||||
|
pMsg->rowsInFileBlock = htonl(pCreateDb->rowPerFileBlock);
|
||||||
|
pMsg->daysPerFile = htonl(pCreateDb->daysPerFile);
|
||||||
|
pMsg->replications = pCreateDb->replica;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
|
||||||
|
SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead));
|
||||||
|
setCreateDBOption(pMsg, pCreateDbSql);
|
||||||
|
|
||||||
|
if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setTimePrecisionOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) {
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex) {
|
void tscAddTimestampColumn(SSqlCmd* pCmd, int16_t functionId, int16_t tableIndex) {
|
||||||
// the first column not timestamp column, add it
|
// the first column not timestamp column, add it
|
||||||
SSqlExpr* pExpr = NULL;
|
SSqlExpr* pExpr = NULL;
|
||||||
|
@ -5381,9 +5399,8 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
|
||||||
|
|
||||||
static void doUpdateSqlFunctionForColPrj(SSqlCmd* pCmd) {
|
static void doUpdateSqlFunctionForColPrj(SSqlCmd* pCmd) {
|
||||||
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
|
||||||
SSqlExpr *pExpr = tscSqlExprGet(pCmd, i);
|
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
|
||||||
if (pExpr->functionId == TSDB_FUNC_PRJ) {
|
if (pExpr->functionId == TSDB_FUNC_PRJ) {
|
||||||
|
|
||||||
bool qualifiedCol = false;
|
bool qualifiedCol = false;
|
||||||
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) {
|
for (int32_t j = 0; j < pCmd->groupbyExpr.numOfGroupCols; ++j) {
|
||||||
if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) {
|
if (pExpr->colInfo.colId == pCmd->groupbyExpr.columnInfo[j].colId) {
|
||||||
|
@ -5720,14 +5737,16 @@ int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) {
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDNodeDynConfOption functionsInfo[5] = {
|
SDNodeDynConfOption functionsInfo[5] = {{"database()", 10},
|
||||||
{"database()", 10}, {"server_version()", 16}, {"server_status()", 15}, {"client_version()", 16}, {"current_user()", 14}
|
{"server_version()", 16},
|
||||||
};
|
{"server_status()", 15},
|
||||||
|
{"client_version()", 16},
|
||||||
|
{"current_user()", 14}};
|
||||||
|
|
||||||
int32_t index = -1;
|
int32_t index = -1;
|
||||||
for(int32_t i = 0; i < tListLen(functionsInfo); ++i) {
|
for (int32_t i = 0; i < tListLen(functionsInfo); ++i) {
|
||||||
if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 &&
|
if (strncasecmp(functionsInfo[i].name, pExpr->operand.z, functionsInfo[i].len) == 0 &&
|
||||||
functionsInfo[i].len == pExpr->operand.n) {
|
functionsInfo[i].len == pExpr->operand.n) {
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -5740,15 +5759,110 @@ int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) {
|
||||||
strncpy(pExpr1->aliasName, functionsInfo[index].name, tListLen(pExpr1->aliasName));
|
strncpy(pExpr1->aliasName, functionsInfo[index].name, tListLen(pExpr1->aliasName));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(index) {
|
switch (index) {
|
||||||
case 0: pCmd->command = TSDB_SQL_CURRENT_DB;return TSDB_CODE_SUCCESS;
|
case 0:
|
||||||
case 1: pCmd->command = TSDB_SQL_SERV_VERSION;return TSDB_CODE_SUCCESS;
|
pCmd->command = TSDB_SQL_CURRENT_DB;
|
||||||
case 2: pCmd->command = TSDB_SQL_SERV_STATUS;return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
case 3: pCmd->command = TSDB_SQL_CLI_VERSION;return TSDB_CODE_SUCCESS;
|
case 1:
|
||||||
case 4: pCmd->command = TSDB_SQL_CURRENT_USER;return TSDB_CODE_SUCCESS;
|
pCmd->command = TSDB_SQL_SERV_VERSION;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case 2:
|
||||||
|
pCmd->command = TSDB_SQL_SERV_STATUS;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case 3:
|
||||||
|
pCmd->command = TSDB_SQL_CLI_VERSION;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
case 4:
|
||||||
|
pCmd->command = TSDB_SQL_CURRENT_USER;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
default: {
|
default: {
|
||||||
setErrMsg(pCmd, msg3);
|
setErrMsg(pCmd, msg3);
|
||||||
return TSDB_CODE_INVALID_SQL;
|
return TSDB_CODE_INVALID_SQL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// can only perform the parameters based on the macro definitation
|
||||||
|
int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate) {
|
||||||
|
char msg[512] = {0};
|
||||||
|
|
||||||
|
if (pCreate->commitLog != -1 && (pCreate->commitLog < 0 || pCreate->commitLog > 1)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option commitLog: %d, only 0 or 1 allowed", pCreate->commitLog);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->replications != -1 &&
|
||||||
|
(pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM,
|
||||||
|
TSDB_REPLICA_MAX_NUM);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t val = htonl(pCreate->daysPerFile);
|
||||||
|
if (val != -1 && (val < TSDB_FILE_MIN_PARTITION_RANGE || val > TSDB_FILE_MAX_PARTITION_RANGE)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val,
|
||||||
|
TSDB_FILE_MIN_PARTITION_RANGE, TSDB_FILE_MAX_PARTITION_RANGE);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = htonl(pCreate->rowsInFileBlock);
|
||||||
|
if (val != -1 && (val < TSDB_MIN_ROWS_IN_FILEBLOCK || val > TSDB_MAX_ROWS_IN_FILEBLOCK)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option rowsInFileBlock: %d valid range: [%d, %d]", val,
|
||||||
|
TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = htonl(pCreate->cacheBlockSize);
|
||||||
|
if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val,
|
||||||
|
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = htonl(pCreate->maxSessions);
|
||||||
|
if (val != -1 && (val < TSDB_MIN_TABLES_PER_VNODE || val > TSDB_MAX_TABLES_PER_VNODE)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option maxSessions: %d valid range: [%d, %d]", val, TSDB_MIN_TABLES_PER_VNODE,
|
||||||
|
TSDB_MAX_TABLES_PER_VNODE);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->precision != -1 &&
|
||||||
|
(pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI,
|
||||||
|
TSDB_TIME_PRECISION_MICRO);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->cacheNumOfBlocks.fraction != -1 && (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS ||
|
||||||
|
pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction,
|
||||||
|
TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = htonl(pCreate->commitTime);
|
||||||
|
if (val != -1 && (val < TSDB_MIN_COMMIT_TIME_INTERVAL || val > TSDB_MAX_COMMIT_TIME_INTERVAL)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val,
|
||||||
|
TSDB_MIN_COMMIT_TIME_INTERVAL, TSDB_MAX_COMMIT_TIME_INTERVAL);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->compression != -1 &&
|
||||||
|
(pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL)) {
|
||||||
|
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL,
|
||||||
|
TSDB_MAX_COMPRESSION_LEVEL);
|
||||||
|
setErrMsg(pCmd, msg);
|
||||||
|
return TSDB_CODE_INVALID_SQL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -14,8 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
#include "taosmsg.h"
|
||||||
#include "tglobalcfg.h"
|
#include "tglobalcfg.h"
|
||||||
#include "tsql.h"
|
#include "tlog.h"
|
||||||
|
#include "tscSQLParser.h"
|
||||||
#include "tstoken.h"
|
#include "tstoken.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
@ -742,3 +744,22 @@ void setCreateAcctSQL(SSqlInfo *pInfo, int32_t type, SSQLToken *pName, SSQLToken
|
||||||
tTokenListAppend(pInfo->pDCLInfo, pPwd);
|
tTokenListAppend(pInfo->pDCLInfo, pPwd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setDefaultCreateDbOption(SCreateDBInfo *pDBInfo) {
|
||||||
|
pDBInfo->numOfBlocksPerTable = -1;
|
||||||
|
pDBInfo->compressionLevel = -1;
|
||||||
|
|
||||||
|
pDBInfo->commitLog = -1;
|
||||||
|
pDBInfo->commitTime = -1;
|
||||||
|
pDBInfo->tablesPerVnode = -1;
|
||||||
|
pDBInfo->numOfAvgCacheBlocks = -1;
|
||||||
|
|
||||||
|
pDBInfo->cacheBlockSize = -1;
|
||||||
|
pDBInfo->rowPerFileBlock = -1;
|
||||||
|
pDBInfo->daysPerFile = -1;
|
||||||
|
|
||||||
|
pDBInfo->replica = -1;
|
||||||
|
pDBInfo->keep = NULL;
|
||||||
|
|
||||||
|
memset(&pDBInfo->precision, 0, sizeof(SSQLToken));
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tlosertree.h"
|
#include "tlosertree.h"
|
||||||
#include "tscSecondaryMerge.h"
|
#include "tscSecondaryMerge.h"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
#include "tnote.h"
|
#include "tnote.h"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "tscSyntaxtreefunction.h"
|
#include "tscSyntaxtreefunction.h"
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "tsql.h"
|
#include "tscSQLParser.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,7 +218,8 @@ comp(Y) ::= COMP INTEGER(X). { Y = X; }
|
||||||
prec(Y) ::= PRECISION STRING(X). { Y = X; }
|
prec(Y) ::= PRECISION STRING(X). { Y = X; }
|
||||||
|
|
||||||
%type db_optr {SCreateDBInfo}
|
%type db_optr {SCreateDBInfo}
|
||||||
db_optr(Y) ::= . {memset(&Y, 0, sizeof(SCreateDBInfo));}
|
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y);}
|
||||||
|
|
||||||
db_optr(Y) ::= db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); }
|
||||||
db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) cache(X). { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); }
|
||||||
db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
|
db_optr(Y) ::= db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
|
||||||
|
@ -233,7 +234,7 @@ db_optr(Y) ::= db_optr(Z) prec(X). { Y = Z; Y.precision = X; }
|
||||||
db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
db_optr(Y) ::= db_optr(Z) keep(X). { Y = Z; Y.keep = X; }
|
||||||
|
|
||||||
%type alter_db_optr {SCreateDBInfo}
|
%type alter_db_optr {SCreateDBInfo}
|
||||||
alter_db_optr(Y) ::= . { memset(&Y, 0, sizeof(SCreateDBInfo));}
|
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y);}
|
||||||
|
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) replica(X). { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
|
||||||
alter_db_optr(Y) ::= alter_db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); }
|
alter_db_optr(Y) ::= alter_db_optr(Z) tables(X). { Y = Z; Y.tablesPerVnode = strtol(X.z, NULL, 10); }
|
||||||
|
|
|
@ -25,7 +25,7 @@ extern "C" {
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tsql.h"
|
#include "ttypes.h"
|
||||||
|
|
||||||
struct tSQLBinaryExpr;
|
struct tSQLBinaryExpr;
|
||||||
struct SSchema;
|
struct SSchema;
|
||||||
|
@ -49,7 +49,7 @@ typedef struct tQueryInfo {
|
||||||
int32_t offset; // offset value in tags
|
int32_t offset; // offset value in tags
|
||||||
int32_t colIdx; // index of column in schema
|
int32_t colIdx; // index of column in schema
|
||||||
uint8_t optr; // expression operator
|
uint8_t optr; // expression operator
|
||||||
SSchema sch; // schema of tags
|
SSchema sch; // schema of tags
|
||||||
tVariant q; // query condition value on the specific schema, filter expression
|
tVariant q; // query condition value on the specific schema, filter expression
|
||||||
__compar_fn_t compare; // filter function
|
__compar_fn_t compare; // filter function
|
||||||
} tQueryInfo;
|
} tQueryInfo;
|
||||||
|
|
|
@ -146,8 +146,8 @@ extern "C" {
|
||||||
#define TSDB_MAX_MPEERS 5
|
#define TSDB_MAX_MPEERS 5
|
||||||
#define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1)
|
#define TSDB_MAX_MGMT_IPS (TSDB_MAX_MPEERS+1)
|
||||||
|
|
||||||
//#define TSDB_REPLICA_MAX_NUM 3
|
|
||||||
#define TSDB_REPLICA_MIN_NUM 1
|
#define TSDB_REPLICA_MIN_NUM 1
|
||||||
|
#define TSDB_REPLICA_MAX_NUM 3
|
||||||
|
|
||||||
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
#define TSDB_TBNAME_COLUMN_INDEX (-1)
|
||||||
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
|
#define TSDB_MULTI_METERMETA_MAX_NUM 100000 // maximum batch size allowed to load metermeta
|
||||||
|
@ -162,9 +162,6 @@ extern "C" {
|
||||||
#define TSDB_MIN_COMPRESSION_LEVEL 0
|
#define TSDB_MIN_COMPRESSION_LEVEL 0
|
||||||
#define TSDB_MAX_COMPRESSION_LEVEL 2
|
#define TSDB_MAX_COMPRESSION_LEVEL 2
|
||||||
|
|
||||||
#define TSDB_MIN_CACHE_BLOCKS_PER_METER 32
|
|
||||||
#define TSDB_MAX_CACHE_BLOCKS_PER_METER 40960
|
|
||||||
|
|
||||||
#define TSDB_MIN_COMMIT_TIME_INTERVAL 30
|
#define TSDB_MIN_COMMIT_TIME_INTERVAL 30
|
||||||
#define TSDB_MAX_COMMIT_TIME_INTERVAL 40960
|
#define TSDB_MAX_COMMIT_TIME_INTERVAL 40960
|
||||||
|
|
||||||
|
@ -177,7 +174,9 @@ extern "C" {
|
||||||
#define TSDB_MIN_CACHE_BLOCKS 100
|
#define TSDB_MIN_CACHE_BLOCKS 100
|
||||||
#define TSDB_MAX_CACHE_BLOCKS 409600
|
#define TSDB_MAX_CACHE_BLOCKS 409600
|
||||||
|
|
||||||
|
#define TSDB_MIN_AVG_BLOCKS 2
|
||||||
#define TSDB_MAX_AVG_BLOCKS 2048
|
#define TSDB_MAX_AVG_BLOCKS 2048
|
||||||
|
#define TSDB_DEFAULT_AVG_BLOCKS 4
|
||||||
|
|
||||||
#define TSDB_MIN_TABLES_PER_VNODE 1
|
#define TSDB_MIN_TABLES_PER_VNODE 1
|
||||||
#define TSDB_MAX_TABLES_PER_VNODE 220000
|
#define TSDB_MAX_TABLES_PER_VNODE 220000
|
||||||
|
@ -204,7 +203,7 @@ extern "C" {
|
||||||
|
|
||||||
#define TSDB_MAX_RPC_THREADS 5
|
#define TSDB_MAX_RPC_THREADS 5
|
||||||
|
|
||||||
#define TSDB_QUERY_TYPE_QUERY 0 // normal query
|
#define TSDB_QUERY_TYPE_QUERY 0 // normal query
|
||||||
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01U // free qhandle at vnode
|
#define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01U // free qhandle at vnode
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -220,6 +219,9 @@ extern "C" {
|
||||||
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40U // select *,columns... query
|
#define TSDB_QUERY_TYPE_PROJECTION_QUERY 0x40U // select *,columns... query
|
||||||
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80U // join sub query at the second stage
|
#define TSDB_QUERY_TYPE_JOIN_SEC_STAGE 0x80U // join sub query at the second stage
|
||||||
|
|
||||||
|
#define TSQL_SO_ASC 1
|
||||||
|
#define TSQL_SO_DESC 0
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,7 +24,6 @@ extern "C" {
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "tsql.h"
|
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
|
|
||||||
#define TSDB_FUNC_INVALID_ID -1
|
#define TSDB_FUNC_INVALID_ID -1
|
||||||
|
|
|
@ -22,6 +22,18 @@ extern "C" {
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define TK_SPACE 200
|
||||||
|
#define TK_COMMENT 201
|
||||||
|
#define TK_ILLEGAL 202
|
||||||
|
#define TK_HEX 203 // hex number 0x123
|
||||||
|
#define TK_OCT 204 // oct number
|
||||||
|
#define TK_BIN 205 // bin format data 0b111
|
||||||
|
#define TK_FILE 206
|
||||||
|
#define TK_QUESTION 207 // denoting the placeholder of "?",when invoking statement bind query
|
||||||
|
|
||||||
|
#define TSQL_TBNAME "TBNAME"
|
||||||
|
#define TSQL_TBNAME_L "tbname"
|
||||||
|
|
||||||
// used to denote the minimum unite in sql parsing
|
// used to denote the minimum unite in sql parsing
|
||||||
typedef struct SSQLToken {
|
typedef struct SSQLToken {
|
||||||
uint32_t n;
|
uint32_t n;
|
||||||
|
@ -29,10 +41,6 @@ typedef struct SSQLToken {
|
||||||
char * z;
|
char * z;
|
||||||
} SSQLToken;
|
} SSQLToken;
|
||||||
|
|
||||||
#if 0
|
|
||||||
char *tscGetToken(char *string, char **token, int *tokenLen);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tokenizer for sql string
|
* tokenizer for sql string
|
||||||
* @param z
|
* @param z
|
||||||
|
|
|
@ -31,6 +31,7 @@ int32_t mgmtFindTagCol(STabObj * pMetric, const char * tagName);
|
||||||
|
|
||||||
int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col);
|
int32_t mgmtGetTagsLength(STabObj* pMetric, int32_t col);
|
||||||
bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
|
bool mgmtCheckIsMonitorDB(char *db, char *monitordb);
|
||||||
|
int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate);
|
||||||
|
|
||||||
int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes);
|
int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes);
|
||||||
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes);
|
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes);
|
||||||
|
|
|
@ -140,90 +140,31 @@ int mgmtCheckDbParams(SCreateDbMsg *pCreate) {
|
||||||
if (pCreate->replications < 0) pCreate->replications = tsReplications; //
|
if (pCreate->replications < 0) pCreate->replications = tsReplications; //
|
||||||
if (pCreate->rowsInFileBlock < 0) pCreate->rowsInFileBlock = tsRowsInFileBlock; //
|
if (pCreate->rowsInFileBlock < 0) pCreate->rowsInFileBlock = tsRowsInFileBlock; //
|
||||||
if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; //
|
if (pCreate->cacheNumOfBlocks.fraction < 0) pCreate->cacheNumOfBlocks.fraction = tsAverageCacheBlocks; //
|
||||||
//-1 for balance
|
|
||||||
|
|
||||||
if (pCreate->replications < 0 || pCreate->replications > TSDB_REPLICA_MAX_NUM) {
|
if (mgmtCheckDBParams(pCreate) != TSDB_CODE_SUCCESS) {
|
||||||
mTrace("invalid db option replications: %d", pCreate->replications);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCreate->commitLog < 0 || pCreate->commitLog > 1) {
|
pCreate->cacheNumOfBlocks.totalBlocks = (int32_t)(pCreate->cacheNumOfBlocks.fraction * pCreate->maxSessions);
|
||||||
mTrace("invalid db option commitLog: %d", pCreate->commitLog);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM) {
|
|
||||||
mTrace("invalid db option replications: %d", pCreate->replications);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) {
|
|
||||||
mTrace("invalid db option daysPerFile: %d valid range: %d--%d", pCreate->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE,
|
|
||||||
TSDB_FILE_MAX_PARTITION_RANGE);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->daysToKeep1 > pCreate->daysToKeep2 || pCreate->daysToKeep2 > pCreate->daysToKeep) {
|
|
||||||
mTrace("invalid db option daystokeep1: %d, daystokeep2: %d, daystokeep: %d", pCreate->daysToKeep1,
|
|
||||||
pCreate->daysToKeep2, pCreate->daysToKeep);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysToKeep1 < pCreate->daysPerFile) {
|
|
||||||
mTrace("invalid db option daystokeep: %d", pCreate->daysToKeep);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (pCreate->rowsInFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCreate->rowsInFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) {
|
|
||||||
mTrace("invalid db option rowsInFileBlock: %d valid range: %d--%d", pCreate->rowsInFileBlock,
|
|
||||||
TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (pCreate->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCreate->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
|
||||||
mTrace("invalid db option cacheBlockSize: %d valid range: %d--%d", pCreate->cacheBlockSize,
|
|
||||||
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (pCreate->maxSessions < TSDB_MIN_TABLES_PER_VNODE || pCreate->maxSessions > TSDB_MAX_TABLES_PER_VNODE) {
|
|
||||||
mTrace("invalid db option maxSessions: %d valid range: %d--%d", pCreate->maxSessions, TSDB_MIN_TABLES_PER_VNODE,
|
|
||||||
TSDB_MAX_TABLES_PER_VNODE);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) {
|
|
||||||
mTrace("invalid db option timePrecision: %d valid value: %d,%d", pCreate->precision, TSDB_TIME_PRECISION_MILLI,
|
|
||||||
TSDB_TIME_PRECISION_MICRO);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->cacheNumOfBlocks.fraction < 0 || pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS) {
|
|
||||||
mTrace("invalid db option ablocks: %d valid value: %d,%d", pCreate->precision, 0, TSDB_MAX_AVG_BLOCKS);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
} else {
|
|
||||||
pCreate->cacheNumOfBlocks.totalBlocks = (int32_t)(pCreate->cacheNumOfBlocks.fraction * pCreate->maxSessions);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pCreate->cacheNumOfBlocks.totalBlocks > TSDB_MAX_CACHE_BLOCKS) {
|
if (pCreate->cacheNumOfBlocks.totalBlocks > TSDB_MAX_CACHE_BLOCKS) {
|
||||||
mTrace("invalid db option cacheNumOfBlocks: %d valid range: %d", pCreate->cacheNumOfBlocks.totalBlocks,
|
mTrace("invalid db option cacheNumOfBlocks: %d valid range: [%d, %d]", pCreate->cacheNumOfBlocks.totalBlocks,
|
||||||
TSDB_MAX_CACHE_BLOCKS);
|
TSDB_MIN_CACHE_BLOCKS, TSDB_MAX_CACHE_BLOCKS);
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCreate->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCreate->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) {
|
// calculate the blocks per table
|
||||||
mTrace("invalid db option commitTime: %d valid range: %d-%d", pCreate->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL,
|
if (pCreate->blocksPerMeter < 0) {
|
||||||
TSDB_MAX_COMMIT_TIME_INTERVAL);
|
pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks / 4;
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
|
||||||
if (pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL) {
|
|
||||||
mTrace("invalid db option compression: %d", pCreate->compression, TSDB_MIN_COMMIT_TIME_INTERVAL,
|
|
||||||
TSDB_MAX_COMMIT_TIME_INTERVAL);
|
|
||||||
return TSDB_CODE_INVALID_OPTION;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCreate->blocksPerMeter < 0) pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks / 4;
|
|
||||||
if (pCreate->blocksPerMeter > pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4) {
|
if (pCreate->blocksPerMeter > pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4) {
|
||||||
pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4;
|
pCreate->blocksPerMeter = pCreate->cacheNumOfBlocks.totalBlocks * 3 / 4;
|
||||||
}
|
}
|
||||||
if (pCreate->blocksPerMeter < 4) pCreate->blocksPerMeter = 4;
|
|
||||||
|
if (pCreate->blocksPerMeter < TSDB_MIN_AVG_BLOCKS) {
|
||||||
|
pCreate->blocksPerMeter = TSDB_MIN_AVG_BLOCKS;
|
||||||
|
}
|
||||||
|
|
||||||
pCreate->maxSessions++;
|
pCreate->maxSessions++;
|
||||||
|
|
||||||
|
|
|
@ -92,3 +92,76 @@ bool mgmtCheckIsMonitorDB(char *db, char *monitordb) {
|
||||||
size_t len = strlen(dbName);
|
size_t len = strlen(dbName);
|
||||||
return (strncasecmp(dbName, monitordb, len) == 0 && len == strlen(monitordb));
|
return (strncasecmp(dbName, monitordb, len) == 0 && len == strlen(monitordb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mgmtCheckDBParams(SCreateDbMsg *pCreate) {
|
||||||
|
if (pCreate->commitLog < 0 || pCreate->commitLog > 1) {
|
||||||
|
mError("invalid db option commitLog: %d, only 0 or 1 allowed", pCreate->commitLog);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM) {
|
||||||
|
mError("invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM,
|
||||||
|
TSDB_REPLICA_MAX_NUM);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->daysPerFile < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysPerFile > TSDB_FILE_MAX_PARTITION_RANGE) {
|
||||||
|
mError("invalid db option daysPerFile: %d valid range: [%d, %d]", pCreate->daysPerFile, TSDB_FILE_MIN_PARTITION_RANGE,
|
||||||
|
TSDB_FILE_MAX_PARTITION_RANGE);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->daysToKeep1 > pCreate->daysToKeep2 || pCreate->daysToKeep2 > pCreate->daysToKeep) {
|
||||||
|
mError("invalid db option daystokeep1: %d, daystokeep2: %d, daystokeep: %d", pCreate->daysToKeep1,
|
||||||
|
pCreate->daysToKeep2, pCreate->daysToKeep);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->daysToKeep1 < TSDB_FILE_MIN_PARTITION_RANGE || pCreate->daysToKeep1 < pCreate->daysPerFile) {
|
||||||
|
mError("invalid db option daystokeep: %d", pCreate->daysToKeep);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->rowsInFileBlock < TSDB_MIN_ROWS_IN_FILEBLOCK || pCreate->rowsInFileBlock > TSDB_MAX_ROWS_IN_FILEBLOCK) {
|
||||||
|
mError("invalid db option rowsInFileBlock: %d valid range: [%d, %d]", pCreate->rowsInFileBlock,
|
||||||
|
TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCreate->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) {
|
||||||
|
mError("invalid db option cacheBlockSize: %d valid range: [%d, %d]", pCreate->cacheBlockSize,
|
||||||
|
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->maxSessions < TSDB_MIN_TABLES_PER_VNODE || pCreate->maxSessions > TSDB_MAX_TABLES_PER_VNODE) {
|
||||||
|
mError("invalid db option maxSessions: %d valid range: [%d, %d]", pCreate->maxSessions, TSDB_MIN_TABLES_PER_VNODE,
|
||||||
|
TSDB_MAX_TABLES_PER_VNODE);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) {
|
||||||
|
mError("invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI,
|
||||||
|
TSDB_TIME_PRECISION_MICRO);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS || pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS) {
|
||||||
|
mError("invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction, 0, TSDB_MAX_AVG_BLOCKS);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->commitTime < TSDB_MIN_COMMIT_TIME_INTERVAL || pCreate->commitTime > TSDB_MAX_COMMIT_TIME_INTERVAL) {
|
||||||
|
mError("invalid db option commitTime: %d valid range: [%d, %d]", pCreate->commitTime, TSDB_MIN_COMMIT_TIME_INTERVAL,
|
||||||
|
TSDB_MAX_COMMIT_TIME_INTERVAL);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL) {
|
||||||
|
mError("invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL,
|
||||||
|
TSDB_MAX_COMPRESSION_LEVEL);
|
||||||
|
return TSDB_CODE_INVALID_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "vnodeQueryImpl.h"
|
#include "vnodeQueryImpl.h"
|
||||||
|
|
||||||
#define ALL_CACHE_BLOCKS_CHECKED(q) \
|
#define ALL_CACHE_BLOCKS_CHECKED(q) \
|
||||||
((q)->slot == (q)->currentSlot && QUERY_IS_ASC_QUERY(q) || (q)->slot == (q)->firstSlot && (!QUERY_IS_ASC_QUERY(q)))
|
(((q)->slot == (q)->currentSlot && QUERY_IS_ASC_QUERY(q)) || ((q)->slot == (q)->firstSlot && (!QUERY_IS_ASC_QUERY(q))))
|
||||||
|
|
||||||
#define FORWARD_CACHE_BLOCK_CHECK_SLOT(slot, step, maxblocks) (slot) = ((slot) + (step) + (maxblocks)) % (maxblocks);
|
#define FORWARD_CACHE_BLOCK_CHECK_SLOT(slot, step, maxblocks) (slot) = ((slot) + (step) + (maxblocks)) % (maxblocks);
|
||||||
|
|
||||||
|
|
|
@ -283,6 +283,7 @@ SSqlFunctionExpr* vnodeCreateSqlFunctionExpr(SQueryMeterMsg* pQueryMsg, int32_t*
|
||||||
int32_t param = pExprs[i].pBase.arg[0].argValue.i64;
|
int32_t param = pExprs[i].pBase.arg[0].argValue.i64;
|
||||||
if (getResultDataInfo(type, bytes, pExprs[i].pBase.functionId, param, &pExprs[i].resType, &pExprs[i].resBytes,
|
if (getResultDataInfo(type, bytes, pExprs[i].pBase.functionId, param, &pExprs[i].resType, &pExprs[i].resBytes,
|
||||||
&pExprs[i].interResBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) {
|
&pExprs[i].interResBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) {
|
||||||
|
*code = TSDB_CODE_INVALID_QUERY_MSG;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -626,16 +627,16 @@ void vnodeUpdateQueryColumnIndex(SQuery* pQuery, SMeterObj* pMeterObj) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int32_t i = 0; i < pQuery->numOfOutputCols; ++i) {
|
for(int32_t k = 0; k < pQuery->numOfOutputCols; ++k) {
|
||||||
SSqlFuncExprMsg* pSqlExprMsg = &pQuery->pSelectExpr[i].pBase;
|
SSqlFuncExprMsg* pSqlExprMsg = &pQuery->pSelectExpr[k].pBase;
|
||||||
if (pSqlExprMsg->functionId == TSDB_FUNC_ARITHM || pSqlExprMsg->colInfo.flag == TSDB_COL_TAG) {
|
if (pSqlExprMsg->functionId == TSDB_FUNC_ARITHM || pSqlExprMsg->colInfo.flag == TSDB_COL_TAG) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
SColIndexEx* pColIndexEx = &pSqlExprMsg->colInfo;
|
SColIndexEx* pColIndexEx = &pSqlExprMsg->colInfo;
|
||||||
for(int32_t j = 0; j < pQuery->numOfCols; ++j) {
|
for(int32_t f = 0; f < pQuery->numOfCols; ++f) {
|
||||||
if (pColIndexEx->colId == pQuery->colList[j].data.colId) {
|
if (pColIndexEx->colId == pQuery->colList[f].data.colId) {
|
||||||
pColIndexEx->colIdx = pQuery->colList[j].colIdx;
|
pColIndexEx->colIdx = pQuery->colList[f].colIdx;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "textbuffer.h"
|
#include "textbuffer.h"
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "tsql.h"
|
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
|
|
|
@ -84,7 +84,7 @@ short tsCheckHeaderFile = 0;
|
||||||
|
|
||||||
int tsSessionsPerVnode = 1000;
|
int tsSessionsPerVnode = 1000;
|
||||||
int tsCacheBlockSize = 16384; // 256 columns
|
int tsCacheBlockSize = 16384; // 256 columns
|
||||||
int tsAverageCacheBlocks = 4;
|
int tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS;
|
||||||
|
|
||||||
int tsRowsInFileBlock = 4096;
|
int tsRowsInFileBlock = 4096;
|
||||||
float tsFileBlockMinPercent = 0.05;
|
float tsFileBlockMinPercent = 0.05;
|
||||||
|
@ -92,10 +92,10 @@ float tsFileBlockMinPercent = 0.05;
|
||||||
short tsNumOfBlocksPerMeter = 100;
|
short tsNumOfBlocksPerMeter = 100;
|
||||||
short tsCommitTime = 3600; // seconds
|
short tsCommitTime = 3600; // seconds
|
||||||
short tsCommitLog = 1;
|
short tsCommitLog = 1;
|
||||||
short tsCompression = 2;
|
short tsCompression = TSDB_MAX_COMPRESSION_LEVEL;
|
||||||
short tsDaysPerFile = 10;
|
short tsDaysPerFile = 10;
|
||||||
int tsDaysToKeep = 3650;
|
int tsDaysToKeep = 3650;
|
||||||
int tsReplications = 1;
|
int tsReplications = TSDB_REPLICA_MIN_NUM;
|
||||||
|
|
||||||
int tsNumOfMPeers = 3;
|
int tsNumOfMPeers = 3;
|
||||||
int tsMaxShellConns = 2000;
|
int tsMaxShellConns = 2000;
|
||||||
|
@ -522,7 +522,7 @@ static void doInitGlobalConfig() {
|
||||||
0, 1.0, 0, TSDB_CFG_UTYPE_NONE);
|
0, 1.0, 0, TSDB_CFG_UTYPE_NONE);
|
||||||
tsInitConfigOption(cfg++, "ablocks", &tsAverageCacheBlocks, TSDB_CFG_VTYPE_INT,
|
tsInitConfigOption(cfg++, "ablocks", &tsAverageCacheBlocks, TSDB_CFG_VTYPE_INT,
|
||||||
TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW,
|
TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW,
|
||||||
2, 128, 0, TSDB_CFG_UTYPE_NONE);
|
TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS, 0, TSDB_CFG_UTYPE_NONE);
|
||||||
tsInitConfigOption(cfg++, "tblocks", &tsNumOfBlocksPerMeter, TSDB_CFG_VTYPE_SHORT,
|
tsInitConfigOption(cfg++, "tblocks", &tsNumOfBlocksPerMeter, TSDB_CFG_VTYPE_SHORT,
|
||||||
TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW,
|
TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW,
|
||||||
32, 4096, 0, TSDB_CFG_UTYPE_NONE);
|
32, 4096, 0, TSDB_CFG_UTYPE_NONE);
|
||||||
|
|
|
@ -1,142 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can use, redistribute, and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License, version 3
|
|
||||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "shash.h"
|
|
||||||
#include "tstoken.h"
|
|
||||||
void shiftStr(char *dst, char *src);
|
|
||||||
|
|
||||||
static char operator[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '$', '%', '&', 0, '(', ')', '*', '+',
|
|
||||||
0, '-', 0, '/', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '<', '=', '>', 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, '[', 0, ']', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0, 0};
|
|
||||||
|
|
||||||
static char delimiter[] = {
|
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
||||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ',', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ';', 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool isCharInDelimiter(char c, char *delimiter) {
|
|
||||||
for (int i = 0; i < strlen(delimiter); i++) {
|
|
||||||
if (delimiter[i] == c) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *tscGetTokenDelimiter(char *string, char **token, int *tokenLen, char *delimiters) {
|
|
||||||
while (*string != 0) {
|
|
||||||
if (isCharInDelimiter(*string, delimiters)) {
|
|
||||||
++string;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*token = string;
|
|
||||||
|
|
||||||
char *str = string;
|
|
||||||
*tokenLen = 0;
|
|
||||||
while (*str != 0) {
|
|
||||||
if (!isCharInDelimiter(*str, delimiters)) {
|
|
||||||
*tokenLen = *tokenLen + 1;
|
|
||||||
str++;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *tscGetToken(char *string, char **token, int *tokenLen) {
|
|
||||||
char quote = 0;
|
|
||||||
|
|
||||||
while (*string != 0) {
|
|
||||||
if (delimiter[*string]) {
|
|
||||||
++string;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char quotaChar = 0;
|
|
||||||
if (*string == '\'' || *string == '\"') {
|
|
||||||
quote = 1;
|
|
||||||
quotaChar = *string;
|
|
||||||
string++;
|
|
||||||
}
|
|
||||||
|
|
||||||
*token = string;
|
|
||||||
/* not in string, return token */
|
|
||||||
if (*string > 0 && operator[*string] && quote == 0) {
|
|
||||||
string++;
|
|
||||||
/* handle the case: insert into tabx using stable1 tags(-1)/tags(+1)
|
|
||||||
* values(....) */
|
|
||||||
if (operator[*string] &&(*string != '(' && *string != ')' && *string != '-' && *string != '+'))
|
|
||||||
*tokenLen = 2;
|
|
||||||
else
|
|
||||||
*tokenLen = 1;
|
|
||||||
return *token + *tokenLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (*string != 0) {
|
|
||||||
if (quote) {
|
|
||||||
// handle escape situation: '\"', the " should not be eliminated
|
|
||||||
if (*string == quotaChar) {
|
|
||||||
if (*(string - 1) != '\\') {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
shiftStr(string - 1, string);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
++string;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (delimiter[*string]) break;
|
|
||||||
|
|
||||||
if (operator[*string]) break;
|
|
||||||
|
|
||||||
++string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
*tokenLen = (int)(string - *token);
|
|
||||||
|
|
||||||
if (quotaChar != 0 && *string != 0 && *(string + 1) != 0) {
|
|
||||||
return string + 1;
|
|
||||||
} else {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void shiftStr(char *dst, char *src) {
|
|
||||||
int32_t i = 0;
|
|
||||||
do {
|
|
||||||
dst[i] = src[i];
|
|
||||||
i++;
|
|
||||||
} while (delimiter[src[i]] == 0);
|
|
||||||
|
|
||||||
src[i - 1] = ' ';
|
|
||||||
}
|
|
|
@ -13,14 +13,12 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "shash.h"
|
#include "shash.h"
|
||||||
#include "tsql.h"
|
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
#include "tsqldef.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
#include "ttypes.h"
|
||||||
|
|
||||||
// All the keywords of the SQL language are stored in a hash table
|
// All the keywords of the SQL language are stored in a hash table
|
||||||
typedef struct SKeyword {
|
typedef struct SKeyword {
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tsdb.h"
|
#include "tsdb.h"
|
||||||
#include "tsql.h"
|
|
||||||
#include "tsqldef.h"
|
#include "tsqldef.h"
|
||||||
#include "ttypes.h"
|
#include "ttypes.h"
|
||||||
#include "tutil.h"
|
#include "tutil.h"
|
||||||
|
@ -67,6 +66,8 @@ bool isValidDataType(int32_t type, int32_t length) {
|
||||||
void tVariantCreate(tVariant *pVar, SSQLToken *token) { tVariantCreateFromString(pVar, token->z, token->n, token->type); }
|
void tVariantCreate(tVariant *pVar, SSQLToken *token) { tVariantCreateFromString(pVar, token->z, token->n, token->type); }
|
||||||
|
|
||||||
void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type) {
|
void tVariantCreateFromString(tVariant *pVar, char *pz, uint32_t len, uint32_t type) {
|
||||||
|
memset(pVar, 0, sizeof(tVariant));
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TSDB_DATA_TYPE_BOOL: {
|
case TSDB_DATA_TYPE_BOOL: {
|
||||||
int32_t k = strncasecmp(pz, "true", 4);
|
int32_t k = strncasecmp(pz, "true", 4);
|
||||||
|
|
Loading…
Reference in New Issue