提交 37ff331d 编写于 作者: sangshuduo's avatar sangshuduo

Merge branch 'master' into hotfix/sangshuduo/TD-5136-taosdemo-rework-for-master

...@@ -50,6 +50,12 @@ void tscUnlockByThread(int64_t *lockedBy); ...@@ -50,6 +50,12 @@ void tscUnlockByThread(int64_t *lockedBy);
int tsInsertInitialCheck(SSqlObj *pSql); int tsInsertInitialCheck(SSqlObj *pSql);
void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs);
void tscFreeRetrieveSup(SSqlObj *pSql);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -123,17 +123,15 @@ typedef struct { ...@@ -123,17 +123,15 @@ typedef struct {
int32_t kvLen; // len of SKVRow int32_t kvLen; // len of SKVRow
} SMemRowInfo; } SMemRowInfo;
typedef struct { typedef struct {
uint8_t memRowType; uint8_t memRowType; // default is 0, that is SDataRow
uint8_t compareStat; // 0 unknown, 1 need compare, 2 no need uint8_t compareStat; // 0 no need, 1 need compare
TDRowTLenT dataRowInitLen;
TDRowTLenT kvRowInitLen; TDRowTLenT kvRowInitLen;
SMemRowInfo *rowInfo; SMemRowInfo *rowInfo;
} SMemRowBuilder; } SMemRowBuilder;
typedef enum { typedef enum {
ROW_COMPARE_UNKNOWN = 0, ROW_COMPARE_NO_NEED = 0,
ROW_COMPARE_NEED = 1, ROW_COMPARE_NEED = 1,
ROW_COMPARE_NO_NEED = 2,
} ERowCompareStat; } ERowCompareStat;
int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int16_t timePrec); int tsParseTime(SStrToken *pToken, int64_t *time, char **next, char *error, int16_t timePrec);
......
...@@ -51,20 +51,18 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint3 ...@@ -51,20 +51,18 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint3
} }
} }
// default compareStat is ROW_COMPARE_NO_NEED
if (nBoundCols == 0) { // file input if (nBoundCols == 0) { // file input
pBuilder->memRowType = SMEM_ROW_DATA; pBuilder->memRowType = SMEM_ROW_DATA;
pBuilder->compareStat = ROW_COMPARE_NO_NEED;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
float boundRatio = ((float)nBoundCols / (float)nCols); float boundRatio = ((float)nBoundCols / (float)nCols);
if (boundRatio < KVRatioKV) { if (boundRatio < KVRatioKV) {
pBuilder->memRowType = SMEM_ROW_KV; pBuilder->memRowType = SMEM_ROW_KV;
pBuilder->compareStat = ROW_COMPARE_NO_NEED;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (boundRatio > KVRatioData) { } else if (boundRatio > KVRatioData) {
pBuilder->memRowType = SMEM_ROW_DATA; pBuilder->memRowType = SMEM_ROW_DATA;
pBuilder->compareStat = ROW_COMPARE_NO_NEED;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
pBuilder->compareStat = ROW_COMPARE_NEED; pBuilder->compareStat = ROW_COMPARE_NEED;
...@@ -76,7 +74,6 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint3 ...@@ -76,7 +74,6 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint3
} }
} }
pBuilder->dataRowInitLen = TD_MEM_ROW_DATA_HEAD_SIZE + allNullLen;
pBuilder->kvRowInitLen = TD_MEM_ROW_KV_HEAD_SIZE + nBoundCols * sizeof(SColIdx); pBuilder->kvRowInitLen = TD_MEM_ROW_KV_HEAD_SIZE + nBoundCols * sizeof(SColIdx);
if (nRows > 0) { if (nRows > 0) {
...@@ -86,7 +83,7 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint3 ...@@ -86,7 +83,7 @@ int initMemRowBuilder(SMemRowBuilder *pBuilder, uint32_t nRows, uint3
} }
for (int i = 0; i < nRows; ++i) { for (int i = 0; i < nRows; ++i) {
(pBuilder->rowInfo + i)->dataLen = pBuilder->dataRowInitLen; (pBuilder->rowInfo + i)->dataLen = TD_MEM_ROW_DATA_HEAD_SIZE + allNullLen;
(pBuilder->rowInfo + i)->kvLen = pBuilder->kvRowInitLen; (pBuilder->rowInfo + i)->kvLen = pBuilder->kvRowInitLen;
} }
} }
...@@ -460,7 +457,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i ...@@ -460,7 +457,7 @@ int tsParseOneRow(char **str, STableDataBlocks *pDataBlocks, int16_t timePrec, i
STableMeta * pTableMeta = pDataBlocks->pTableMeta; STableMeta * pTableMeta = pDataBlocks->pTableMeta;
SSchema * schema = tscGetTableSchema(pTableMeta); SSchema * schema = tscGetTableSchema(pTableMeta);
SMemRowBuilder * pBuilder = &pDataBlocks->rowBuilder; SMemRowBuilder * pBuilder = &pDataBlocks->rowBuilder;
int32_t dataLen = pBuilder->dataRowInitLen; int32_t dataLen = spd->allNullLen + TD_MEM_ROW_DATA_HEAD_SIZE;
int32_t kvLen = pBuilder->kvRowInitLen; int32_t kvLen = pBuilder->kvRowInitLen;
bool isParseBindParam = false; bool isParseBindParam = false;
...@@ -809,13 +806,12 @@ int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlk ...@@ -809,13 +806,12 @@ int tscSortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlk
// allocate memory // allocate memory
size_t nAlloc = nRows * sizeof(SBlockKeyTuple); size_t nAlloc = nRows * sizeof(SBlockKeyTuple);
if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) { if (pBlkKeyInfo->pKeyTuple == NULL || pBlkKeyInfo->maxBytesAlloc < nAlloc) {
size_t nRealAlloc = nAlloc + 10 * sizeof(SBlockKeyTuple); char *tmp = trealloc(pBlkKeyInfo->pKeyTuple, nAlloc);
char * tmp = trealloc(pBlkKeyInfo->pKeyTuple, nRealAlloc);
if (tmp == NULL) { if (tmp == NULL) {
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple *)tmp; pBlkKeyInfo->pKeyTuple = (SBlockKeyTuple *)tmp;
pBlkKeyInfo->maxBytesAlloc = (int32_t)nRealAlloc; pBlkKeyInfo->maxBytesAlloc = (int32_t)nAlloc;
} }
memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc); memset(pBlkKeyInfo->pKeyTuple, 0, nAlloc);
...@@ -1697,7 +1693,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow ...@@ -1697,7 +1693,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow
STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; STableMeta * pTableMeta = pTableMetaInfo->pTableMeta;
STableComInfo tinfo = tscGetTableInfo(pTableMeta); STableComInfo tinfo = tscGetTableInfo(pTableMeta);
SInsertStatementParam* pInsertParam = &pCmd->insertParam; SInsertStatementParam *pInsertParam = &pCmd->insertParam;
destroyTableNameList(pInsertParam); destroyTableNameList(pInsertParam);
pInsertParam->pDataBlocks = tscDestroyBlockArrayList(pInsertParam->pDataBlocks); pInsertParam->pDataBlocks = tscDestroyBlockArrayList(pInsertParam->pDataBlocks);
...@@ -1726,12 +1722,6 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow ...@@ -1726,12 +1722,6 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int32_t numOfRow
goto _error; goto _error;
} }
if (TSDB_CODE_SUCCESS !=
(ret = initMemRowBuilder(&pTableDataBlock->rowBuilder, 0, tinfo.numOfColumns, pTableDataBlock->numOfParams,
pTableDataBlock->boundColumnInfo.allNullLen))) {
goto _error;
}
while ((readLen = tgetline(&line, &n, fp)) != -1) { while ((readLen = tgetline(&line, &n, fp)) != -1) {
if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) { if (('\r' == line[readLen - 1]) || ('\n' == line[readLen - 1])) {
line[--readLen] = 0; line[--readLen] = 0;
......
...@@ -2034,17 +2034,14 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) { ...@@ -2034,17 +2034,14 @@ void tscHandleMasterJoinQuery(SSqlObj* pSql) {
tscAsyncResultOnError(pSql); tscAsyncResultOnError(pSql);
} }
static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs) { void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs) {
assert(numOfSubs <= pSql->subState.numOfSub && numOfSubs >= 0); assert(numOfSubs <= pSql->subState.numOfSub && numOfSubs >= 0);
for(int32_t i = 0; i < numOfSubs; ++i) { for(int32_t i = 0; i < numOfSubs; ++i) {
SSqlObj* pSub = pSql->pSubs[i]; SSqlObj* pSub = pSql->pSubs[i];
assert(pSub != NULL); assert(pSub != NULL);
SRetrieveSupport* pSupport = pSub->param; tscFreeRetrieveSup(pSub);
tfree(pSupport->localBuffer);
tfree(pSupport);
taos_free_result(pSub); taos_free_result(pSub);
} }
...@@ -2562,7 +2559,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { ...@@ -2562,7 +2559,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static void tscFreeRetrieveSup(SSqlObj *pSql) { void tscFreeRetrieveSup(SSqlObj *pSql) {
SRetrieveSupport *trsupport = pSql->param; SRetrieveSupport *trsupport = pSql->param;
void* p = atomic_val_compare_exchange_ptr(&pSql->param, trsupport, 0); void* p = atomic_val_compare_exchange_ptr(&pSql->param, trsupport, 0);
...@@ -2720,33 +2717,43 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO ...@@ -2720,33 +2717,43 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) { if (!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_JOIN_SEC_STAGE)) {
int32_t code = pParentSql->res.code; int32_t code = pParentSql->res.code;
if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) && pParentSql->retry < pParentSql->maxRetry) { SSqlObj *userSql = NULL;
// remove the cached tableMeta and vgroup id list, and then parse the sql again if (pParentSql->param) {
SSqlCmd* pParentCmd = &pParentSql->cmd; userSql = ((SRetrieveSupport*)pParentSql->param)->pParentSql;
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pParentCmd, 0); }
tscRemoveTableMetaBuf(pTableMetaInfo, pParentSql->self);
pParentCmd->pTableMetaMap = tscCleanupTableMetaMap(pParentCmd->pTableMetaMap); if (userSql == NULL) {
pParentCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); userSql = pParentSql;
}
if ((code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) && userSql->retry < userSql->maxRetry) {
if (userSql != pParentSql) {
tscFreeRetrieveSup(pParentSql);
}
pParentSql->res.code = TSDB_CODE_SUCCESS; tscFreeSubobj(userSql);
pParentSql->retry++; tfree(userSql->pSubs);
tscDebug("0x%"PRIx64" retry parse sql and send query, prev error: %s, retry:%d", pParentSql->self, userSql->res.code = TSDB_CODE_SUCCESS;
tstrerror(code), pParentSql->retry); userSql->retry++;
code = tsParseSql(pParentSql, true); tscDebug("0x%"PRIx64" retry parse sql and send query, prev error: %s, retry:%d", userSql->self,
tstrerror(code), userSql->retry);
tscResetSqlCmd(&userSql->cmd, true);
code = tsParseSql(userSql, true);
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
return; return;
} }
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
pParentSql->res.code = code; userSql->res.code = code;
tscAsyncResultOnError(pParentSql); tscAsyncResultOnError(userSql);
return; return;
} }
executeQuery(pParentSql, pQueryInfo); pQueryInfo = tscGetQueryInfo(&userSql->cmd);
executeQuery(userSql, pQueryInfo);
} else { } else {
(*pParentSql->fp)(pParentSql->param, pParentSql, pParentSql->res.code); (*pParentSql->fp)(pParentSql->param, pParentSql, pParentSql->res.code);
} }
......
...@@ -3767,8 +3767,7 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) { ...@@ -3767,8 +3767,7 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) {
int32_t index = ps->subqueryIndex; int32_t index = ps->subqueryIndex;
bool ret = subAndCheckDone(pSql, pParentSql, index); bool ret = subAndCheckDone(pSql, pParentSql, index);
tfree(ps); tscFreeRetrieveSup(pSql);
pSql->param = NULL;
if (!ret) { if (!ret) {
tscDebug("0x%"PRIx64" sub:0x%"PRIx64" orderOfSub:%d completed, not all subquery finished", pParentSql->self, pSql->self, index); tscDebug("0x%"PRIx64" sub:0x%"PRIx64" orderOfSub:%d completed, not all subquery finished", pParentSql->self, pSql->self, index);
...@@ -3778,12 +3777,13 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) { ...@@ -3778,12 +3777,13 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) {
// todo refactor // todo refactor
tscDebug("0x%"PRIx64" all subquery response received, retry", pParentSql->self); tscDebug("0x%"PRIx64" all subquery response received, retry", pParentSql->self);
SSqlCmd* pParentCmd = &pParentSql->cmd; if (code && !((code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_VND_INVALID_VGROUP_ID) && pParentSql->retry < pParentSql->maxRetry)) {
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pParentCmd, 0); tscAsyncResultOnError(pParentSql);
tscRemoveTableMetaBuf(pTableMetaInfo, pParentSql->self); return;
}
pParentCmd->pTableMetaMap = tscCleanupTableMetaMap(pParentCmd->pTableMetaMap); tscFreeSubobj(pParentSql);
pParentCmd->pTableMetaMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); tfree(pParentSql->pSubs);
pParentSql->res.code = TSDB_CODE_SUCCESS; pParentSql->res.code = TSDB_CODE_SUCCESS;
pParentSql->retry++; pParentSql->retry++;
...@@ -3791,6 +3791,9 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) { ...@@ -3791,6 +3791,9 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) {
tscDebug("0x%"PRIx64" retry parse sql and send query, prev error: %s, retry:%d", pParentSql->self, tscDebug("0x%"PRIx64" retry parse sql and send query, prev error: %s, retry:%d", pParentSql->self,
tstrerror(code), pParentSql->retry); tstrerror(code), pParentSql->retry);
tscResetSqlCmd(&pParentSql->cmd, true);
code = tsParseSql(pParentSql, true); code = tsParseSql(pParentSql, true);
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
return; return;
...@@ -3802,7 +3805,8 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) { ...@@ -3802,7 +3805,8 @@ static void tscSubqueryCompleteCallback(void* param, TAOS_RES* tres, int code) {
return; return;
} }
SQueryInfo *pQueryInfo = tscGetQueryInfo(pParentCmd); SQueryInfo *pQueryInfo = tscGetQueryInfo(&pParentSql->cmd);
executeQuery(pParentSql, pQueryInfo); executeQuery(pParentSql, pQueryInfo);
return; return;
} }
...@@ -3825,9 +3829,11 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) { ...@@ -3825,9 +3829,11 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
} }
if (taosArrayGetSize(pQueryInfo->pUpstream) > 0) { // nest query. do execute it firstly if (taosArrayGetSize(pQueryInfo->pUpstream) > 0) { // nest query. do execute it firstly
assert(pSql->subState.numOfSub == 0);
pSql->subState.numOfSub = (int32_t) taosArrayGetSize(pQueryInfo->pUpstream); pSql->subState.numOfSub = (int32_t) taosArrayGetSize(pQueryInfo->pUpstream);
assert(pSql->pSubs == NULL);
pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES); pSql->pSubs = calloc(pSql->subState.numOfSub, POINTER_BYTES);
assert(pSql->subState.states == NULL);
pSql->subState.states = calloc(pSql->subState.numOfSub, sizeof(int8_t)); pSql->subState.states = calloc(pSql->subState.numOfSub, sizeof(int8_t));
code = pthread_mutex_init(&pSql->subState.mutex, NULL); code = pthread_mutex_init(&pSql->subState.mutex, NULL);
......
...@@ -158,6 +158,7 @@ extern char tsDataDir[]; ...@@ -158,6 +158,7 @@ extern char tsDataDir[];
extern char tsLogDir[]; extern char tsLogDir[];
extern char tsScriptDir[]; extern char tsScriptDir[];
extern int64_t tsTickPerDay[3]; extern int64_t tsTickPerDay[3];
extern int32_t tsTopicBianryLen;
// system info // system info
extern char tsOsName[]; extern char tsOsName[];
......
...@@ -199,6 +199,7 @@ char tsScriptDir[PATH_MAX] = {0}; ...@@ -199,6 +199,7 @@ char tsScriptDir[PATH_MAX] = {0};
char tsTempDir[PATH_MAX] = "/tmp/"; char tsTempDir[PATH_MAX] = "/tmp/";
int32_t tsDiskCfgNum = 0; int32_t tsDiskCfgNum = 0;
int32_t tsTopicBianryLen = 16000;
#ifndef _STORAGE #ifndef _STORAGE
SDiskCfg tsDiskCfg[1]; SDiskCfg tsDiskCfg[1];
...@@ -1216,6 +1217,16 @@ static void doInitGlobalConfig(void) { ...@@ -1216,6 +1217,16 @@ static void doInitGlobalConfig(void) {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); taosInitConfigOption(cfg);
cfg.option = "topicBianryLen";
cfg.ptr = &tsTopicBianryLen;
cfg.valType = TAOS_CFG_VTYPE_INT32;
cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG;
cfg.minValue = 16;
cfg.maxValue = 16000;
cfg.ptrLength = 0;
cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg);
cfg.option = "httpEnableRecordSql"; cfg.option = "httpEnableRecordSql";
cfg.ptr = &tsHttpEnableRecordSql; cfg.ptr = &tsHttpEnableRecordSql;
cfg.valType = TAOS_CFG_VTYPE_INT8; cfg.valType = TAOS_CFG_VTYPE_INT8;
......
...@@ -38,11 +38,7 @@ const int32_t TYPE_BYTES[15] = { ...@@ -38,11 +38,7 @@ const int32_t TYPE_BYTES[15] = {
#define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \ #define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \
do { \ do { \
if (_list[(_index)] >= (INT64_MAX - (__sum))) { \ (__sum) += (_list)[(_index)]; \
__sum = INT64_MAX; \
} else { \
(__sum) += (_list)[(_index)]; \
} \
if ((__min) > (_list)[(_index)]) { \ if ((__min) > (_list)[(_index)]) { \
(__min) = (_list)[(_index)]; \ (__min) = (_list)[(_index)]; \
(__minIndex) = (_index); \ (__minIndex) = (_index); \
......
...@@ -64,6 +64,10 @@ void printHelp() { ...@@ -64,6 +64,10 @@ void printHelp() {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
char DARWINCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
char g_password[MAX_PASSWORD_SIZE];
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
wordexp_t full_path; wordexp_t full_path;
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
...@@ -77,10 +81,21 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -77,10 +81,21 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} }
} }
// for password // for password
else if (strcmp(argv[i], "-p") == 0) { else if (strncmp(argv[i], "-p", 2) == 0) {
arguments->is_use_passwd = true; strcpy(tsOsName, "Darwin");
printf(DARWINCLIENT_VERSION, tsOsName, taos_get_client_info());
if (strlen(argv[i]) == 2) {
printf("Enter password: ");
if (scanf("%s", g_password) > 1) {
fprintf(stderr, "password read error\n");
}
getchar();
} else {
tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
arguments->password = g_password;
} }
// for management port // for management port
else if (strcmp(argv[i], "-P") == 0) { else if (strcmp(argv[i], "-P") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
arguments->port = atoi(argv[++i]); arguments->port = atoi(argv[++i]);
...@@ -98,7 +113,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -98,7 +113,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if (strcmp(argv[i], "-c") == 0) { } else if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) { if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1); fprintf(stderr, "config file path: %s overflow max len %d\n", argv[i], TSDB_FILENAME_LEN - 1);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
...@@ -65,7 +65,15 @@ extern TAOS *taos_connect_auth(const char *ip, const char *user, const char *aut ...@@ -65,7 +65,15 @@ extern TAOS *taos_connect_auth(const char *ip, const char *user, const char *aut
*/ */
TAOS *shellInit(SShellArguments *_args) { TAOS *shellInit(SShellArguments *_args) {
printf("\n"); printf("\n");
printf(CLIENT_VERSION, tsOsName, taos_get_client_info()); if (!_args->is_use_passwd) {
#ifdef TD_WINDOWS
strcpy(tsOsName, "Windows");
#elif defined(TD_DARWIN)
strcpy(tsOsName, "Darwin");
#endif
printf(CLIENT_VERSION, tsOsName, taos_get_client_info());
}
fflush(stdout); fflush(stdout);
// set options before initializing // set options before initializing
...@@ -73,9 +81,7 @@ TAOS *shellInit(SShellArguments *_args) { ...@@ -73,9 +81,7 @@ TAOS *shellInit(SShellArguments *_args) {
taos_options(TSDB_OPTION_TIMEZONE, _args->timezone); taos_options(TSDB_OPTION_TIMEZONE, _args->timezone);
} }
if (_args->is_use_passwd) { if (!_args->is_use_passwd) {
if (_args->password == NULL) _args->password = getpass("Enter password: ");
} else {
_args->password = TSDB_DEFAULT_PASS; _args->password = TSDB_DEFAULT_PASS;
} }
...@@ -170,7 +176,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -170,7 +176,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
system("clear"); system("clear");
return 0; return 0;
} }
if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
strtok(command, " \t"); strtok(command, " \t");
strtok(NULL, " \t"); strtok(NULL, " \t");
...@@ -182,7 +188,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -182,7 +188,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
} }
return 0; return 0;
} }
if (regex_match(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
/* If source file. */ /* If source file. */
char *c_ptr = strtok(command, " ;"); char *c_ptr = strtok(command, " ;");
...@@ -247,7 +253,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { ...@@ -247,7 +253,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
esc = false; esc = false;
continue; continue;
} }
if (c == '\\') { if (c == '\\') {
esc = true; esc = true;
continue; continue;
...@@ -336,8 +342,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { ...@@ -336,8 +342,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
} }
if (!tscIsUpdateQuery(pSql)) { // select and show kinds of commands if (!tscIsUpdateQuery(pSql)) { // select and show kinds of commands
int error_no = 0; int error_no = 0;
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode); int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
if (numOfRows < 0) { if (numOfRows < 0) {
atomic_store_64(&result, 0); atomic_store_64(&result, 0);
...@@ -530,7 +536,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -530,7 +536,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
fprintf(fp, "%s", fields[col].name); fprintf(fp, "%s", fields[col].name);
} }
fputc('\n', fp); fputc('\n', fp);
int numOfRows = 0; int numOfRows = 0;
do { do {
int32_t* length = taos_fetch_lengths(tres); int32_t* length = taos_fetch_lengths(tres);
...@@ -716,7 +722,7 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -716,7 +722,7 @@ static int verticalPrintResult(TAOS_RES* tres) {
int numOfRows = 0; int numOfRows = 0;
int showMore = 1; int showMore = 1;
do { do {
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
printf("*************************** %d.row ***************************\n", numOfRows + 1); printf("*************************** %d.row ***************************\n", numOfRows + 1);
...@@ -851,7 +857,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -851,7 +857,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
int numOfRows = 0; int numOfRows = 0;
int showMore = 1; int showMore = 1;
do { do {
int32_t* length = taos_fetch_lengths(tres); int32_t* length = taos_fetch_lengths(tres);
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
...@@ -867,7 +873,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -867,7 +873,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
printf("[You can add limit statement to show more or redirect results to specific file to get all.]\n"); printf("[You can add limit statement to show more or redirect results to specific file to get all.]\n");
showMore = 0; showMore = 0;
} }
numOfRows++; numOfRows++;
row = taos_fetch_row(tres); row = taos_fetch_row(tres);
} while(row != NULL); } while(row != NULL);
...@@ -909,7 +915,7 @@ void read_history() { ...@@ -909,7 +915,7 @@ void read_history() {
if (errno != ENOENT) { if (errno != ENOENT) {
fprintf(stderr, "Failed to open file %s, reason:%s\n", f_history, strerror(errno)); fprintf(stderr, "Failed to open file %s, reason:%s\n", f_history, strerror(errno));
} }
#endif #endif
return; return;
} }
...@@ -934,9 +940,9 @@ void write_history() { ...@@ -934,9 +940,9 @@ void write_history() {
FILE *f = fopen(f_history, "w"); FILE *f = fopen(f_history, "w");
if (f == NULL) { if (f == NULL) {
#ifndef WINDOWS #ifndef WINDOWS
fprintf(stderr, "Failed to open file %s for write, reason:%s\n", f_history, strerror(errno)); fprintf(stderr, "Failed to open file %s for write, reason:%s\n", f_history, strerror(errno));
#endif #endif
return; return;
} }
...@@ -982,13 +988,13 @@ void source_file(TAOS *con, char *fptr) { ...@@ -982,13 +988,13 @@ void source_file(TAOS *con, char *fptr) {
/* /*
if (access(fname, F_OK) != 0) { if (access(fname, F_OK) != 0) {
fprintf(stderr, "ERROR: file %s is not exist\n", fptr); fprintf(stderr, "ERROR: file %s is not exist\n", fptr);
wordfree(&full_path); wordfree(&full_path);
free(cmd); free(cmd);
return; return;
} }
*/ */
FILE *f = fopen(fname, "r"); FILE *f = fopen(fname, "r");
if (f == NULL) { if (f == NULL) {
fprintf(stderr, "ERROR: failed to open file %s\n", fname); fprintf(stderr, "ERROR: failed to open file %s\n", fname);
......
...@@ -34,7 +34,7 @@ static char doc[] = ""; ...@@ -34,7 +34,7 @@ static char doc[] = "";
static char args_doc[] = ""; static char args_doc[] = "";
static struct argp_option options[] = { static struct argp_option options[] = {
{"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."}, {"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."},
{"password", 'p', "PASSWORD", OPTION_ARG_OPTIONAL, "The password to use when connecting to the server."}, {"password", 'p', 0, 0, "The password to use when connecting to the server."},
{"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."}, {"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."},
{"user", 'u', "USER", 0, "The user name to use when connecting to the server."}, {"user", 'u', "USER", 0, "The user name to use when connecting to the server."},
{"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."}, {"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."},
...@@ -63,8 +63,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -63,8 +63,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
arguments->host = arg; arguments->host = arg;
break; break;
case 'p': case 'p':
arguments->is_use_passwd = true;
if (arg) arguments->password = arg;
break; break;
case 'P': case 'P':
if (arg) { if (arg) {
...@@ -160,12 +158,41 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -160,12 +158,41 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
/* Our argp parser. */ /* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc}; static struct argp argp = {options, parse_opt, args_doc, doc};
char LINUXCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
char g_password[MAX_PASSWORD_SIZE];
static void parse_password(
int argc, char *argv[], SShellArguments *arguments) {
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-p", 2) == 0) {
strcpy(tsOsName, "Linux");
printf(LINUXCLIENT_VERSION, tsOsName, taos_get_client_info());
if (strlen(argv[i]) == 2) {
printf("Enter password: ");
if (scanf("%20s", g_password) > 1) {
fprintf(stderr, "password reading error\n");
}
getchar();
} else {
tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
arguments->password = g_password;
arguments->is_use_passwd = true;
}
}
}
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
static char verType[32] = {0}; static char verType[32] = {0};
sprintf(verType, "version: %s\n", version); sprintf(verType, "version: %s\n", version);
argp_program_version = verType; argp_program_version = verType;
if (argc > 1) {
parse_password(argc, argv, arguments);
}
argp_parse(&argp, argc, argv, 0, 0, arguments); argp_parse(&argp, argc, argv, 0, 0, arguments);
if (arguments->abort) { if (arguments->abort) {
#ifndef _ALPINE #ifndef _ALPINE
......
...@@ -71,7 +71,9 @@ int checkVersion() { ...@@ -71,7 +71,9 @@ int checkVersion() {
// Global configurations // Global configurations
SShellArguments args = { SShellArguments args = {
.host = NULL, .host = NULL,
#ifndef TD_WINDOWS
.password = NULL, .password = NULL,
#endif
.user = NULL, .user = NULL,
.database = NULL, .database = NULL,
.timezone = NULL, .timezone = NULL,
......
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
extern char configDir[]; extern char configDir[];
char WINCLIENT_VERSION[] = "Welcome to the TDengine shell from %s, Client Version:%s\n"
"Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.\n\n";
void printVersion() { void printVersion() {
printf("version: %s\n", version); printf("version: %s\n", version);
} }
...@@ -61,6 +64,8 @@ void printHelp() { ...@@ -61,6 +64,8 @@ void printHelp() {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
char g_password[MAX_PASSWORD_SIZE];
void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
// for host // for host
...@@ -73,11 +78,20 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -73,11 +78,20 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
} }
} }
// for password // for password
else if (strcmp(argv[i], "-p") == 0) { else if (strncmp(argv[i], "-p", 2) == 0) {
arguments->is_use_passwd = true; arguments->is_use_passwd = true;
if (i < argc - 1 && argv[i + 1][0] != '-') { strcpy(tsOsName, "Windows");
arguments->password = argv[++i]; printf(WINCLIENT_VERSION, tsOsName, taos_get_client_info());
} if (strlen(argv[i]) == 2) {
printf("Enter password: ");
if (scanf("%s", g_password) > 1) {
fprintf(stderr, "password read error!\n");
}
getchar();
} else {
tstrncpy(g_password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
arguments->password = g_password;
} }
// for management port // for management port
else if (strcmp(argv[i], "-P") == 0) { else if (strcmp(argv[i], "-P") == 0) {
...@@ -104,7 +118,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -104,7 +118,7 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else if (strcmp(argv[i], "-c") == 0) { } else if (strcmp(argv[i], "-c") == 0) {
if (i < argc - 1) { if (i < argc - 1) {
char *tmp = argv[++i]; char *tmp = argv[++i];
if (strlen(tmp) >= TSDB_FILENAME_LEN) { if (strlen(tmp) >= TSDB_FILENAME_LEN) {
fprintf(stderr, "config file path: %s overflow max len %d\n", tmp, TSDB_FILENAME_LEN - 1); fprintf(stderr, "config file path: %s overflow max len %d\n", tmp, TSDB_FILENAME_LEN - 1);
...@@ -265,7 +279,7 @@ void *shellLoopQuery(void *arg) { ...@@ -265,7 +279,7 @@ void *shellLoopQuery(void *arg) {
if (command == NULL) return NULL; if (command == NULL) return NULL;
int32_t err = 0; int32_t err = 0;
do { do {
memset(command, 0, MAX_COMMAND_SIZE); memset(command, 0, MAX_COMMAND_SIZE);
shellPrintPrompt(); shellPrintPrompt();
...@@ -274,7 +288,7 @@ void *shellLoopQuery(void *arg) { ...@@ -274,7 +288,7 @@ void *shellLoopQuery(void *arg) {
err = shellReadCommand(con, command); err = shellReadCommand(con, command);
if (err) { if (err) {
break; break;
} }
} while (shellRunCommand(con, command) == 0); } while (shellRunCommand(con, command) == 0);
return NULL; return NULL;
......
...@@ -866,8 +866,12 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { ...@@ -866,8 +866,12 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) {
arguments->user = argv[++i]; arguments->user = argv[++i];
} else if (strncmp(argv[i], "-p", 2) == 0) { } else if (strncmp(argv[i], "-p", 2) == 0) {
if (strlen(argv[i]) == 2) { if (strlen(argv[i]) == 2) {
printf("Enter password:"); printf("Enter password: ");
scanf("%s", arguments->password); taosSetConsoleEcho(false);
if (scanf("%s", arguments->password) > 1) {
fprintf(stderr, "password read error!\n");
}
taosSetConsoleEcho(true);
} else { } else {
tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE); tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
} }
......
...@@ -206,9 +206,9 @@ static struct argp_option options[] = { ...@@ -206,9 +206,9 @@ static struct argp_option options[] = {
{"host", 'h', "HOST", 0, "Server host dumping data from. Default is localhost.", 0}, {"host", 'h', "HOST", 0, "Server host dumping data from. Default is localhost.", 0},
{"user", 'u', "USER", 0, "User name used to connect to server. Default is root.", 0}, {"user", 'u', "USER", 0, "User name used to connect to server. Default is root.", 0},
#ifdef _TD_POWER_ #ifdef _TD_POWER_
{"password", 'p', "PASSWORD", 0, "User password to connect to server. Default is powerdb.", 0}, {"password", 'p', 0, 0, "User password to connect to server. Default is powerdb.", 0},
#else #else
{"password", 'p', "PASSWORD", 0, "User password to connect to server. Default is taosdata.", 0}, {"password", 'p', 0, 0, "User password to connect to server. Default is taosdata.", 0},
#endif #endif
{"port", 'P', "PORT", 0, "Port to connect", 0}, {"port", 'P', "PORT", 0, "Port to connect", 0},
{"cversion", 'v', "CVERION", 0, "client version", 0}, {"cversion", 'v', "CVERION", 0, "client version", 0},
...@@ -248,12 +248,14 @@ static struct argp_option options[] = { ...@@ -248,12 +248,14 @@ static struct argp_option options[] = {
{0} {0}
}; };
#define MAX_PASSWORD_SIZE 20
/* Used by main to communicate with parse_opt. */ /* Used by main to communicate with parse_opt. */
typedef struct arguments { typedef struct arguments {
// connection option // connection option
char *host; char *host;
char *user; char *user;
char *password; char password[MAX_PASSWORD_SIZE];
uint16_t port; uint16_t port;
char cversion[12]; char cversion[12];
uint16_t mysqlFlag; uint16_t mysqlFlag;
...@@ -376,7 +378,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -376,7 +378,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
g_args.user = arg; g_args.user = arg;
break; break;
case 'p': case 'p':
g_args.password = arg;
break; break;
case 'P': case 'P':
g_args.port = atoi(arg); g_args.port = atoi(arg);
...@@ -554,6 +555,25 @@ static void parse_precision_first( ...@@ -554,6 +555,25 @@ static void parse_precision_first(
} }
} }
static void parse_password(
int argc, char *argv[], SArguments *arguments) {
for (int i = 1; i < argc; i++) {
if (strncmp(argv[i], "-p", 2) == 0) {
if (strlen(argv[i]) == 2) {
printf("Enter password: ");
taosSetConsoleEcho(false);
if(scanf("%20s", arguments->password) > 1) {
errorPrint("%s() LN%d, password read error!\n", __func__, __LINE__);
}
taosSetConsoleEcho(true);
} else {
tstrncpy(arguments->password, (char *)(argv[i] + 2), MAX_PASSWORD_SIZE);
}
argv[i] = "";
}
}
}
static void parse_timestamp( static void parse_timestamp(
int argc, char *argv[], SArguments *arguments) { int argc, char *argv[], SArguments *arguments) {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
...@@ -616,9 +636,10 @@ int main(int argc, char *argv[]) { ...@@ -616,9 +636,10 @@ int main(int argc, char *argv[]) {
int ret = 0; int ret = 0;
/* Parse our arguments; every option seen by parse_opt will be /* Parse our arguments; every option seen by parse_opt will be
reflected in arguments. */ reflected in arguments. */
if (argc > 2) { if (argc > 1) {
parse_precision_first(argc, argv, &g_args); parse_precision_first(argc, argv, &g_args);
parse_timestamp(argc, argv, &g_args); parse_timestamp(argc, argv, &g_args);
parse_password(argc, argv, &g_args);
} }
argp_parse(&argp, argc, argv, 0, 0, &g_args); argp_parse(&argp, argc, argv, 0, 0, &g_args);
......
...@@ -24,6 +24,8 @@ void* taosLoadDll(const char *filename); ...@@ -24,6 +24,8 @@ void* taosLoadDll(const char *filename);
void* taosLoadSym(void* handle, char* name); void* taosLoadSym(void* handle, char* name);
void taosCloseDll(void *handle); void taosCloseDll(void *handle);
int taosSetConsoleEcho(bool on);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -29,4 +29,30 @@ void* taosLoadSym(void* handle, char* name) { ...@@ -29,4 +29,30 @@ void* taosLoadSym(void* handle, char* name) {
void taosCloseDll(void *handle) { void taosCloseDll(void *handle) {
} }
int taosSetConsoleEcho(bool on)
{
#if 0
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
int err;
struct termios term;
if (tcgetattr(STDIN_FILENO, &term) == -1) {
perror("Cannot get the attribution of the terminal");
return -1;
}
if (on)
term.c_lflag|=ECHOFLAGS;
else
term.c_lflag &=~ECHOFLAGS;
err = tcsetattr(STDIN_FILENO,TCSAFLUSH,&term);
if (err == -1 && err == EINTR) {
perror("Cannot set the attribution of the terminal");
return -1;
}
#endif
return 0;
}
...@@ -51,4 +51,28 @@ void taosCloseDll(void *handle) { ...@@ -51,4 +51,28 @@ void taosCloseDll(void *handle) {
} }
} }
int taosSetConsoleEcho(bool on)
{
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
int err;
struct termios term;
if (tcgetattr(STDIN_FILENO, &term) == -1) {
perror("Cannot get the attribution of the terminal");
return -1;
}
if (on)
term.c_lflag|=ECHOFLAGS;
else
term.c_lflag &=~ECHOFLAGS;
err = tcsetattr(STDIN_FILENO,TCSAFLUSH,&term);
if (err == -1 && err == EINTR) {
perror("Cannot set the attribution of the terminal");
return -1;
}
return 0;
}
...@@ -30,3 +30,17 @@ void taosCloseDll(void *handle) { ...@@ -30,3 +30,17 @@ void taosCloseDll(void *handle) {
} }
int taosSetConsoleEcho(bool on)
{
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode );
if (on) {
mode |= ENABLE_ECHO_INPUT;
} else {
mode &= ~ENABLE_ECHO_INPUT;
}
SetConsoleMode(hStdin, mode);
return 0;
}
...@@ -1250,8 +1250,14 @@ static int tsdbEncodeTable(void **buf, STable *pTable) { ...@@ -1250,8 +1250,14 @@ static int tsdbEncodeTable(void **buf, STable *pTable) {
tlen += taosEncodeFixedU64(buf, TABLE_SUID(pTable)); tlen += taosEncodeFixedU64(buf, TABLE_SUID(pTable));
tlen += tdEncodeKVRow(buf, pTable->tagVal); tlen += tdEncodeKVRow(buf, pTable->tagVal);
} else { } else {
tlen += taosEncodeFixedU8(buf, (uint8_t)taosArrayGetSize(pTable->schema)); uint32_t arraySize = (uint32_t)taosArrayGetSize(pTable->schema);
for (int i = 0; i < taosArrayGetSize(pTable->schema); i++) { if(arraySize > UINT8_MAX) {
tlen += taosEncodeFixedU8(buf, 0);
tlen += taosEncodeFixedU32(buf, arraySize);
} else {
tlen += taosEncodeFixedU8(buf, (uint8_t)arraySize);
}
for (uint32_t i = 0; i < arraySize; i++) {
STSchema *pSchema = taosArrayGetP(pTable->schema, i); STSchema *pSchema = taosArrayGetP(pTable->schema, i);
tlen += tdEncodeSchema(buf, pSchema); tlen += tdEncodeSchema(buf, pSchema);
} }
...@@ -1284,8 +1290,11 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) { ...@@ -1284,8 +1290,11 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) {
buf = taosDecodeFixedU64(buf, &TABLE_SUID(pTable)); buf = taosDecodeFixedU64(buf, &TABLE_SUID(pTable));
buf = tdDecodeKVRow(buf, &(pTable->tagVal)); buf = tdDecodeKVRow(buf, &(pTable->tagVal));
} else { } else {
uint8_t nSchemas; uint32_t nSchemas = 0;
buf = taosDecodeFixedU8(buf, &nSchemas); buf = taosDecodeFixedU8(buf, (uint8_t *)&nSchemas);
if(nSchemas == 0) {
buf = taosDecodeFixedU32(buf, &nSchemas);
}
for (int i = 0; i < nSchemas; i++) { for (int i = 0; i < nSchemas; i++) {
STSchema *pSchema; STSchema *pSchema;
buf = tdDecodeSchema(buf, &pSchema); buf = tdDecodeSchema(buf, &pSchema);
...@@ -1485,4 +1494,4 @@ static void tsdbFreeTableSchema(STable *pTable) { ...@@ -1485,4 +1494,4 @@ static void tsdbFreeTableSchema(STable *pTable) {
taosArrayDestroy(pTable->schema); taosArrayDestroy(pTable->schema);
} }
} }
\ No newline at end of file
...@@ -313,6 +313,12 @@ if $rows != 6 then ...@@ -313,6 +313,12 @@ if $rows != 6 then
return -1 return -1
endi endi
print =============================> TD-6086
sql create stable td6086st(ts timestamp, d double) tags(t nchar(50));
sql create table td6086ct1 using td6086st tags("ct1");
sql create table td6086ct2 using td6086st tags("ct2");
sql SELECT LAST(d),t FROM td6086st WHERE tbname in ('td6086ct1', 'td6086ct2') and ts>="2019-07-30 00:00:00" and ts<="2021-08-31 00:00:00" interval(1800s) fill(prev) GROUP BY tbname;
print ==================> td-2624 print ==================> td-2624
sql create table tm2(ts timestamp, k int, b binary(12)); sql create table tm2(ts timestamp, k int, b binary(12));
sql insert into tm2 values('2011-01-02 18:42:45.326', -1,'abc'); sql insert into tm2 values('2011-01-02 18:42:45.326', -1,'abc');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册