Merge branch 'develop' into xiaoping/add_test_case
This commit is contained in:
commit
ca04cae64f
|
@ -4,7 +4,7 @@ PROJECT(TDengine)
|
||||||
IF (DEFINED VERNUMBER)
|
IF (DEFINED VERNUMBER)
|
||||||
SET(TD_VER_NUMBER ${VERNUMBER})
|
SET(TD_VER_NUMBER ${VERNUMBER})
|
||||||
ELSE ()
|
ELSE ()
|
||||||
SET(TD_VER_NUMBER "2.0.3.0")
|
SET(TD_VER_NUMBER "2.0.4.0")
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
IF (DEFINED VERCOMPATIBLE)
|
IF (DEFINED VERCOMPATIBLE)
|
||||||
|
|
|
@ -191,6 +191,7 @@ SColumn* tscColumnListInsert(SArray* pColList, SColumnIndex* colIndex);
|
||||||
SArray* tscColumnListClone(const SArray* src, int16_t tableIndex);
|
SArray* tscColumnListClone(const SArray* src, int16_t tableIndex);
|
||||||
void tscColumnListDestroy(SArray* pColList);
|
void tscColumnListDestroy(SArray* pColList);
|
||||||
|
|
||||||
|
void tscDequoteAndTrimToken(SStrToken* pToken);
|
||||||
int32_t tscValidateName(SStrToken* pToken);
|
int32_t tscValidateName(SStrToken* pToken);
|
||||||
|
|
||||||
void tscIncStreamExecutionCount(void* pStream);
|
void tscIncStreamExecutionCount(void* pStream);
|
||||||
|
|
|
@ -99,6 +99,7 @@ typedef struct STableMeta {
|
||||||
uint8_t tableType;
|
uint8_t tableType;
|
||||||
int16_t sversion;
|
int16_t sversion;
|
||||||
int16_t tversion;
|
int16_t tversion;
|
||||||
|
char sTableId[TSDB_TABLE_FNAME_LEN];
|
||||||
SCMVgroupInfo vgroupInfo;
|
SCMVgroupInfo vgroupInfo;
|
||||||
SCMCorVgroupInfo corVgroupInfo;
|
SCMCorVgroupInfo corVgroupInfo;
|
||||||
STableId id;
|
STableId id;
|
||||||
|
|
|
@ -23,7 +23,30 @@
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
#include "taos.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
|
|
||||||
|
#define STR_NOCASE_EQUAL(str1, len1, str2, len2) ((len1 == len2) && 0 == strncasecmp(str1, str2, len1))
|
||||||
|
|
||||||
|
typedef enum BuildType {
|
||||||
|
SCREATE_BUILD_TABLE = 1,
|
||||||
|
SCREATE_BUILD_DB = 2,
|
||||||
|
} BuildType;
|
||||||
|
|
||||||
|
typedef enum Stage {
|
||||||
|
SCREATE_CALLBACK_QUERY = 1,
|
||||||
|
SCREATE_CALLBACK_RETRIEVE = 2,
|
||||||
|
} Stage;
|
||||||
|
|
||||||
|
// support 'show create table'
|
||||||
|
typedef struct SCreateBuilder {
|
||||||
|
char sTableName[TSDB_TABLE_FNAME_LEN];
|
||||||
|
char buf[TSDB_TABLE_FNAME_LEN];
|
||||||
|
SSqlObj *pParentSql;
|
||||||
|
SSqlObj *pInterSql;
|
||||||
|
int32_t (*fp)(void *para, char* result);
|
||||||
|
Stage callStage;
|
||||||
|
} SCreateBuilder;
|
||||||
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength);
|
static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, int16_t type, size_t valueLength);
|
||||||
|
|
||||||
static int32_t getToStringLength(const char *pData, int32_t length, int32_t type) {
|
static int32_t getToStringLength(const char *pData, int32_t length, int32_t type) {
|
||||||
|
@ -272,14 +295,511 @@ static int32_t tscProcessDescribeTable(SSqlObj *pSql) {
|
||||||
tscFieldInfoUpdateOffset(pQueryInfo);
|
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||||
return tscSetValueToResObj(pSql, rowLen);
|
return tscSetValueToResObj(pSql, rowLen);
|
||||||
}
|
}
|
||||||
|
static int32_t tscGetNthFieldResult(TAOS_ROW row, TAOS_FIELD* fields, int *lengths, int idx, char *result) {
|
||||||
|
const char *val = row[idx];
|
||||||
|
if (val == NULL) {
|
||||||
|
sprintf(result, "%s", TSDB_DATA_NULL_STR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
uint8_t type = fields[idx].type;
|
||||||
|
int32_t length = lengths[idx];
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case TSDB_DATA_TYPE_BOOL:
|
||||||
|
sprintf(result, "%s", ((((int)(*((char *)val))) == 1) ? "true" : "false"));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TINYINT:
|
||||||
|
sprintf(result, "%d", (int)(*((char *)val)));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_SMALLINT:
|
||||||
|
sprintf(result, "%d", (int)(*((short *)val)));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_INT:
|
||||||
|
sprintf(result, "%d", *((int *)val));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_BIGINT:
|
||||||
|
sprintf(result, "%"PRId64, *((int64_t *)val));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_FLOAT:
|
||||||
|
sprintf(result, "%f", GET_FLOAT_VAL(val));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DOUBLE:
|
||||||
|
sprintf(result, "%f", GET_DOUBLE_VAL(val));
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
|
memcpy(result, val, length);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||||
|
///formatTimestamp(buf, *(int64_t*)val, TSDB_TIME_PRECISION_MICRO);
|
||||||
|
//memcpy(result, val, strlen(buf));
|
||||||
|
sprintf(result, "%"PRId64, *((int64_t *)val));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tscSCreateCallBack(void *param, TAOS_RES *tres, int code) {
|
||||||
|
if (param == NULL || tres == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SCreateBuilder *builder = (SCreateBuilder *)(param);
|
||||||
|
SSqlObj *pParentSql = builder->pParentSql;
|
||||||
|
SSqlObj *pSql = (SSqlObj *)tres;
|
||||||
|
|
||||||
|
SSqlRes *pRes = &pParentSql->res;
|
||||||
|
pRes->code = taos_errno(pSql);
|
||||||
|
if (pRes->code != TSDB_CODE_SUCCESS) {
|
||||||
|
taos_free_result(pSql);
|
||||||
|
free(builder);
|
||||||
|
tscQueueAsyncRes(pParentSql);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (builder->callStage == SCREATE_CALLBACK_QUERY) {
|
||||||
|
taos_fetch_rows_a(tres, tscSCreateCallBack, param);
|
||||||
|
builder->callStage = SCREATE_CALLBACK_RETRIEVE;
|
||||||
|
} else {
|
||||||
|
char *result = calloc(1, TSDB_MAX_BINARY_LEN);
|
||||||
|
pRes->code = builder->fp(builder, result);
|
||||||
|
|
||||||
|
taos_free_result(pSql);
|
||||||
|
free(builder);
|
||||||
|
free(result);
|
||||||
|
|
||||||
|
if (pRes->code == TSDB_CODE_SUCCESS) {
|
||||||
|
(*pParentSql->fp)(pParentSql->param, pParentSql, code);
|
||||||
|
} else {
|
||||||
|
tscQueueAsyncRes(pParentSql);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TAOS_ROW tscFetchRow(void *param) {
|
||||||
|
SCreateBuilder *builder = (SCreateBuilder *)param;
|
||||||
|
if (builder == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
SSqlObj *pSql = builder->pInterSql;
|
||||||
|
if (pSql == NULL || pSql->signature != pSql) {
|
||||||
|
terrno = TSDB_CODE_TSC_DISCONNECTED;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSqlCmd *pCmd = &pSql->cmd;
|
||||||
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
|
if (pRes->qhandle == 0 ||
|
||||||
|
pCmd->command == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
|
||||||
|
pCmd->command == TSDB_SQL_INSERT) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the sql object owner
|
||||||
|
tscSetSqlOwner(pSql);
|
||||||
|
|
||||||
|
// current data set are exhausted, fetch more data from node
|
||||||
|
if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) &&
|
||||||
|
(pCmd->command == TSDB_SQL_RETRIEVE ||
|
||||||
|
pCmd->command == TSDB_SQL_RETRIEVE_LOCALMERGE ||
|
||||||
|
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
|
||||||
|
pCmd->command == TSDB_SQL_FETCH ||
|
||||||
|
pCmd->command == TSDB_SQL_SHOW ||
|
||||||
|
pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE ||
|
||||||
|
pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE ||
|
||||||
|
pCmd->command == TSDB_SQL_SELECT ||
|
||||||
|
pCmd->command == TSDB_SQL_DESCRIBE_TABLE ||
|
||||||
|
pCmd->command == TSDB_SQL_SERV_STATUS ||
|
||||||
|
pCmd->command == TSDB_SQL_CURRENT_DB ||
|
||||||
|
pCmd->command == TSDB_SQL_SERV_VERSION ||
|
||||||
|
pCmd->command == TSDB_SQL_CLI_VERSION ||
|
||||||
|
pCmd->command == TSDB_SQL_CURRENT_USER )) {
|
||||||
|
taos_fetch_rows_a(pSql, tscSCreateCallBack, param);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* data = doSetResultRowData(pSql, true);
|
||||||
|
|
||||||
|
tscClearSqlOwner(pSql);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
static int32_t tscGetTableTagValue(SCreateBuilder *builder, char *result) {
|
||||||
|
TAOS_ROW row = tscFetchRow(builder);
|
||||||
|
SSqlObj* pSql = builder->pInterSql;
|
||||||
|
|
||||||
|
if (row == NULL) {
|
||||||
|
return TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t* lengths = taos_fetch_lengths(pSql);
|
||||||
|
int num_fields = taos_num_fields(pSql);
|
||||||
|
TAOS_FIELD *fields = taos_fetch_fields(pSql);
|
||||||
|
|
||||||
|
char buf[TSDB_COL_NAME_LEN + 16];
|
||||||
|
for (int i = 0; i < num_fields; i++) {
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
int32_t ret = tscGetNthFieldResult(row, fields, lengths, i, buf);
|
||||||
|
|
||||||
|
if (i == 0) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s", "(");
|
||||||
|
}
|
||||||
|
if ((fields[i].type == TSDB_DATA_TYPE_NCHAR
|
||||||
|
|| fields[i].type == TSDB_DATA_TYPE_BINARY
|
||||||
|
|| fields[i].type == TSDB_DATA_TYPE_TIMESTAMP) && 0 == ret) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "\"%s\",", buf);
|
||||||
|
} else {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s,", buf);
|
||||||
|
}
|
||||||
|
if (i == num_fields - 1) {
|
||||||
|
sprintf(result + strlen(result) - 1, "%s", ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 == strlen(result)) {
|
||||||
|
return TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// build 'show create table/database' result fields
|
||||||
|
static int32_t tscSCreateBuildResultFields(SSqlObj *pSql, BuildType type, const char *ddl) {
|
||||||
|
int32_t rowLen = 0;
|
||||||
|
int16_t ddlLen = (int16_t)strlen(ddl);
|
||||||
|
SColumnIndex index = {0};
|
||||||
|
pSql->cmd.numOfCols = 2;
|
||||||
|
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||||
|
|
||||||
|
TAOS_FIELD f;
|
||||||
|
if (type == SCREATE_BUILD_TABLE) {
|
||||||
|
f.type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
f.bytes = (TSDB_COL_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||||
|
tstrncpy(f.name, "Table", sizeof(f.name));
|
||||||
|
} else {
|
||||||
|
f.type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
f.bytes = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
|
||||||
|
tstrncpy(f.name, "Database", sizeof(f.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
SFieldSupInfo* pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||||
|
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||||
|
f.bytes, f.bytes - VARSTR_HEADER_SIZE, false);
|
||||||
|
|
||||||
|
rowLen += f.bytes;
|
||||||
|
|
||||||
|
f.bytes = (int16_t)(ddlLen + VARSTR_HEADER_SIZE);
|
||||||
|
f.type = TSDB_DATA_TYPE_BINARY;
|
||||||
|
if (type == SCREATE_BUILD_TABLE) {
|
||||||
|
tstrncpy(f.name, "Create Table", sizeof(f.name));
|
||||||
|
} else {
|
||||||
|
tstrncpy(f.name, "Create Database", sizeof(f.name));
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo = tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||||
|
pInfo->pSqlExpr = tscSqlExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index, TSDB_DATA_TYPE_BINARY,
|
||||||
|
(int16_t)(ddlLen + VARSTR_HEADER_SIZE), ddlLen, false);
|
||||||
|
|
||||||
|
rowLen += ddlLen + VARSTR_HEADER_SIZE;
|
||||||
|
|
||||||
|
return rowLen;
|
||||||
|
}
|
||||||
|
static int32_t tscSCreateSetValueToResObj(SSqlObj *pSql, int32_t rowLen, const char *tableName, const char *ddl) {
|
||||||
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
int32_t numOfRows = 1;
|
||||||
|
if (strlen(ddl) == 0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
tscInitResObjForLocalQuery(pSql, numOfRows, rowLen);
|
||||||
|
|
||||||
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||||
|
char* dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 0) * numOfRows;
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(dst, tableName, pField->bytes);
|
||||||
|
|
||||||
|
pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 1);
|
||||||
|
dst = pRes->data + tscFieldInfoGetOffset(pQueryInfo, 1) * numOfRows;
|
||||||
|
STR_WITH_MAXSIZE_TO_VARSTR(dst, ddl, pField->bytes);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int32_t tscSCreateBuildResult(SSqlObj *pSql, BuildType type, const char *str, const char *result) {
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
int32_t rowLen = tscSCreateBuildResultFields(pSql, type, result);
|
||||||
|
|
||||||
|
tscFieldInfoUpdateOffset(pQueryInfo);
|
||||||
|
return tscSCreateSetValueToResObj(pSql, rowLen, str, result);
|
||||||
|
}
|
||||||
|
int32_t tscRebuildCreateTableStatement(void *param,char *result) {
|
||||||
|
SCreateBuilder *builder = (SCreateBuilder *)param;
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
char *buf = calloc(1,TSDB_MAX_BINARY_LEN);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = tscGetTableTagValue(builder, buf);
|
||||||
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE TABLE %s USING %s TAGS %s", builder->buf, builder->sTableName, buf);
|
||||||
|
code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_TABLE, builder->buf, result);
|
||||||
|
}
|
||||||
|
free(buf);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tscGetDBInfo(SCreateBuilder *builder, char *result) {
|
||||||
|
TAOS_ROW row = tscFetchRow(builder);
|
||||||
|
if (row == NULL) {
|
||||||
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
}
|
||||||
|
const char *showColumns[] = {"REPLICA", "QUORUM", "DAYS", "KEEP", "BLOCKS", NULL};
|
||||||
|
|
||||||
|
SSqlObj *pSql = builder->pInterSql;
|
||||||
|
TAOS_FIELD *fields = taos_fetch_fields(pSql);
|
||||||
|
int num_fields = taos_num_fields(pSql);
|
||||||
|
|
||||||
|
char buf[TSDB_DB_NAME_LEN + 64] = {0};
|
||||||
|
do {
|
||||||
|
int32_t* lengths = taos_fetch_lengths(pSql);
|
||||||
|
int32_t ret = tscGetNthFieldResult(row, fields, lengths, 0, buf);
|
||||||
|
if (0 == ret && STR_NOCASE_EQUAL(buf, strlen(buf), builder->buf, strlen(builder->buf))) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "CREATE DATABASE %s", buf);
|
||||||
|
for (int i = 1; i < num_fields; i++) {
|
||||||
|
for (int j = 0; showColumns[j] != NULL; j++) {
|
||||||
|
if (STR_NOCASE_EQUAL(fields[i].name, strlen(fields[i].name), showColumns[j], strlen(showColumns[j]))) {
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
ret = tscGetNthFieldResult(row, fields, lengths, i, buf);
|
||||||
|
if (ret == 0) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), " %s %s", showColumns[j], buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
row = tscFetchRow(builder);
|
||||||
|
} while (row != NULL);
|
||||||
|
|
||||||
|
if (0 == strlen(result)) {
|
||||||
|
return TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
int32_t tscRebuildCreateDBStatement(void *param,char *result) {
|
||||||
|
SCreateBuilder *builder = (SCreateBuilder *)param;
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
char *buf = calloc(1, TSDB_MAX_BINARY_LEN);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
code = tscGetDBInfo(param, buf);
|
||||||
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
code = tscSCreateBuildResult(builder->pParentSql, SCREATE_BUILD_DB, builder->buf, buf);
|
||||||
|
}
|
||||||
|
free(buf);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tscGetTableTagColumnName(SSqlObj *pSql, char **result) {
|
||||||
|
char *buf = (char *)malloc(TSDB_MAX_BINARY_LEN);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
buf[0] = 0;
|
||||||
|
|
||||||
|
STableMeta *pMeta = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0)->pTableMeta;
|
||||||
|
if (pMeta->tableType == TSDB_SUPER_TABLE || pMeta->tableType == TSDB_NORMAL_TABLE ||
|
||||||
|
pMeta->tableType == TSDB_STREAM_TABLE) {
|
||||||
|
free(buf);
|
||||||
|
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSchema *pTagsSchema = tscGetTableTagSchema(pMeta);
|
||||||
|
int32_t numOfTags = tscGetNumOfTags(pMeta);
|
||||||
|
for (int32_t i = 0; i < numOfTags; i++) {
|
||||||
|
if (i != numOfTags - 1) {
|
||||||
|
snprintf(buf + strlen(buf), TSDB_MAX_BINARY_LEN - strlen(buf), "%s,", pTagsSchema[i].name);
|
||||||
|
} else {
|
||||||
|
snprintf(buf + strlen(buf), TSDB_MAX_BINARY_LEN - strlen(buf), "%s", pTagsSchema[i].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*result = buf;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
static int32_t tscRebuildDDLForSubTable(SSqlObj *pSql, const char *tableName, char *ddl) {
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
|
||||||
|
SSqlObj *pInterSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||||
|
if (pInterSql == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCreateBuilder *param = (SCreateBuilder *)malloc(sizeof(SCreateBuilder));
|
||||||
|
if (param == NULL) {
|
||||||
|
free(pInterSql);
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
char fullName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||||
|
extractDBName(pTableMetaInfo->name, fullName);
|
||||||
|
extractTableName(pMeta->sTableId, param->sTableName);
|
||||||
|
snprintf(fullName + strlen(fullName), TSDB_TABLE_FNAME_LEN - strlen(fullName), ".%s", param->sTableName);
|
||||||
|
extractTableName(pTableMetaInfo->name, param->buf);
|
||||||
|
|
||||||
|
param->pParentSql = pSql;
|
||||||
|
param->pInterSql = pInterSql;
|
||||||
|
param->fp = tscRebuildCreateTableStatement;
|
||||||
|
param->callStage = SCREATE_CALLBACK_QUERY;
|
||||||
|
|
||||||
|
char *query = (char *)calloc(1, TSDB_MAX_BINARY_LEN);
|
||||||
|
if (query == NULL) {
|
||||||
|
free(param);
|
||||||
|
free(pInterSql);
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *columns = NULL;
|
||||||
|
int32_t code = tscGetTableTagColumnName(pSql, &columns) ;
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
free(param);
|
||||||
|
free(pInterSql);
|
||||||
|
free(query);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(query + strlen(query), TSDB_MAX_BINARY_LEN - strlen(query), "SELECT %s FROM %s WHERE TBNAME IN(\'%s\')", columns, fullName, param->buf);
|
||||||
|
doAsyncQuery(pSql->pTscObj, pInterSql, tscSCreateCallBack, param, query, strlen(query));
|
||||||
|
free(query);
|
||||||
|
free(columns);
|
||||||
|
|
||||||
|
return TSDB_CODE_TSC_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
|
static int32_t tscRebuildDDLForNormalTable(SSqlObj *pSql, const char *tableName, char *ddl) {
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
|
||||||
|
int32_t numOfRows = tscGetNumOfColumns(pMeta);
|
||||||
|
SSchema *pSchema = tscGetTableSchema(pMeta);
|
||||||
|
|
||||||
|
char *result = ddl;
|
||||||
|
sprintf(result, "create table %s (", tableName);
|
||||||
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
|
uint8_t type = pSchema[i].type;
|
||||||
|
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s(%d),", pSchema[i].name,tDataTypeDesc[pSchema[i].type].aName,pSchema->bytes);
|
||||||
|
} else {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s,", pSchema[i].name, tDataTypeDesc[pSchema[i].type].aName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprintf(result + strlen(result) - 1, "%s", ")");
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
static int32_t tscRebuildDDLForSuperTable(SSqlObj *pSql, const char *tableName, char *ddl) {
|
||||||
|
char *result = ddl;
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
STableMeta * pMeta = pTableMetaInfo->pTableMeta;
|
||||||
|
|
||||||
|
int32_t numOfRows = tscGetNumOfColumns(pMeta);
|
||||||
|
int32_t totalRows = numOfRows + tscGetNumOfTags(pMeta);
|
||||||
|
SSchema *pSchema = tscGetTableSchema(pMeta);
|
||||||
|
|
||||||
|
sprintf(result, "create table %s (", tableName);
|
||||||
|
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||||
|
uint8_t type = pSchema[i].type;
|
||||||
|
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result),"%s %s(%d),", pSchema[i].name,tDataTypeDesc[pSchema[i].type].aName,pSchema->bytes);
|
||||||
|
} else {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s,", pSchema[i].name, tDataTypeDesc[type].aName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
snprintf(result + strlen(result) - 1, TSDB_MAX_BINARY_LEN - strlen(result), "%s %s", ")", "TAGS (");
|
||||||
|
|
||||||
|
for (int32_t i = numOfRows; i < totalRows; i++) {
|
||||||
|
uint8_t type = pSchema[i].type;
|
||||||
|
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s(%d),", pSchema[i].name,tDataTypeDesc[pSchema[i].type].aName,pSchema->bytes);
|
||||||
|
} else {
|
||||||
|
snprintf(result + strlen(result), TSDB_MAX_BINARY_LEN - strlen(result), "%s %s,", pSchema[i].name, tDataTypeDesc[type].aName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprintf(result + strlen(result) - 1, "%s", ")");
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tscProcessShowCreateTable(SSqlObj *pSql) {
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
assert(pTableMetaInfo->pTableMeta != NULL);
|
||||||
|
|
||||||
|
char tableName[TSDB_TABLE_NAME_LEN] = {0};
|
||||||
|
extractTableName(pTableMetaInfo->name, tableName);
|
||||||
|
|
||||||
|
char *result = (char *)calloc(1, TSDB_MAX_BINARY_LEN);
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
||||||
|
code = tscRebuildDDLForSuperTable(pSql, tableName, result);
|
||||||
|
} else if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) {
|
||||||
|
code = tscRebuildDDLForNormalTable(pSql, tableName, result);
|
||||||
|
} else if (UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo)) {
|
||||||
|
code = tscRebuildDDLForSubTable(pSql, tableName, result);
|
||||||
|
} else {
|
||||||
|
code = TSDB_CODE_TSC_INVALID_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
|
code = tscSCreateBuildResult(pSql, SCREATE_BUILD_TABLE, tableName, result);
|
||||||
|
}
|
||||||
|
free(result);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t tscProcessShowCreateDatabase(SSqlObj *pSql) {
|
||||||
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
|
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||||
|
|
||||||
|
SSqlObj *pInterSql = (SSqlObj *)calloc(1, sizeof(SSqlObj));
|
||||||
|
if (pInterSql == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
SCreateBuilder *param = (SCreateBuilder *)malloc(sizeof(SCreateBuilder));
|
||||||
|
if (param == NULL) {
|
||||||
|
free(pInterSql);
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
extractTableName(pTableMetaInfo->name, param->buf);
|
||||||
|
param->pParentSql = pSql;
|
||||||
|
param->pInterSql = pInterSql;
|
||||||
|
param->fp = tscRebuildCreateDBStatement;
|
||||||
|
param->callStage = SCREATE_CALLBACK_QUERY;
|
||||||
|
|
||||||
|
const char *query = "show databases";
|
||||||
|
doAsyncQuery(pSql->pTscObj, pInterSql, tscSCreateCallBack, param, query, strlen(query));
|
||||||
|
return TSDB_CODE_TSC_ACTION_IN_PROGRESS;
|
||||||
|
}
|
||||||
static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
pExpr->resBytes = TSDB_USER_LEN + TSDB_DATA_TYPE_BINARY;
|
pExpr->resBytes = TSDB_USER_LEN + TSDB_DATA_TYPE_BINARY;
|
||||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||||
|
|
||||||
char* vx = calloc(1, pExpr->resBytes);
|
char* vx = calloc(1, pExpr->resBytes);
|
||||||
if (vx == NULL) {
|
if (vx == NULL) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
@ -287,7 +807,7 @@ static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
||||||
|
|
||||||
size_t size = sizeof(pSql->pTscObj->user);
|
size_t size = sizeof(pSql->pTscObj->user);
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, size);
|
STR_WITH_MAXSIZE_TO_VARSTR(vx, pSql->pTscObj->user, size);
|
||||||
|
|
||||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
free(vx);
|
free(vx);
|
||||||
|
|
||||||
|
@ -297,15 +817,15 @@ static int32_t tscProcessCurrentUser(SSqlObj *pSql) {
|
||||||
static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
||||||
char db[TSDB_DB_NAME_LEN] = {0};
|
char db[TSDB_DB_NAME_LEN] = {0};
|
||||||
extractDBName(pSql->pTscObj->db, db);
|
extractDBName(pSql->pTscObj->db, db);
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||||
|
|
||||||
size_t t = strlen(db);
|
size_t t = strlen(db);
|
||||||
pExpr->resBytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE;
|
pExpr->resBytes = TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE;
|
||||||
|
|
||||||
char* vx = calloc(1, pExpr->resBytes);
|
char* vx = calloc(1, pExpr->resBytes);
|
||||||
if (vx == NULL) {
|
if (vx == NULL) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
@ -316,7 +836,7 @@ static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
||||||
} else {
|
} else {
|
||||||
STR_WITH_SIZE_TO_VARSTR(vx, db, (VarDataLenT)t);
|
STR_WITH_SIZE_TO_VARSTR(vx, db, (VarDataLenT)t);
|
||||||
}
|
}
|
||||||
|
|
||||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
free(vx);
|
free(vx);
|
||||||
|
|
||||||
|
@ -326,49 +846,53 @@ static int32_t tscProcessCurrentDB(SSqlObj *pSql) {
|
||||||
static int32_t tscProcessServerVer(SSqlObj *pSql) {
|
static int32_t tscProcessServerVer(SSqlObj *pSql) {
|
||||||
const char* v = pSql->pTscObj->sversion;
|
const char* v = pSql->pTscObj->sversion;
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, pSql->cmd.clauseIndex);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||||
|
|
||||||
size_t t = strlen(v);
|
size_t t = strlen(v);
|
||||||
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
||||||
|
|
||||||
char* vx = calloc(1, pExpr->resBytes);
|
char* vx = calloc(1, pExpr->resBytes);
|
||||||
if (vx == NULL) {
|
if (vx == NULL) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STR_WITH_SIZE_TO_VARSTR(vx, v, (VarDataLenT)t);
|
STR_WITH_SIZE_TO_VARSTR(vx, v, (VarDataLenT)t);
|
||||||
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
|
|
||||||
free(vx);
|
free(vx);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tscProcessClientVer(SSqlObj *pSql) {
|
static int32_t tscProcessClientVer(SSqlObj *pSql) {
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
pExpr->resType = TSDB_DATA_TYPE_BINARY;
|
||||||
|
|
||||||
size_t t = strlen(version);
|
size_t t = strlen(version);
|
||||||
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
pExpr->resBytes = (int16_t)(t + VARSTR_HEADER_SIZE);
|
||||||
|
|
||||||
char* v = calloc(1, pExpr->resBytes);
|
char* v = calloc(1, pExpr->resBytes);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
STR_WITH_SIZE_TO_VARSTR(v, version, (VarDataLenT)t);
|
STR_WITH_SIZE_TO_VARSTR(v, version, (VarDataLenT)t);
|
||||||
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes);
|
||||||
|
|
||||||
free(v);
|
free(v);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
||||||
STscObj* pObj = pSql->pTscObj;
|
STscObj* pObj = pSql->pTscObj;
|
||||||
|
|
||||||
if (pObj->pHb != NULL) {
|
if (pObj->pHb != NULL) {
|
||||||
if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
if (pObj->pHb->res.code == TSDB_CODE_RPC_NETWORK_UNAVAIL) {
|
||||||
pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
pSql->res.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||||
|
@ -379,9 +903,9 @@ static int32_t tscProcessServStatus(SSqlObj *pSql) {
|
||||||
return pSql->res.code;
|
return pSql->res.code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(&pSql->cmd, 0);
|
||||||
|
|
||||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
int32_t val = 1;
|
int32_t val = 1;
|
||||||
tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t));
|
tscSetLocalQueryResult(pSql, (char*) &val, pExpr->aliasName, TSDB_DATA_TYPE_INT, sizeof(int32_t));
|
||||||
|
@ -393,23 +917,23 @@ void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnNa
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
|
||||||
pCmd->numOfCols = 1;
|
pCmd->numOfCols = 1;
|
||||||
|
|
||||||
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
SQueryInfo* pQueryInfo = tscGetQueryInfoDetail(pCmd, pCmd->clauseIndex);
|
||||||
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
pQueryInfo->order.order = TSDB_ORDER_ASC;
|
||||||
|
|
||||||
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
tscFieldInfoClear(&pQueryInfo->fieldsInfo);
|
||||||
pQueryInfo->fieldsInfo.pFields = taosArrayInit(1, sizeof(TAOS_FIELD));
|
pQueryInfo->fieldsInfo.pFields = taosArrayInit(1, sizeof(TAOS_FIELD));
|
||||||
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(1, sizeof(SFieldSupInfo));
|
pQueryInfo->fieldsInfo.pSupportInfo = taosArrayInit(1, sizeof(SFieldSupInfo));
|
||||||
|
|
||||||
TAOS_FIELD f = tscCreateField((int8_t)type, columnName, (int16_t)valueLength);
|
TAOS_FIELD f = tscCreateField((int8_t)type, columnName, (int16_t)valueLength);
|
||||||
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
tscFieldInfoAppend(&pQueryInfo->fieldsInfo, &f);
|
||||||
|
|
||||||
tscInitResObjForLocalQuery(pSql, 1, (int32_t)valueLength);
|
tscInitResObjForLocalQuery(pSql, 1, (int32_t)valueLength);
|
||||||
|
|
||||||
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
TAOS_FIELD *pField = tscFieldInfoGetField(&pQueryInfo->fieldsInfo, 0);
|
||||||
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0);
|
SFieldSupInfo* pInfo = tscFieldInfoGetSupp(&pQueryInfo->fieldsInfo, 0);
|
||||||
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
pInfo->pSqlExpr = taosArrayGetP(pQueryInfo->exprList, 0);
|
||||||
|
|
||||||
memcpy(pRes->data, val, pField->bytes);
|
memcpy(pRes->data, val, pField->bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +952,10 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
|
||||||
*/
|
*/
|
||||||
pRes->qhandle = 0x1;
|
pRes->qhandle = 0x1;
|
||||||
pRes->numOfRows = 0;
|
pRes->numOfRows = 0;
|
||||||
|
} else if (pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE) {
|
||||||
|
pRes->code = tscProcessShowCreateTable(pSql);
|
||||||
|
} else if (pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE) {
|
||||||
|
pRes->code = tscProcessShowCreateDatabase(pSql);
|
||||||
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
} else if (pCmd->command == TSDB_SQL_RESET_CACHE) {
|
||||||
taosCacheEmpty(tscMetaCache);
|
taosCacheEmpty(tscMetaCache);
|
||||||
pRes->code = TSDB_CODE_SUCCESS;
|
pRes->code = TSDB_CODE_SUCCESS;
|
||||||
|
@ -447,12 +975,13 @@ int tscProcessLocalCmd(SSqlObj *pSql) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep the code in local variable in order to avoid invalid read in case of async query
|
// keep the code in local variable in order to avoid invalid read in case of async query
|
||||||
|
|
||||||
int32_t code = pRes->code;
|
int32_t code = pRes->code;
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
(*pSql->fp)(pSql->param, pSql, code);
|
(*pSql->fp)(pSql->param, pSql, code);
|
||||||
|
} else if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS){
|
||||||
} else {
|
} else {
|
||||||
tscQueueAsyncRes(pSql);
|
tscQueueAsyncRes(pSql);
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1192,8 +1192,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
|
||||||
str += index;
|
str += index;
|
||||||
|
|
||||||
if (TK_STRING == sToken.type) {
|
if (TK_STRING == sToken.type) {
|
||||||
strdequote(sToken.z);
|
tscDequoteAndTrimToken(&sToken);
|
||||||
sToken.n = (uint32_t)strtrim(sToken.z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sToken.type == TK_RP) {
|
if (sToken.type == TK_RP) {
|
||||||
|
|
|
@ -368,7 +368,40 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
|
||||||
|
|
||||||
return tscGetTableMeta(pSql, pTableMetaInfo);
|
return tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
}
|
}
|
||||||
|
case TSDB_SQL_SHOW_CREATE_TABLE: {
|
||||||
|
SStrToken* pToken = &pInfo->pDCLInfo->a[0];
|
||||||
|
const char* msg1 = "invalid table name";
|
||||||
|
const char* msg2 = "table name is too long";
|
||||||
|
|
||||||
|
if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!tscValidateTableNameLength(pToken->n)) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tscSetTableFullName(pTableMetaInfo, pToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
|
}
|
||||||
|
return tscGetTableMeta(pSql, pTableMetaInfo);
|
||||||
|
}
|
||||||
|
case TSDB_SQL_SHOW_CREATE_DATABASE: {
|
||||||
|
const char* msg1 = "invalid database name";
|
||||||
|
const char* msg2 = "table name is too long";
|
||||||
|
SStrToken* pToken = &pInfo->pDCLInfo->a[0];
|
||||||
|
|
||||||
|
if (tscValidateName(pToken) != TSDB_CODE_SUCCESS) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
|
}
|
||||||
|
if (pToken->n > TSDB_DB_NAME_LEN) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||||
|
}
|
||||||
|
if (tscSetTableFullName(pTableMetaInfo, pToken, pSql) != TSDB_CODE_SUCCESS) {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
|
||||||
|
}
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
case TSDB_SQL_CFG_DNODE: {
|
case TSDB_SQL_CFG_DNODE: {
|
||||||
const char* msg2 = "invalid configure options or values, such as resetlog / debugFlag 135 / balance 'vnode:2-dnode:2' / monitor 1 ";
|
const char* msg2 = "invalid configure options or values, such as resetlog / debugFlag 135 / balance 'vnode:2-dnode:2' / monitor 1 ";
|
||||||
const char* msg3 = "invalid dnode ep";
|
const char* msg3 = "invalid dnode ep";
|
||||||
|
@ -5722,7 +5755,7 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) {
|
||||||
char msg[512] = {0};
|
char msg[512] = {0};
|
||||||
|
|
||||||
if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
|
if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
|
||||||
snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 0-2 allowed", pCreate->walLevel);
|
snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel);
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,6 +170,7 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
|
||||||
|
|
||||||
pTableMeta->sversion = pTableMetaMsg->sversion;
|
pTableMeta->sversion = pTableMetaMsg->sversion;
|
||||||
pTableMeta->tversion = pTableMetaMsg->tversion;
|
pTableMeta->tversion = pTableMetaMsg->tversion;
|
||||||
|
tstrncpy(pTableMeta->sTableId, pTableMetaMsg->sTableId, TSDB_TABLE_FNAME_LEN);
|
||||||
|
|
||||||
memcpy(pTableMeta->schema, pTableMetaMsg->schema, schemaSize);
|
memcpy(pTableMeta->schema, pTableMetaMsg->schema, schemaSize);
|
||||||
|
|
||||||
|
|
|
@ -2093,6 +2093,9 @@ int tscProcessAlterDbMsgRsp(SSqlObj *pSql) {
|
||||||
UNUSED(pSql);
|
UNUSED(pSql);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int tscProcessShowCreateRsp(SSqlObj *pSql) {
|
||||||
|
return tscLocalResultCommonBuilder(pSql, 1);
|
||||||
|
}
|
||||||
|
|
||||||
int tscProcessQueryRsp(SSqlObj *pSql) {
|
int tscProcessQueryRsp(SSqlObj *pSql) {
|
||||||
SSqlRes *pRes = &pSql->res;
|
SSqlRes *pRes = &pSql->res;
|
||||||
|
@ -2379,6 +2382,10 @@ void tscInitMsgsFp() {
|
||||||
tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp;
|
tscProcessMsgRsp[TSDB_SQL_ALTER_TABLE] = tscProcessAlterTableMsgRsp;
|
||||||
tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp;
|
tscProcessMsgRsp[TSDB_SQL_ALTER_DB] = tscProcessAlterDbMsgRsp;
|
||||||
|
|
||||||
|
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_TABLE] = tscProcessShowCreateRsp;
|
||||||
|
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp;
|
||||||
|
|
||||||
|
|
||||||
tscKeepConn[TSDB_SQL_SHOW] = 1;
|
tscKeepConn[TSDB_SQL_SHOW] = 1;
|
||||||
tscKeepConn[TSDB_SQL_RETRIEVE] = 1;
|
tscKeepConn[TSDB_SQL_RETRIEVE] = 1;
|
||||||
tscKeepConn[TSDB_SQL_SELECT] = 1;
|
tscKeepConn[TSDB_SQL_SELECT] = 1;
|
||||||
|
|
|
@ -264,12 +264,13 @@ void taos_close(TAOS *taos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSqlObj* pHb = pObj->pHb;
|
SSqlObj* pHb = pObj->pHb;
|
||||||
if (pHb != NULL) {
|
if (pHb != NULL && atomic_val_compare_exchange_ptr(&pObj->pHb, pHb, 0) == pHb) {
|
||||||
if (pHb->pRpcCtx != NULL) { // wait for rsp from dnode
|
if (pHb->pRpcCtx != NULL) { // wait for rsp from dnode
|
||||||
rpcCancelRequest(pHb->pRpcCtx);
|
rpcCancelRequest(pHb->pRpcCtx);
|
||||||
|
pHb->pRpcCtx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj->pHb = NULL;
|
tscDebug("%p, HB is freed", pHb);
|
||||||
taos_free_result(pHb);
|
taos_free_result(pHb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,6 +477,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
||||||
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
|
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
|
||||||
pCmd->command == TSDB_SQL_FETCH ||
|
pCmd->command == TSDB_SQL_FETCH ||
|
||||||
pCmd->command == TSDB_SQL_SHOW ||
|
pCmd->command == TSDB_SQL_SHOW ||
|
||||||
|
pCmd->command == TSDB_SQL_SHOW_CREATE_TABLE ||
|
||||||
|
pCmd->command == TSDB_SQL_SHOW_CREATE_DATABASE ||
|
||||||
pCmd->command == TSDB_SQL_SELECT ||
|
pCmd->command == TSDB_SQL_SELECT ||
|
||||||
pCmd->command == TSDB_SQL_DESCRIBE_TABLE ||
|
pCmd->command == TSDB_SQL_DESCRIBE_TABLE ||
|
||||||
pCmd->command == TSDB_SQL_SERV_STATUS ||
|
pCmd->command == TSDB_SQL_SERV_STATUS ||
|
||||||
|
|
|
@ -136,7 +136,6 @@ static void tscProcessStreamTimer(void *handle, void *tmrId) {
|
||||||
etime = pStream->stime + (etime - pStream->stime) / pStream->interval.interval * pStream->interval.interval;
|
etime = pStream->stime + (etime - pStream->stime) / pStream->interval.interval * pStream->interval.interval;
|
||||||
} else {
|
} else {
|
||||||
etime = taosTimeTruncate(etime, &pStream->interval, pStream->precision);
|
etime = taosTimeTruncate(etime, &pStream->interval, pStream->precision);
|
||||||
//etime = taosGetIntervalStartTimestamp(etime, pStream->interval.sliding, pStream->interval.sliding, pStream->interval.slidingUnit, pStream->precision);
|
|
||||||
}
|
}
|
||||||
pQueryInfo->window.ekey = etime;
|
pQueryInfo->window.ekey = etime;
|
||||||
if (pQueryInfo->window.skey >= pQueryInfo->window.ekey) {
|
if (pQueryInfo->window.skey >= pQueryInfo->window.ekey) {
|
||||||
|
@ -454,17 +453,11 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
|
||||||
}
|
}
|
||||||
} else { // timewindow based aggregation stream
|
} else { // timewindow based aggregation stream
|
||||||
if (stime == 0) { // no data in meter till now
|
if (stime == 0) { // no data in meter till now
|
||||||
stime = pQueryInfo->window.skey;
|
if (pQueryInfo->window.skey != INT64_MIN) {
|
||||||
if (stime == INT64_MIN) {
|
stime = pQueryInfo->window.skey;
|
||||||
stime = (int64_t)taosGetTimestamp(pStream->precision);
|
|
||||||
stime = taosTimeTruncate(stime, &pStream->interval, pStream->precision);
|
|
||||||
stime = taosTimeTruncate(stime - 1, &pStream->interval, pStream->precision);
|
|
||||||
//stime = taosGetIntervalStartTimestamp(stime, pStream->interval.interval, pStream->interval.interval, pStream->interval.intervalUnit, pStream->precision);
|
|
||||||
//stime = taosGetIntervalStartTimestamp(stime - 1, pStream->interval.interval, pStream->interval.interval, pStream->interval.intervalUnit, pStream->precision);
|
|
||||||
tscWarn("%p stream:%p, last timestamp:0, reset to:%" PRId64, pSql, pStream, stime);
|
|
||||||
}
|
}
|
||||||
|
stime = taosTimeTruncate(stime, &pStream->interval, pStream->precision);
|
||||||
} else {
|
} else {
|
||||||
//int64_t newStime = taosGetIntervalStartTimestamp(stime, pStream->interval.interval, pStream->interval.interval, pStream->interval.intervalUnit, pStream->precision);
|
|
||||||
int64_t newStime = taosTimeTruncate(stime, &pStream->interval, pStream->precision);
|
int64_t newStime = taosTimeTruncate(stime, &pStream->interval, pStream->precision);
|
||||||
if (newStime != stime) {
|
if (newStime != stime) {
|
||||||
tscWarn("%p stream:%p, last timestamp:%" PRId64 ", reset to:%" PRId64, pSql, pStream, stime, newStime);
|
tscWarn("%p stream:%p, last timestamp:%" PRId64 ", reset to:%" PRId64, pSql, pStream, stime, newStime);
|
||||||
|
@ -477,8 +470,10 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) {
|
static int64_t tscGetLaunchTimestamp(const SSqlStream *pStream) {
|
||||||
int64_t timer = pStream->stime - taosGetTimestamp(pStream->precision);
|
int64_t timer = 0, now = taosGetTimestamp(pStream->precision);
|
||||||
if (timer < 0) timer = 0;
|
if (pStream->stime > now) {
|
||||||
|
timer = pStream->stime - now;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t startDelay =
|
int64_t startDelay =
|
||||||
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsStreamCompStartDelay * 1000L : tsStreamCompStartDelay;
|
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsStreamCompStartDelay * 1000L : tsStreamCompStartDelay;
|
||||||
|
@ -572,6 +567,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
pStream->pSql = pSql;
|
pStream->pSql = pSql;
|
||||||
pSql->pStream = pStream;
|
pSql->pStream = pStream;
|
||||||
pSql->param = pStream;
|
pSql->param = pStream;
|
||||||
|
pSql->maxRetry = TSDB_MAX_REPLICA;
|
||||||
|
|
||||||
pSql->sqlstr = calloc(1, strlen(sqlstr) + 1);
|
pSql->sqlstr = calloc(1, strlen(sqlstr) + 1);
|
||||||
if (pSql->sqlstr == NULL) {
|
if (pSql->sqlstr == NULL) {
|
||||||
|
@ -579,6 +575,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
|
||||||
tscFreeSqlObj(pSql);
|
tscFreeSqlObj(pSql);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strtolower(pSql->sqlstr, sqlstr);
|
strtolower(pSql->sqlstr, sqlstr);
|
||||||
|
|
||||||
tscDebugL("%p SQL: %s", pSql, pSql->sqlstr);
|
tscDebugL("%p SQL: %s", pSql, pSql->sqlstr);
|
||||||
|
@ -619,10 +616,9 @@ void taos_close_stream(TAOS_STREAM *handle) {
|
||||||
tscDebug("%p stream:%p is closed", pSql, pStream);
|
tscDebug("%p stream:%p is closed", pSql, pStream);
|
||||||
// notify CQ to release the pStream object
|
// notify CQ to release the pStream object
|
||||||
pStream->fp(pStream->param, NULL, NULL);
|
pStream->fp(pStream->param, NULL, NULL);
|
||||||
|
|
||||||
taos_free_result(pSql);
|
|
||||||
pStream->pSql = NULL;
|
pStream->pSql = NULL;
|
||||||
|
|
||||||
|
taos_free_result(pSql);
|
||||||
taosTFree(pStream);
|
taosTFree(pStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "tscSubquery.h"
|
#include "tscSubquery.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
|
|
||||||
typedef struct SInsertSupporter {
|
typedef struct SInsertSupporter {
|
||||||
SSubqueryState* pState;
|
SSubqueryState* pState;
|
||||||
|
@ -278,7 +279,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
||||||
tscDebug("%p subIndex: %d, no need to launch query, ignore it", pSql, i);
|
tscDebug("%p subIndex: %d, no need to launch query, ignore it", pSql, i);
|
||||||
|
|
||||||
tscDestroyJoinSupporter(pSupporter);
|
tscDestroyJoinSupporter(pSupporter);
|
||||||
tscFreeSqlObj(pPrevSub);
|
taos_free_result(pPrevSub);
|
||||||
|
|
||||||
pSql->pSubs[i] = NULL;
|
pSql->pSubs[i] = NULL;
|
||||||
continue;
|
continue;
|
||||||
|
@ -1383,7 +1384,7 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState
|
||||||
taosTFree(pSupport->localBuffer);
|
taosTFree(pSupport->localBuffer);
|
||||||
taosTFree(pSupport);
|
taosTFree(pSupport);
|
||||||
|
|
||||||
tscFreeSqlObj(pSub);
|
taos_free_result(pSub);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(pState);
|
free(pState);
|
||||||
|
|
|
@ -1265,6 +1265,51 @@ static int32_t validateQuoteToken(SStrToken* pToken) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tscDequoteAndTrimToken(SStrToken* pToken) {
|
||||||
|
assert(pToken->type == TK_STRING);
|
||||||
|
|
||||||
|
uint32_t first = 0, last = pToken->n;
|
||||||
|
|
||||||
|
// trim leading spaces
|
||||||
|
while (first < last) {
|
||||||
|
char c = pToken->z[first];
|
||||||
|
if (c != ' ' && c != '\t') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
first++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// trim ending spaces
|
||||||
|
while (first < last) {
|
||||||
|
char c = pToken->z[last - 1];
|
||||||
|
if (c != ' ' && c != '\t') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
last--;
|
||||||
|
}
|
||||||
|
|
||||||
|
// there are still at least two characters
|
||||||
|
if (first < last - 1) {
|
||||||
|
char c = pToken->z[first];
|
||||||
|
// dequote
|
||||||
|
if ((c == '\'' || c == '"') && c == pToken->z[last - 1]) {
|
||||||
|
first++;
|
||||||
|
last--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// left shift the string and pad spaces
|
||||||
|
for (uint32_t i = 0; i + first < last; i++) {
|
||||||
|
pToken->z[i] = pToken->z[first + i];
|
||||||
|
}
|
||||||
|
for (uint32_t i = last - first; i < pToken->n; i++) {
|
||||||
|
pToken->z[i] = ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
// adjust token length
|
||||||
|
pToken->n = last - first;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t tscValidateName(SStrToken* pToken) {
|
int32_t tscValidateName(SStrToken* pToken) {
|
||||||
if (pToken->type != TK_STRING && pToken->type != TK_ID) {
|
if (pToken->type != TK_STRING && pToken->type != TK_ID) {
|
||||||
return TSDB_CODE_TSC_INVALID_SQL;
|
return TSDB_CODE_TSC_INVALID_SQL;
|
||||||
|
@ -1743,13 +1788,12 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm
|
||||||
}
|
}
|
||||||
|
|
||||||
pNew->pTscObj = pSql->pTscObj;
|
pNew->pTscObj = pSql->pTscObj;
|
||||||
T_REF_INC(pNew->pTscObj);
|
|
||||||
|
|
||||||
pNew->signature = pNew;
|
pNew->signature = pNew;
|
||||||
|
|
||||||
SSqlCmd* pCmd = &pNew->cmd;
|
SSqlCmd* pCmd = &pNew->cmd;
|
||||||
pCmd->command = cmd;
|
pCmd->command = cmd;
|
||||||
pCmd->parseFinished = 1;
|
pCmd->parseFinished = 1;
|
||||||
|
pCmd->autoCreated = pSql->cmd.autoCreated;
|
||||||
|
|
||||||
if (tscAddSubqueryInfo(pCmd) != TSDB_CODE_SUCCESS) {
|
if (tscAddSubqueryInfo(pCmd) != TSDB_CODE_SUCCESS) {
|
||||||
tscFreeSqlObj(pNew);
|
tscFreeSqlObj(pNew);
|
||||||
|
@ -1777,7 +1821,6 @@ SSqlObj* createSimpleSubObj(SSqlObj* pSql, void (*fp)(), void* param, int32_t cm
|
||||||
tscAddTableMetaInfo(pQueryInfo, pMasterTableMetaInfo->name, NULL, NULL, NULL);
|
tscAddTableMetaInfo(pQueryInfo, pMasterTableMetaInfo->name, NULL, NULL, NULL);
|
||||||
|
|
||||||
T_REF_INC(pNew->pTscObj);
|
T_REF_INC(pNew->pTscObj);
|
||||||
|
|
||||||
uint64_t p = (uint64_t) pNew;
|
uint64_t p = (uint64_t) pNew;
|
||||||
pNew->self = taosCachePut(tscObjCache, &p, sizeof(uint64_t), &pNew, sizeof(uint64_t), 2 * 600 * 1000);
|
pNew->self = taosCachePut(tscObjCache, &p, sizeof(uint64_t), &pNew, sizeof(uint64_t), 2 * 600 * 1000);
|
||||||
return pNew;
|
return pNew;
|
||||||
|
@ -1869,7 +1912,6 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, void (*fp)(), void
|
||||||
|
|
||||||
pNew->pTscObj = pSql->pTscObj;
|
pNew->pTscObj = pSql->pTscObj;
|
||||||
pNew->signature = pNew;
|
pNew->signature = pNew;
|
||||||
T_REF_INC(pNew->pTscObj);
|
|
||||||
|
|
||||||
pNew->sqlstr = strdup(pSql->sqlstr);
|
pNew->sqlstr = strdup(pSql->sqlstr);
|
||||||
if (pNew->sqlstr == NULL) {
|
if (pNew->sqlstr == NULL) {
|
||||||
|
|
|
@ -78,6 +78,9 @@ enum {
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_LOCALMERGE, "retrieve-localmerge" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_LOCALMERGE, "retrieve-localmerge" )
|
||||||
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_TABLE_JOIN_RETRIEVE, "join-retrieve" )
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_TABLE_JOIN_RETRIEVE, "join-retrieve" )
|
||||||
|
|
||||||
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_TABLE, "show-create-table")
|
||||||
|
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW_CREATE_DATABASE, "show-create-database")
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* build empty result instead of accessing dnode to fetch result
|
* build empty result instead of accessing dnode to fetch result
|
||||||
* reset the client cache
|
* reset the client cache
|
||||||
|
|
|
@ -131,7 +131,7 @@ uint16_t tsHttpPort = 6041; // only tcp, range tcp[6041]
|
||||||
int32_t tsHttpCacheSessions = 1000;
|
int32_t tsHttpCacheSessions = 1000;
|
||||||
int32_t tsHttpSessionExpire = 36000;
|
int32_t tsHttpSessionExpire = 36000;
|
||||||
int32_t tsHttpMaxThreads = 2;
|
int32_t tsHttpMaxThreads = 2;
|
||||||
int32_t tsHttpEnableCompress = 0;
|
int32_t tsHttpEnableCompress = 1;
|
||||||
int32_t tsHttpEnableRecordSql = 0;
|
int32_t tsHttpEnableRecordSql = 0;
|
||||||
int32_t tsTelegrafUseFieldNum = 0;
|
int32_t tsTelegrafUseFieldNum = 0;
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8c58c512b6acda8bcdfa48fdc7140227b5221766
|
Subproject commit 06ec30a0f1762e8169bf6b9045c82bcaa52bcdf0
|
|
@ -5,10 +5,9 @@
|
||||||
|
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.6</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
<name>JDBCDriver</name>
|
<name>JDBCDriver</name>
|
||||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||||
<description>TDengine JDBC Driver</description>
|
<description>TDengine JDBC Driver</description>
|
||||||
|
|
|
@ -291,8 +291,8 @@ public class TSDBDriver implements java.sql.Driver {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String lowerUrl = url.toLowerCase();
|
// String lowerUrl = url.toLowerCase();
|
||||||
if (!lowerUrl.startsWith(URL_PREFIX) && !lowerUrl.startsWith(URL_PREFIX1)) {
|
if (!url.startsWith(URL_PREFIX) && !url.startsWith(URL_PREFIX1)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -673,6 +673,7 @@ typedef struct {
|
||||||
typedef struct STableMetaMsg {
|
typedef struct STableMetaMsg {
|
||||||
int32_t contLen;
|
int32_t contLen;
|
||||||
char tableId[TSDB_TABLE_FNAME_LEN]; // table id
|
char tableId[TSDB_TABLE_FNAME_LEN]; // table id
|
||||||
|
char sTableId[TSDB_TABLE_FNAME_LEN];
|
||||||
uint8_t numOfTags;
|
uint8_t numOfTags;
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
uint8_t tableType;
|
uint8_t tableType;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#ifndef TDENGINE_TTOKENDEF_H
|
#ifndef TDENGINE_TTOKENDEF_H
|
||||||
#define TDENGINE_TTOKENDEF_H
|
#define TDENGINE_TTOKENDEF_H
|
||||||
|
|
||||||
|
|
||||||
#define TK_ID 1
|
#define TK_ID 1
|
||||||
#define TK_BOOL 2
|
#define TK_BOOL 2
|
||||||
#define TK_TINYINT 3
|
#define TK_TINYINT 3
|
||||||
|
@ -75,24 +76,24 @@
|
||||||
#define TK_VNODES 57
|
#define TK_VNODES 57
|
||||||
#define TK_IPTOKEN 58
|
#define TK_IPTOKEN 58
|
||||||
#define TK_DOT 59
|
#define TK_DOT 59
|
||||||
#define TK_TABLES 60
|
#define TK_CREATE 60
|
||||||
#define TK_STABLES 61
|
#define TK_TABLE 61
|
||||||
#define TK_VGROUPS 62
|
#define TK_DATABASE 62
|
||||||
#define TK_DROP 63
|
#define TK_TABLES 63
|
||||||
#define TK_TABLE 64
|
#define TK_STABLES 64
|
||||||
#define TK_DATABASE 65
|
#define TK_VGROUPS 65
|
||||||
#define TK_DNODE 66
|
#define TK_DROP 66
|
||||||
#define TK_USER 67
|
#define TK_DNODE 67
|
||||||
#define TK_ACCOUNT 68
|
#define TK_USER 68
|
||||||
#define TK_USE 69
|
#define TK_ACCOUNT 69
|
||||||
#define TK_DESCRIBE 70
|
#define TK_USE 70
|
||||||
#define TK_ALTER 71
|
#define TK_DESCRIBE 71
|
||||||
#define TK_PASS 72
|
#define TK_ALTER 72
|
||||||
#define TK_PRIVILEGE 73
|
#define TK_PASS 73
|
||||||
#define TK_LOCAL 74
|
#define TK_PRIVILEGE 74
|
||||||
#define TK_IF 75
|
#define TK_LOCAL 75
|
||||||
#define TK_EXISTS 76
|
#define TK_IF 76
|
||||||
#define TK_CREATE 77
|
#define TK_EXISTS 77
|
||||||
#define TK_PPS 78
|
#define TK_PPS 78
|
||||||
#define TK_TSERIES 79
|
#define TK_TSERIES 79
|
||||||
#define TK_DBS 80
|
#define TK_DBS 80
|
||||||
|
@ -222,7 +223,6 @@
|
||||||
#define TK_INTO 204
|
#define TK_INTO 204
|
||||||
#define TK_VALUES 205
|
#define TK_VALUES 205
|
||||||
|
|
||||||
|
|
||||||
#define TK_SPACE 300
|
#define TK_SPACE 300
|
||||||
#define TK_COMMENT 301
|
#define TK_COMMENT 301
|
||||||
#define TK_ILLEGAL 302
|
#define TK_ILLEGAL 302
|
||||||
|
|
|
@ -44,6 +44,7 @@ typedef void* twalh; // WAL HANDLE
|
||||||
typedef int (*FWalWrite)(void *ahandle, void *pHead, int type);
|
typedef int (*FWalWrite)(void *ahandle, void *pHead, int type);
|
||||||
|
|
||||||
twalh walOpen(const char *path, const SWalCfg *pCfg);
|
twalh walOpen(const char *path, const SWalCfg *pCfg);
|
||||||
|
int walAlter(twalh pWal, const SWalCfg *pCfg);
|
||||||
void walClose(twalh);
|
void walClose(twalh);
|
||||||
int walRenew(twalh);
|
int walRenew(twalh);
|
||||||
int walWrite(twalh, SWalHead *);
|
int walWrite(twalh, SWalHead *);
|
||||||
|
|
|
@ -910,13 +910,13 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (walLevel > 0 && walLevel != pDb->cfg.walLevel) {
|
if (walLevel > 0 && walLevel != pDb->cfg.walLevel) {
|
||||||
mError("db:%s, can't alter walLevel option", pDb->name);
|
mDebug("db:%s, walLevel:%d change to %d", pDb->name, pDb->cfg.walLevel, walLevel);
|
||||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
newCfg.walLevel = walLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fsyncPeriod >= 0 && fsyncPeriod != pDb->cfg.fsyncPeriod) {
|
if (fsyncPeriod >= 0 && fsyncPeriod != pDb->cfg.fsyncPeriod) {
|
||||||
mError("db:%s, can't alter fsyncPeriod option", pDb->name);
|
mDebug("db:%s, fsyncPeriod:%d change to %d", pDb->name, pDb->cfg.fsyncPeriod, fsyncPeriod);
|
||||||
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
|
newCfg.fsyncPeriod = fsyncPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (replications > 0 && replications != pDb->cfg.replications) {
|
if (replications > 0 && replications != pDb->cfg.replications) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ int32_t mnodeInitShow() {
|
||||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg);
|
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_CONNECT, mnodeProcessConnectMsg);
|
||||||
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg);
|
mnodeAddReadMsgHandle(TSDB_MSG_TYPE_CM_USE_DB, mnodeProcessUseMsg);
|
||||||
|
|
||||||
tsMnodeShowCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, 5, false, mnodeFreeShowObj, "show");
|
tsMnodeShowCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, 5, true, mnodeFreeShowObj, "show");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,10 +389,12 @@ static bool mnodeAccquireShowObj(SShowObj *pShow) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void* mnodePutShowObj(SShowObj *pShow) {
|
static void* mnodePutShowObj(SShowObj *pShow) {
|
||||||
|
const int32_t DEFAULT_SHOWHANDLE_LIFE_SPAN = tsShellActivityTimer * 6 * 1000;
|
||||||
|
|
||||||
if (tsMnodeShowCache != NULL) {
|
if (tsMnodeShowCache != NULL) {
|
||||||
pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1);
|
pShow->index = atomic_add_fetch_32(&tsShowObjIndex, 1);
|
||||||
uint64_t handleVal = (uint64_t)pShow;
|
uint64_t handleVal = (uint64_t)pShow;
|
||||||
SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &handleVal, sizeof(int64_t), &pShow, sizeof(int64_t), 6000);
|
SShowObj **ppShow = taosCachePut(tsMnodeShowCache, &handleVal, sizeof(int64_t), &pShow, sizeof(int64_t), DEFAULT_SHOWHANDLE_LIFE_SPAN);
|
||||||
pShow->ppShow = (void**)ppShow;
|
pShow->ppShow = (void**)ppShow;
|
||||||
mDebug("%p, show is put into cache, data:%p index:%d", pShow, ppShow, pShow->index);
|
mDebug("%p, show is put into cache, data:%p index:%d", pShow, ppShow, pShow->index);
|
||||||
return pShow;
|
return pShow;
|
||||||
|
|
|
@ -1384,6 +1384,9 @@ int32_t mnodeRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows,
|
||||||
}
|
}
|
||||||
|
|
||||||
pShow->numOfReads += numOfRows;
|
pShow->numOfReads += numOfRows;
|
||||||
|
const int32_t NUM_OF_COLUMNS = 5;
|
||||||
|
|
||||||
|
mnodeVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow);
|
||||||
mnodeDecDbRef(pDb);
|
mnodeDecDbRef(pDb);
|
||||||
|
|
||||||
return numOfRows;
|
return numOfRows;
|
||||||
|
@ -2090,6 +2093,9 @@ static int32_t mnodeDoGetChildTableMeta(SMnodeMsg *pMsg, STableMetaMsg *pMeta) {
|
||||||
pMeta->precision = pDb->cfg.precision;
|
pMeta->precision = pDb->cfg.precision;
|
||||||
pMeta->tableType = pTable->info.type;
|
pMeta->tableType = pTable->info.type;
|
||||||
tstrncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_FNAME_LEN);
|
tstrncpy(pMeta->tableId, pTable->info.tableId, TSDB_TABLE_FNAME_LEN);
|
||||||
|
if (pTable->superTable) {
|
||||||
|
tstrncpy(pMeta->sTableId, pTable->superTable->info.tableId, TSDB_TABLE_FNAME_LEN);
|
||||||
|
}
|
||||||
|
|
||||||
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
if (pTable->info.type == TSDB_CHILD_TABLE) {
|
||||||
pMeta->sversion = htons(pTable->superTable->sversion);
|
pMeta->sversion = htons(pTable->superTable->sversion);
|
||||||
|
|
|
@ -660,13 +660,13 @@ static int32_t mnodeGetVgroupMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *p
|
||||||
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
|
for (int32_t i = 0; i < pShow->maxReplica; ++i) {
|
||||||
pShow->bytes[cols] = 2;
|
pShow->bytes[cols] = 2;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||||
strcpy(pSchema[cols].name, "dnode");
|
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "dnode%d", i + 1);
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
|
|
||||||
pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE;
|
pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE;
|
||||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||||
strcpy(pSchema[cols].name, "vstatus");
|
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%dstatus", i + 1);
|
||||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||||
cols++;
|
cols++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#define JSON_BUFFER_SIZE 10240
|
#define JSON_BUFFER_SIZE 16384
|
||||||
struct HttpContext;
|
struct HttpContext;
|
||||||
|
|
||||||
enum { JsonNumber, JsonString, JsonBoolean, JsonArray, JsonObject, JsonNull };
|
enum { JsonNumber, JsonString, JsonBoolean, JsonArray, JsonObject, JsonNull };
|
||||||
|
|
|
@ -52,12 +52,12 @@ int32_t httpWriteBufByFd(struct HttpContext* pContext, const char* buf, int32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < 0) {
|
if (len < 0) {
|
||||||
httpDebug("context:%p, fd:%d, socket write errno:%d, times:%d", pContext, pContext->fd, errno, countWait);
|
httpDebug("context:%p, fd:%d, socket write errno:%d:%s, times:%d", pContext, pContext->fd, errno, strerror(errno), countWait);
|
||||||
if (++countWait > HTTP_WRITE_RETRY_TIMES) break;
|
if (++countWait > HTTP_WRITE_RETRY_TIMES) break;
|
||||||
taosMsleep(HTTP_WRITE_WAIT_TIME_MS);
|
taosMsleep(HTTP_WRITE_WAIT_TIME_MS);
|
||||||
continue;
|
continue;
|
||||||
} else if (len == 0) {
|
} else if (len == 0) {
|
||||||
httpDebug("context:%p, fd:%d, socket write errno:%d, connect already closed", pContext, pContext->fd, errno);
|
httpDebug("context:%p, fd:%d, socket write errno:%d:%s, connect already closed", pContext, pContext->fd, errno, strerror(errno));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
countWait = 0;
|
countWait = 0;
|
||||||
|
@ -131,14 +131,14 @@ int32_t httpWriteJsonBufBody(JsonBuf* buf, bool isTheLast) {
|
||||||
httpWriteBufNoTrace(buf->pContext, sLen, len);
|
httpWriteBufNoTrace(buf->pContext, sLen, len);
|
||||||
remain = httpWriteBufNoTrace(buf->pContext, (const char*)compressBuf, compressBufLen);
|
remain = httpWriteBufNoTrace(buf->pContext, (const char*)compressBuf, compressBufLen);
|
||||||
} else {
|
} else {
|
||||||
httpTrace("context:%p, fd:%d, last:%d, compress already dumped, response:\n%s", buf->pContext,
|
httpDebug("context:%p, fd:%d, last:%d, compress already dumped, response:\n%s", buf->pContext,
|
||||||
buf->pContext->fd, isTheLast, buf->buf);
|
buf->pContext->fd, isTheLast, buf->buf);
|
||||||
return 0; // there is no data to dump.
|
remain = 0; // there is no data to dump.
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
httpError("context:%p, fd:%d, failed to compress data, chunkSize:%" PRIu64 ", last:%d, error:%d, response:\n%s",
|
httpError("context:%p, fd:%d, failed to compress data, chunkSize:%" PRIu64 ", last:%d, error:%d, response:\n%s",
|
||||||
buf->pContext, buf->pContext->fd, srcLen, isTheLast, ret, buf->buf);
|
buf->pContext, buf->pContext->fd, srcLen, isTheLast, ret, buf->buf);
|
||||||
return 0;
|
remain = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -406,15 +406,21 @@ int32_t httpGzipCompressInit(HttpContext *pContext) {
|
||||||
|
|
||||||
int32_t httpGzipCompress(HttpContext *pContext, char *srcData, int32_t nSrcData, char *destData, int32_t *nDestData, bool isTheLast) {
|
int32_t httpGzipCompress(HttpContext *pContext, char *srcData, int32_t nSrcData, char *destData, int32_t *nDestData, bool isTheLast) {
|
||||||
int32_t err = 0;
|
int32_t err = 0;
|
||||||
|
int32_t lastTotalLen = (int32_t) (pContext->gzipStream.total_out);
|
||||||
pContext->gzipStream.next_in = (Bytef *) srcData;
|
pContext->gzipStream.next_in = (Bytef *) srcData;
|
||||||
pContext->gzipStream.avail_in = (uLong) nSrcData;
|
pContext->gzipStream.avail_in = (uLong) nSrcData;
|
||||||
pContext->gzipStream.next_out = (Bytef *) destData;
|
pContext->gzipStream.next_out = (Bytef *) destData;
|
||||||
pContext->gzipStream.avail_out = (uLong) (*nDestData);
|
pContext->gzipStream.avail_out = (uLong) (*nDestData);
|
||||||
|
|
||||||
while (pContext->gzipStream.avail_in != 0 && pContext->gzipStream.total_out < (uLong) (*nDestData)) {
|
while (pContext->gzipStream.avail_in != 0) {
|
||||||
if (deflate(&pContext->gzipStream, Z_FULL_FLUSH) != Z_OK) {
|
if (deflate(&pContext->gzipStream, Z_FULL_FLUSH) != Z_OK) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t cacheLen = pContext->gzipStream.total_out - lastTotalLen;
|
||||||
|
if (cacheLen >= *nDestData) {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pContext->gzipStream.avail_in != 0) {
|
if (pContext->gzipStream.avail_in != 0) {
|
||||||
|
@ -427,16 +433,16 @@ int32_t httpGzipCompress(HttpContext *pContext, char *srcData, int32_t nSrcData,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (err != Z_OK) {
|
if (err != Z_OK) {
|
||||||
return -2;
|
return -3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deflateEnd(&pContext->gzipStream) != Z_OK) {
|
if (deflateEnd(&pContext->gzipStream) != Z_OK) {
|
||||||
return -3;
|
return -4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*nDestData = (int32_t) (pContext->gzipStream.total_out);
|
*nDestData = (int32_t) (pContext->gzipStream.total_out) - lastTotalLen;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0);
|
||||||
cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
|
cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
|
||||||
cmd ::= SHOW VNODES IPTOKEN(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); }
|
cmd ::= SHOW VNODES IPTOKEN(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); }
|
||||||
|
|
||||||
|
|
||||||
%type dbPrefix {SStrToken}
|
%type dbPrefix {SStrToken}
|
||||||
dbPrefix(A) ::=. {A.n = 0; A.type = 0;}
|
dbPrefix(A) ::=. {A.n = 0; A.type = 0;}
|
||||||
dbPrefix(A) ::= ids(X) DOT. {A = X; }
|
dbPrefix(A) ::= ids(X) DOT. {A = X; }
|
||||||
|
@ -88,6 +89,15 @@ dbPrefix(A) ::= ids(X) DOT. {A = X; }
|
||||||
cpxName(A) ::= . {A.n = 0; }
|
cpxName(A) ::= . {A.n = 0; }
|
||||||
cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
|
cpxName(A) ::= DOT ids(Y). {A = Y; A.n += 1; }
|
||||||
|
|
||||||
|
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y). {
|
||||||
|
X.n += Y.n;
|
||||||
|
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd ::= SHOW CREATE DATABASE ids(X). {
|
||||||
|
setDCLSQLElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
|
||||||
|
}
|
||||||
|
|
||||||
cmd ::= SHOW dbPrefix(X) TABLES. {
|
cmd ::= SHOW dbPrefix(X) TABLES. {
|
||||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, 0);
|
setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, 0);
|
||||||
}
|
}
|
||||||
|
|
2864
src/query/src/sql.c
2864
src/query/src/sql.c
File diff suppressed because it is too large
Load Diff
|
@ -266,7 +266,6 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
|
||||||
|
|
||||||
if (taosHashGetSize(pCacheObj->pHashTable) == 0) {
|
if (taosHashGetSize(pCacheObj->pHashTable) == 0) {
|
||||||
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
||||||
uError("cache:%s, key:%p, not in cache, retrieved failed, reason: empty sqlObj cache", pCacheObj->name, key);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +279,7 @@ void *taosCacheAcquireByKey(SCacheObj *pCacheObj, const void *key, size_t keyLen
|
||||||
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(ptNode));
|
uDebug("cache:%s, key:%p, %p is retrieved from cache, refcnt:%d", pCacheObj->name, key, pData, T_REF_VAL_GET(ptNode));
|
||||||
} else {
|
} else {
|
||||||
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1);
|
||||||
uError("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key);
|
uDebug("cache:%s, key:%p, not in cache, retrieved failed", pCacheObj->name, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1);
|
atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1);
|
||||||
|
|
|
@ -186,6 +186,12 @@ int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
code = walAlter(pVnode->wal, &pVnode->walCfg);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
pVnode->status = TAOS_VN_STATUS_READY;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
code = syncReconfig(pVnode->sync, &pVnode->syncCfg);
|
code = syncReconfig(pVnode->sync, &pVnode->syncCfg);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
pVnode->status = TAOS_VN_STATUS_READY;
|
pVnode->status = TAOS_VN_STATUS_READY;
|
||||||
|
@ -390,6 +396,7 @@ void vnodeRelease(void *pVnodeRaw) {
|
||||||
if (0 == tsEnableVnodeBak) {
|
if (0 == tsEnableVnodeBak) {
|
||||||
vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId);
|
vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId);
|
||||||
} else {
|
} else {
|
||||||
|
taosRemoveDir(newDir);
|
||||||
taosRename(rootDir, newDir);
|
taosRename(rootDir, newDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,8 @@ int32_t vnodeProcessRead(void *param, SReadMsg *pReadMsg) {
|
||||||
return TSDB_CODE_APP_NOT_READY;
|
return TSDB_CODE_APP_NOT_READY;
|
||||||
|
|
||||||
// TODO: Later, let slave to support query
|
// TODO: Later, let slave to support query
|
||||||
if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) {
|
// if (pVnode->syncCfg.replica > 1 && pVnode->role != TAOS_SYNC_ROLE_MASTER) {
|
||||||
|
if (pVnode->role != TAOS_SYNC_ROLE_SLAVE && pVnode->role != TAOS_SYNC_ROLE_MASTER) {
|
||||||
vDebug("vgId:%d, msgType:%s not processed, replica:%d role:%d", pVnode->vgId, taosMsg[msgType], pVnode->syncCfg.replica, pVnode->role);
|
vDebug("vgId:%d, msgType:%s not processed, replica:%d role:%d", pVnode->vgId, taosMsg[msgType], pVnode->syncCfg.replica, pVnode->role);
|
||||||
return TSDB_CODE_APP_NOT_READY;
|
return TSDB_CODE_APP_NOT_READY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,13 @@ static void walModuleInitFunc() {
|
||||||
wDebug("WAL module is initialized");
|
wDebug("WAL module is initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool walNeedFsyncTimer(SWal *pWal) {
|
||||||
|
if (pWal->fsyncPeriod > 0 && pWal->level == TAOS_WAL_FSYNC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void *walOpen(const char *path, const SWalCfg *pCfg) {
|
void *walOpen(const char *path, const SWalCfg *pCfg) {
|
||||||
SWal *pWal = calloc(sizeof(SWal), 1);
|
SWal *pWal = calloc(sizeof(SWal), 1);
|
||||||
if (pWal == NULL) {
|
if (pWal == NULL) {
|
||||||
|
@ -95,7 +102,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
|
||||||
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
tstrncpy(pWal->path, path, sizeof(pWal->path));
|
||||||
pthread_mutex_init(&pWal->mutex, NULL);
|
pthread_mutex_init(&pWal->mutex, NULL);
|
||||||
|
|
||||||
if (pWal->fsyncPeriod > 0 && pWal->level == TAOS_WAL_FSYNC) {
|
if (walNeedFsyncTimer(pWal)) {
|
||||||
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
||||||
if (pWal->timer == NULL) {
|
if (pWal->timer == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
@ -127,6 +134,37 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
|
||||||
return pWal;
|
return pWal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int walAlter(twalh wal, const SWalCfg *pCfg) {
|
||||||
|
SWal *pWal = wal;
|
||||||
|
if (pWal == NULL) {
|
||||||
|
return TSDB_CODE_WAL_APP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pWal->level == pCfg->walLevel && pWal->fsyncPeriod == pCfg->fsyncPeriod) {
|
||||||
|
wDebug("wal:%s, old walLevel:%d fsync:%d, new walLevel:%d fsync:%d not change", pWal->name, pWal->level,
|
||||||
|
pWal->fsyncPeriod, pCfg->walLevel, pCfg->fsyncPeriod);
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
wInfo("wal:%s, change old walLevel:%d fsync:%d, new walLevel:%d fsync:%d", pWal->name, pWal->level, pWal->fsyncPeriod,
|
||||||
|
pCfg->walLevel, pCfg->fsyncPeriod);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&pWal->mutex);
|
||||||
|
pWal->level = pCfg->walLevel;
|
||||||
|
pWal->fsyncPeriod = pCfg->fsyncPeriod;
|
||||||
|
if (walNeedFsyncTimer(pWal)) {
|
||||||
|
wInfo("wal:%s, reset fsync timer, walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod);
|
||||||
|
taosTmrReset(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, &pWal->timer,walTmrCtrl);
|
||||||
|
} else {
|
||||||
|
wInfo("wal:%s, stop fsync timer, walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod);
|
||||||
|
taosTmrStop(pWal->timer);
|
||||||
|
pWal->timer = NULL;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&pWal->mutex);
|
||||||
|
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
void walClose(void *handle) {
|
void walClose(void *handle) {
|
||||||
if (handle == NULL) return;
|
if (handle == NULL) return;
|
||||||
|
|
||||||
|
@ -484,6 +522,12 @@ static void walProcessFsyncTimer(void *param, void *tmrId) {
|
||||||
if (fsync(pWal->fd) < 0) {
|
if (fsync(pWal->fd) < 0) {
|
||||||
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
if (walNeedFsyncTimer(pWal)) {
|
||||||
|
pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl);
|
||||||
|
} else {
|
||||||
|
wInfo("wal:%s, stop fsync timer for walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod);
|
||||||
|
taosTmrStop(pWal->timer);
|
||||||
|
pWal->timer = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ public class JDBCConnectorChecker {
|
||||||
private static String tbName = "weather";
|
private static String tbName = "weather";
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get connection
|
* get connection
|
||||||
**/
|
**/
|
||||||
|
@ -170,5 +169,4 @@ public class JDBCConnectorChecker {
|
||||||
checker.close();
|
checker.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
bash ./case001/case001.sh
|
||||||
|
#bash ./case002/case002.sh
|
||||||
|
#bash ./case003/case003.sh
|
|
@ -0,0 +1,308 @@
|
||||||
|
/*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/taosdata/driver-go/taosSql"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
taosDriverName := "taosSql"
|
||||||
|
demodb := "demodb"
|
||||||
|
demot := "demot"
|
||||||
|
|
||||||
|
fmt.Printf("\n======== start demo test ========\n")
|
||||||
|
// open connect to taos server
|
||||||
|
db, err := sql.Open(taosDriverName, "root:taosdata@/tcp(192.168.1.217:7100)/")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Open database error: %s\n", err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
drop_database(db, demodb)
|
||||||
|
create_database(db, demodb)
|
||||||
|
use_database(db, demodb)
|
||||||
|
create_table(db, demot)
|
||||||
|
insert_data(db, demot)
|
||||||
|
select_data(db, demot)
|
||||||
|
|
||||||
|
fmt.Printf("\n======== start stmt mode test ========\n")
|
||||||
|
|
||||||
|
demodbStmt := "demodbStmt"
|
||||||
|
demotStmt := "demotStmt"
|
||||||
|
drop_database_stmt(db, demodbStmt)
|
||||||
|
create_database_stmt(db, demodbStmt)
|
||||||
|
use_database_stmt(db, demodbStmt)
|
||||||
|
create_table_stmt(db, demotStmt)
|
||||||
|
insert_data_stmt(db, demotStmt)
|
||||||
|
select_data_stmt(db, demotStmt)
|
||||||
|
|
||||||
|
fmt.Printf("\n======== end demo test ========\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func drop_database(db *sql.DB, demodb string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
res, err := db.Exec("drop database if exists " + demodb)
|
||||||
|
checkErr(err, "drop database if exists "+demodb)
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "drop db, res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
|
||||||
|
fmt.Printf("drop database result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
|
||||||
|
//sleep 50毫秒
|
||||||
|
time.Sleep(time.Duration(50)* time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
func create_database(db *sql.DB, demodb string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// create database
|
||||||
|
res, err := db.Exec("create database " + demodb)
|
||||||
|
checkErr(err, "create db, db.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "create db, res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
|
||||||
|
fmt.Printf("create database result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func use_database(db *sql.DB, demodb string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// use database
|
||||||
|
res, err := db.Exec("use " + demodb) // notes: must no quote to db name
|
||||||
|
checkErr(err, "use db db.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "use db, res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
|
||||||
|
fmt.Printf("use database result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func create_table(db *sql.DB, demot string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// create table
|
||||||
|
res, err := db.Exec("create table " + demot + " (ts timestamp, id int, name binary(8), len tinyint, flag bool, notes binary(8), fv float, dv double)")
|
||||||
|
checkErr(err, "create table db.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "create table res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("create table result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func insert_data(db *sql.DB, demot string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// insert data
|
||||||
|
res, err := db.Exec("insert into " + demot +
|
||||||
|
" values (now, 100, 'beijing', 10, true, 'one', 123.456, 123.456)" +
|
||||||
|
" (now+1s, 101, 'shanghai', 11, true, 'two', 789.123, 789.123)" +
|
||||||
|
" (now+2s, 102, 'shenzhen', 12, false, 'three', 456.789, 456.789)")
|
||||||
|
|
||||||
|
checkErr(err, "insert data, db.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "insert data res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("insert data result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func select_data(db *sql.DB, demot string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
|
||||||
|
rows, err := db.Query("select * from ? ", demot) // go text mode
|
||||||
|
checkErr(err, "select db.Query")
|
||||||
|
|
||||||
|
fmt.Printf("%10s%s%8s %5s %9s%s %s %8s%s %7s%s %8s%s %4s%s %5s%s\n", " ", "ts", " ", "id", " ", "name", " ", "len", " ", "flag", " ", "notes", " ", "fv", " ", " ", "dv")
|
||||||
|
var affectd int
|
||||||
|
|
||||||
|
//decoder := mahonia.NewDecoder("gbk") // 把原来ANSI格式的文本文件里的字符,用gbk进行解码。
|
||||||
|
|
||||||
|
for rows.Next() {
|
||||||
|
var ts string
|
||||||
|
var name string
|
||||||
|
var id int
|
||||||
|
var len int8
|
||||||
|
var flag bool
|
||||||
|
var notes string
|
||||||
|
var fv float32
|
||||||
|
var dv float64
|
||||||
|
|
||||||
|
err = rows.Scan(&ts, &id, &name, &len, &flag, ¬es, &fv, &dv)
|
||||||
|
checkErr(err, "select rows.Scan")
|
||||||
|
|
||||||
|
fmt.Printf("%s|\t", ts)
|
||||||
|
fmt.Printf("%d|\t", id)
|
||||||
|
fmt.Printf("%10s|\t", name)
|
||||||
|
fmt.Printf("%d|\t", len)
|
||||||
|
fmt.Printf("%t|\t", flag)
|
||||||
|
fmt.Printf("%s|\t", notes)
|
||||||
|
fmt.Printf("%06.3f|\t", fv)
|
||||||
|
fmt.Printf("%09.6f|\n\n", dv)
|
||||||
|
|
||||||
|
affectd++
|
||||||
|
}
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("select data result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
//fmt.Printf("insert data result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1E9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func drop_database_stmt(db *sql.DB, demodb string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// drop test db
|
||||||
|
res, err := db.Exec("drop database if exists " + demodb)
|
||||||
|
checkErr(err, "drop database "+demodb)
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "drop db, res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("drop database result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func create_database_stmt(db *sql.DB, demodb string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// create database
|
||||||
|
//var stmt interface{}
|
||||||
|
stmt, err := db.Prepare("create database ?")
|
||||||
|
checkErr(err, "create db, db.Prepare")
|
||||||
|
|
||||||
|
//var res driver.Result
|
||||||
|
res, err := stmt.Exec(demodb)
|
||||||
|
checkErr(err, "create db, stmt.Exec")
|
||||||
|
|
||||||
|
//fmt.Printf("Query OK, %d row(s) affected()", res.RowsAffected())
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "create db, res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("create database result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func use_database_stmt(db *sql.DB, demodb string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// create database
|
||||||
|
//var stmt interface{}
|
||||||
|
stmt, err := db.Prepare("use " + demodb)
|
||||||
|
checkErr(err, "use db, db.Prepare")
|
||||||
|
|
||||||
|
res, err := stmt.Exec()
|
||||||
|
checkErr(err, "use db, stmt.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "use db, res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("use database result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func create_table_stmt(db *sql.DB, demot string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// create table
|
||||||
|
// (ts timestamp, id int, name binary(8), len tinyint, flag bool, notes binary(8), fv float, dv double)
|
||||||
|
stmt, err := db.Prepare("create table ? (? timestamp, ? int, ? binary(10), ? tinyint, ? bool, ? binary(8), ? float, ? double)")
|
||||||
|
checkErr(err, "create table db.Prepare")
|
||||||
|
|
||||||
|
res, err := stmt.Exec(demot, "ts", "id", "name", "len", "flag", "notes", "fv", "dv")
|
||||||
|
checkErr(err, "create table stmt.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "create table res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("create table result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func insert_data_stmt(db *sql.DB, demot string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
// insert data into table
|
||||||
|
stmt, err := db.Prepare("insert into ? values(?, ?, ?, ?, ?, ?, ?, ?) (?, ?, ?, ?, ?, ?, ?, ?) (?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
|
checkErr(err, "insert db.Prepare")
|
||||||
|
|
||||||
|
res, err := stmt.Exec(demot, "now", 1000, "'haidian'", 6, true, "'AI world'", 6987.654, 321.987,
|
||||||
|
"now+1s", 1001, "'changyang'", 7, false, "'DeepMode'", 12356.456, 128634.456,
|
||||||
|
"now+2s", 1002, "'chuangping'", 8, true, "'database'", 3879.456, 65433478.456)
|
||||||
|
checkErr(err, "insert data, stmt.Exec")
|
||||||
|
|
||||||
|
affectd, err := res.RowsAffected()
|
||||||
|
checkErr(err, "res.RowsAffected")
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("insert data result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func select_data_stmt(db *sql.DB, demot string) {
|
||||||
|
st := time.Now().Nanosecond()
|
||||||
|
|
||||||
|
stmt, err := db.Prepare("select ?, ?, ?, ?, ?, ?, ?, ? from ?") // go binary mode
|
||||||
|
checkErr(err, "db.Prepare")
|
||||||
|
|
||||||
|
rows, err := stmt.Query("ts", "id", "name", "len", "flag", "notes", "fv", "dv", demot)
|
||||||
|
checkErr(err, "stmt.Query")
|
||||||
|
|
||||||
|
fmt.Printf("%10s%s%8s %5s %8s%s %s %10s%s %7s%s %8s%s %11s%s %14s%s\n", " ", "ts", " ", "id", " ", "name", " ", "len", " ", "flag", " ", "notes", " ", "fv", " ", " ", "dv")
|
||||||
|
var affectd int
|
||||||
|
for rows.Next() {
|
||||||
|
var ts string
|
||||||
|
var name string
|
||||||
|
var id int
|
||||||
|
var len int8
|
||||||
|
var flag bool
|
||||||
|
var notes string
|
||||||
|
var fv float32
|
||||||
|
var dv float64
|
||||||
|
|
||||||
|
err = rows.Scan(&ts, &id, &name, &len, &flag, ¬es, &fv, &dv)
|
||||||
|
//fmt.Println("start scan fields from row.rs, &fv:", &fv)
|
||||||
|
//err = rows.Scan(&fv)
|
||||||
|
checkErr(err, "rows.Scan")
|
||||||
|
|
||||||
|
fmt.Printf("%s|\t", ts)
|
||||||
|
fmt.Printf("%d|\t", id)
|
||||||
|
fmt.Printf("%10s|\t", name)
|
||||||
|
fmt.Printf("%d|\t", len)
|
||||||
|
fmt.Printf("%t|\t", flag)
|
||||||
|
fmt.Printf("%s|\t", notes)
|
||||||
|
fmt.Printf("%06.3f|\t", fv)
|
||||||
|
fmt.Printf("%09.6f|\n", dv)
|
||||||
|
|
||||||
|
affectd++
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
et := time.Now().Nanosecond()
|
||||||
|
fmt.Printf("select data result:\n %d row(s) affectd (%6.6fs)\n\n", affectd, (float32(et-st))/1e9)
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkErr(err error, prompt string) {
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("%s\n", prompt)
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
#
|
||||||
|
# Do go test
|
||||||
|
#
|
||||||
|
##################################################
|
||||||
|
|
||||||
|
set +e
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
script_dir="$(dirname $(readlink -f $0))"
|
||||||
|
#echo "pwd: $script_dir, para0: $0"
|
||||||
|
|
||||||
|
execName=$0
|
||||||
|
execName=`echo ${execName##*/}`
|
||||||
|
goName=`echo ${execName%.*}`
|
||||||
|
|
||||||
|
###### step 1: start one taosd
|
||||||
|
scriptDir=$script_dir/../../script/sh
|
||||||
|
bash $scriptDir/stop_dnodes.sh
|
||||||
|
bash $scriptDir/deploy.sh -n dnode1 -i 1
|
||||||
|
bash $scriptDir/cfg.sh -n dnode1 -c walLevel -v 0
|
||||||
|
bash $scriptDir/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
|
###### step 2: set config item
|
||||||
|
TAOS_CFG=/etc/taos/taos.cfg
|
||||||
|
HOSTNAME=`hostname -f`
|
||||||
|
|
||||||
|
if [ ! -f ${TAOS_CFG} ]; then
|
||||||
|
touch -f $TAOS_CFG
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo " " > $TAOS_CFG
|
||||||
|
echo "firstEp ${HOSTNAME}:7100" >> $TAOS_CFG
|
||||||
|
echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
|
||||||
|
echo "serverPort 7100" >> $TAOS_CFG
|
||||||
|
#echo "dataDir $DATA_DIR" >> $TAOS_CFG
|
||||||
|
#echo "logDir $LOG_DIR" >> $TAOS_CFG
|
||||||
|
#echo "scriptDir ${CODE_DIR}/../script" >> $TAOS_CFG
|
||||||
|
echo "numOfLogLines 100000000" >> $TAOS_CFG
|
||||||
|
echo "dDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "mDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "sdbDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "rpcDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "tmrDebugFlag 131" >> $TAOS_CFG
|
||||||
|
echo "cDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "httpDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "monitorDebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "udebugFlag 135" >> $TAOS_CFG
|
||||||
|
echo "tablemetakeeptimer 5" >> $TAOS_CFG
|
||||||
|
echo "wal 0" >> $TAOS_CFG
|
||||||
|
echo "asyncLog 0" >> $TAOS_CFG
|
||||||
|
echo "locale en_US.UTF-8" >> $TAOS_CFG
|
||||||
|
echo "enableCoreFile 1" >> $TAOS_CFG
|
||||||
|
echo " " >> $TAOS_CFG
|
||||||
|
|
||||||
|
ulimit -n 600000
|
||||||
|
ulimit -c unlimited
|
||||||
|
#
|
||||||
|
##sudo sysctl -w kernel.core_pattern=$TOP_DIR/core.%p.%e
|
||||||
|
#
|
||||||
|
|
||||||
|
###### step 3: start build
|
||||||
|
cd $script_dir
|
||||||
|
rm -f go.*
|
||||||
|
go mod init $goName
|
||||||
|
go build
|
||||||
|
sleep 1s
|
||||||
|
sudo ./$goName
|
|
@ -0,0 +1,42 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
#
|
||||||
|
# Do go test
|
||||||
|
#
|
||||||
|
##################################################
|
||||||
|
|
||||||
|
set +e
|
||||||
|
#set -x
|
||||||
|
|
||||||
|
FILE_NAME=
|
||||||
|
RELEASE=0
|
||||||
|
while getopts "f:" arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
f)
|
||||||
|
FILE_NAME=$OPTARG
|
||||||
|
echo "input file: $FILE_NAME"
|
||||||
|
;;
|
||||||
|
?)
|
||||||
|
echo "unknow argument"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# start one taosd
|
||||||
|
bash ../script/sh/stop_dnodes.sh
|
||||||
|
bash ../script/sh/deploy.sh -n dnode1 -i 1
|
||||||
|
bash ../script/sh/cfg.sh -n dnode1 -c walLevel -v 0
|
||||||
|
bash ../script/sh/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
|
# start build test go file
|
||||||
|
caseDir=`echo ${FILE_NAME%/*}`
|
||||||
|
echo "caseDir: $caseDir"
|
||||||
|
cd $caseDir
|
||||||
|
rm go.*
|
||||||
|
go mod init $caseDir
|
||||||
|
go build
|
||||||
|
sleep 1s
|
||||||
|
./$caseDir
|
||||||
|
|
|
@ -16,6 +16,7 @@ python3 ./test.py -f insert/nchar.py
|
||||||
python3 ./test.py -f insert/nchar-unicode.py
|
python3 ./test.py -f insert/nchar-unicode.py
|
||||||
python3 ./test.py -f insert/multi.py
|
python3 ./test.py -f insert/multi.py
|
||||||
python3 ./test.py -f insert/randomNullCommit.py
|
python3 ./test.py -f insert/randomNullCommit.py
|
||||||
|
python3 insert/retentionpolicy.py
|
||||||
|
|
||||||
python3 ./test.py -f table/column_name.py
|
python3 ./test.py -f table/column_name.py
|
||||||
python3 ./test.py -f table/column_num.py
|
python3 ./test.py -f table/column_num.py
|
||||||
|
@ -154,6 +155,7 @@ python3 ./test.py -f stream/new.py
|
||||||
python3 ./test.py -f stream/stream1.py
|
python3 ./test.py -f stream/stream1.py
|
||||||
python3 ./test.py -f stream/stream2.py
|
python3 ./test.py -f stream/stream2.py
|
||||||
python3 ./test.py -f stream/parser.py
|
python3 ./test.py -f stream/parser.py
|
||||||
|
python3 ./test.py -f stream/history.py
|
||||||
|
|
||||||
#alter table
|
#alter table
|
||||||
python3 ./test.py -f alter/alter_table_crash.py
|
python3 ./test.py -f alter/alter_table_crash.py
|
||||||
|
@ -195,5 +197,5 @@ python3 test.py -f tools/taosdemo.py
|
||||||
|
|
||||||
# subscribe
|
# subscribe
|
||||||
python3 test.py -f subscribe/singlemeter.py
|
python3 test.py -f subscribe/singlemeter.py
|
||||||
python3 test.py -f subscribe/stability.py
|
#python3 test.py -f subscribe/stability.py
|
||||||
python3 test.py -f subscribe/supertable.py
|
python3 test.py -f subscribe/supertable.py
|
|
@ -0,0 +1,112 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
sys.path.insert(0, os.getcwd())
|
||||||
|
import taos
|
||||||
|
from util.log import *
|
||||||
|
from util.cases import *
|
||||||
|
from util.sql import *
|
||||||
|
from util.dnodes import *
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestRetetion:
|
||||||
|
def init(self):
|
||||||
|
self.queryRows=0
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdLog.info("prepare cluster")
|
||||||
|
tdDnodes.init("")
|
||||||
|
tdDnodes.setTestCluster(False)
|
||||||
|
tdDnodes.setValgrind(False)
|
||||||
|
tdDnodes.stopAll()
|
||||||
|
tdDnodes.deploy(1)
|
||||||
|
tdDnodes.start(1)
|
||||||
|
print(tdDnodes.getDnodesRootDir())
|
||||||
|
self.conn = taos.connect(config=tdDnodes.getSimCfgPath())
|
||||||
|
tdSql.init(self.conn.cursor())
|
||||||
|
tdSql.execute('reset query cache')
|
||||||
|
def checkRows(self, expectRows,sql):
|
||||||
|
if self.queryRows == expectRows:
|
||||||
|
tdLog.info("sql:%s, queryRows:%d == expect:%d" % (sql, self.queryRows, expectRows))
|
||||||
|
else:
|
||||||
|
caller = inspect.getframeinfo(inspect.stack()[1][0])
|
||||||
|
args = (caller.filename, caller.lineno, sql, self.queryRows, expectRows)
|
||||||
|
os.system("timedatectl set-ntp true")
|
||||||
|
tdLog.exit("%s(%d) failed: sql:%s, queryRows:%d != expect:%d" % args)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
tdLog.info("=============== step1")
|
||||||
|
tdSql.execute('create database test keep 3 days 1;')
|
||||||
|
tdSql.execute('use test;')
|
||||||
|
tdSql.execute('create table test(ts timestamp,i int);')
|
||||||
|
|
||||||
|
cmd = 'insert into test values(now-2d,11)(now-1d,11)(now,11)(now+1d,11);'
|
||||||
|
tdLog.info(cmd)
|
||||||
|
tdSql.execute(cmd)
|
||||||
|
tdSql.query('select * from test')
|
||||||
|
tdSql.checkRows(4)
|
||||||
|
|
||||||
|
tdLog.info("=============== step2")
|
||||||
|
tdDnodes.stop(1)
|
||||||
|
os.system("timedatectl set-ntp false")
|
||||||
|
os.system("date -s $(date -d \"${DATE} 2 days\" \"+%Y%m%d\")")
|
||||||
|
tdDnodes.start(1)
|
||||||
|
cmd = 'insert into test values(now,11);'
|
||||||
|
tdLog.info(cmd)
|
||||||
|
tdSql.execute(cmd)
|
||||||
|
queryRows=tdSql.query('select * from test')
|
||||||
|
if queryRows==4:
|
||||||
|
tdSql.checkRows(4)
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
|
tdSql.checkRows(5)
|
||||||
|
|
||||||
|
tdLog.info("=============== step3")
|
||||||
|
tdDnodes.stop(1)
|
||||||
|
os.system("date -s $(date -d \"${DATE} 2 days\" \"+%Y%m%d\")")
|
||||||
|
tdDnodes.start(1)
|
||||||
|
cmd = 'insert into test values(now-1d,11);'
|
||||||
|
tdLog.info(cmd)
|
||||||
|
tdSql.execute(cmd)
|
||||||
|
queryRows=tdSql.query('select * from test')
|
||||||
|
tdSql.checkRows(6)
|
||||||
|
tdLog.info("=============== step4")
|
||||||
|
tdDnodes.stop(1)
|
||||||
|
tdDnodes.start(1)
|
||||||
|
cmd = 'insert into test values(now,11);'
|
||||||
|
tdLog.info(cmd)
|
||||||
|
tdSql.execute(cmd)
|
||||||
|
tdSql.query('select * from test')
|
||||||
|
tdSql.checkRows(7)
|
||||||
|
|
||||||
|
tdLog.info("=============== step5")
|
||||||
|
tdDnodes.stop(1)
|
||||||
|
tdDnodes.start(1)
|
||||||
|
cmd='select * from test where ts > now-1d'
|
||||||
|
queryRows=tdSql.query('select * from test where ts > now-1d')
|
||||||
|
self.checkRows(1,cmd)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
os.system("timedatectl set-ntp true")
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
clients = TDTestRetetion()
|
||||||
|
clients.init()
|
||||||
|
clients.run()
|
||||||
|
clients.stop()
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import taos
|
||||||
|
from util.log import tdLog
|
||||||
|
from util.cases import tdCases
|
||||||
|
from util.sql import tdSql
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
tdSql.execute("create table cars(ts timestamp, s int) tags(id int)")
|
||||||
|
tdSql.execute("create table car0 using cars tags(0)")
|
||||||
|
tdSql.execute("create table car1 using cars tags(1)")
|
||||||
|
tdSql.execute("create table car2 using cars tags(2)")
|
||||||
|
tdSql.execute("create table car3 using cars tags(3)")
|
||||||
|
tdSql.execute("create table car4 using cars tags(4)")
|
||||||
|
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:00.103', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2019-01-01 00:00:00.234', 1)")
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:01.012', 1)")
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:02.003', 1)")
|
||||||
|
tdSql.execute("insert into car2 values('2019-01-01 00:00:02.328', 1)")
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:03.139', 1)")
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:04.348', 1)")
|
||||||
|
tdSql.execute("insert into car0 values('2019-01-01 00:00:05.783', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2019-01-01 00:00:01.893', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2019-01-01 00:00:02.712', 1)")
|
||||||
|
tdSql.execute("insert into car1 values('2019-01-01 00:00:03.982', 1)")
|
||||||
|
tdSql.execute("insert into car3 values('2019-01-01 00:00:01.389', 1)")
|
||||||
|
tdSql.execute("insert into car4 values('2019-01-01 00:00:01.829', 1)")
|
||||||
|
|
||||||
|
tdSql.execute("create table strm as select count(*) from cars interval(4s)")
|
||||||
|
tdSql.waitedQuery("select * from strm", 2, 100)
|
||||||
|
tdSql.checkData(0, 1, 11)
|
||||||
|
tdSql.checkData(1, 1, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -16,6 +16,7 @@ import os
|
||||||
from util.log import *
|
from util.log import *
|
||||||
from util.cases import *
|
from util.cases import *
|
||||||
from util.sql import *
|
from util.sql import *
|
||||||
|
from util.dnodes import *
|
||||||
|
|
||||||
|
|
||||||
class TDTestCase:
|
class TDTestCase:
|
||||||
|
@ -25,11 +26,30 @@ class TDTestCase:
|
||||||
|
|
||||||
self.numberOfTables = 10000
|
self.numberOfTables = 10000
|
||||||
self.numberOfRecords = 100
|
self.numberOfRecords = 100
|
||||||
|
def getBuildPath(self):
|
||||||
|
selfPath = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
|
if ("community" in selfPath):
|
||||||
|
projPath = selfPath[:selfPath.find("community")]
|
||||||
|
else:
|
||||||
|
projPath = selfPath[:selfPath.find("tests")]
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(projPath):
|
||||||
|
if ("taosd" in files):
|
||||||
|
rootRealPath = os.path.dirname(os.path.realpath(root))
|
||||||
|
if ("packaging" not in rootRealPath):
|
||||||
|
buildPath = root[:len(root)-len("/build/bin")]
|
||||||
|
break
|
||||||
|
return buildPath
|
||||||
def run(self):
|
def run(self):
|
||||||
tdSql.prepare()
|
tdSql.prepare()
|
||||||
|
buildPath = self.getBuildPath()
|
||||||
os.system("yes | taosdemo -t %d -n %d" % (self.numberOfTables, self.numberOfRecords))
|
if (buildPath == ""):
|
||||||
|
tdLog.exit("taosd not found!")
|
||||||
|
else:
|
||||||
|
tdLog.info("taosd found in %s" % buildPath)
|
||||||
|
binPath = buildPath+ "/build/bin/"
|
||||||
|
os.system("yes | %staosdemo -t %d -n %d" % (binPath,self.numberOfTables, self.numberOfRecords))
|
||||||
|
|
||||||
tdSql.execute("use test")
|
tdSql.execute("use test")
|
||||||
tdSql.query("select count(*) from meters")
|
tdSql.query("select count(*) from meters")
|
||||||
|
|
|
@ -220,3 +220,5 @@ run general/stream/table_del.sim
|
||||||
run general/stream/metrics_del.sim
|
run general/stream/metrics_del.sim
|
||||||
run general/stream/table_replica1_vnoden.sim
|
run general/stream/table_replica1_vnoden.sim
|
||||||
run general/stream/metrics_replica1_vnoden.sim
|
run general/stream/metrics_replica1_vnoden.sim
|
||||||
|
run general/db/show_create_db.sim
|
||||||
|
run general/db/show_create_table.sim
|
||||||
|
|
|
@ -218,7 +218,10 @@ if $data12_db != 1 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql_error alter database db wal 2
|
sql alter database db wal 1
|
||||||
|
sql alter database db wal 2
|
||||||
|
sql alter database db wal 1
|
||||||
|
sql alter database db wal 2
|
||||||
sql_error alter database db wal 0
|
sql_error alter database db wal 0
|
||||||
sql_error alter database db wal 3
|
sql_error alter database db wal 3
|
||||||
sql_error alter database db wal 4
|
sql_error alter database db wal 4
|
||||||
|
@ -226,11 +229,13 @@ sql_error alter database db wal -1
|
||||||
sql_error alter database db wal 1000
|
sql_error alter database db wal 1000
|
||||||
|
|
||||||
print ============== step fsync
|
print ============== step fsync
|
||||||
sql_error alter database db fsync 2
|
sql alter database db fsync 0
|
||||||
sql_error alter database db fsync 3
|
sql alter database db fsync 1
|
||||||
sql_error alter database db fsync 4
|
sql alter database db fsync 3600
|
||||||
|
sql alter database db fsync 18000
|
||||||
|
sql alter database db fsync 180000
|
||||||
|
sql_error alter database db fsync 180001
|
||||||
sql_error alter database db fsync -1
|
sql_error alter database db fsync -1
|
||||||
sql_error alter database db fsync 1000
|
|
||||||
|
|
||||||
print ============== step comp
|
print ============== step comp
|
||||||
sql show databases
|
sql show databases
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c walLevel -v 0
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sleep 3000
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print =============== step2
|
||||||
|
sql create database db
|
||||||
|
sql show create database db
|
||||||
|
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print =============== step3
|
||||||
|
sql use db
|
||||||
|
sql show create database db
|
||||||
|
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 != db then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql drop database db
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -0,0 +1,87 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c walLevel -v 0
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sleep 3000
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
print ===============create three type table
|
||||||
|
sql create database db
|
||||||
|
sql use db
|
||||||
|
sql create table meters(ts timestamp, f binary(8)) tags(loc int, zone binary(8))
|
||||||
|
sql create table t0 using meters tags(1,'ch')
|
||||||
|
sql create table normalTbl(ts timestamp, zone binary(8))
|
||||||
|
|
||||||
|
sql use db
|
||||||
|
sql show create table meters
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ===============check sub table
|
||||||
|
sql show create table t0
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data00 == 't0' then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ===============check normal table
|
||||||
|
|
||||||
|
sql show create table normalTbl
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 == 'normalTbl' then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ===============check super table
|
||||||
|
sql show create table meters
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 == 'meters' then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ===============check sub table with prefix
|
||||||
|
|
||||||
|
sql show create table db.t0
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 == 't0' then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print ===============check normal table with prefix
|
||||||
|
sql show create table db.normalTbl
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 == 'normalTbl' then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
print ===============check super table with prefix
|
||||||
|
sql show create table db.meters
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 == 'meters' then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql drop database db
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -3,7 +3,7 @@ sleep 3000
|
||||||
system sh/deploy.sh -n dnode1 -i 1
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
system sh/cfg.sh -n dnode1 -c wallevel -v 0
|
system sh/cfg.sh -n dnode1 -c wallevel -v 0
|
||||||
system sh/cfg.sh -n dnode1 -c http -v 1
|
system sh/cfg.sh -n dnode1 -c http -v 1
|
||||||
system sh/cfg.sh -n dnode1 -c maxSQLLength -v 7340032
|
system sh/cfg.sh -n dnode1 -c maxSQLLength -v 340032
|
||||||
system sh/exec.sh -n dnode1 -s start
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
|
||||||
sleep 3000
|
sleep 3000
|
||||||
|
@ -18,10 +18,22 @@ sql use d1
|
||||||
sql create table table_rest (ts timestamp, i int)
|
sql create table table_rest (ts timestamp, i int)
|
||||||
print sql length is 270KB
|
print sql length is 270KB
|
||||||
restful d1 table_rest 1591072800 10000 gzip
|
restful d1 table_rest 1591072800 10000 gzip
|
||||||
|
restful d1 table_rest 1591172800 10000 gzip
|
||||||
|
restful d1 table_rest 1591272800 10000 gzip
|
||||||
|
restful d1 table_rest 1591372800 10000 gzip
|
||||||
|
restful d1 table_rest 1591472800 10000 gzip
|
||||||
|
restful d1 table_rest 1591572800 10000 gzip
|
||||||
|
restful d1 table_rest 1591672800 10000 gzip
|
||||||
|
restful d1 table_rest 1591772800 10000 gzip
|
||||||
|
restful d1 table_rest 1591872800 10000 gzip
|
||||||
|
restful d1 table_rest 1591972800 10000 gzip
|
||||||
|
|
||||||
sql select * from table_rest;
|
sql select * from table_rest;
|
||||||
print rows: $rows
|
print rows: $rows
|
||||||
if $rows != 10000 then
|
if $rows != 100000 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
system curl -H 'Authorization: Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04' -d 'select * from d1.table_rest' 127.0.0.1:7111/rest/sql --compressed
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -79,6 +79,7 @@ cd ../../../debug; make
|
||||||
|
|
||||||
./test.sh -f general/http/autocreate.sim
|
./test.sh -f general/http/autocreate.sim
|
||||||
./test.sh -f general/http/chunked.sim
|
./test.sh -f general/http/chunked.sim
|
||||||
|
./test.sh -f general/http/gzip.sim
|
||||||
./test.sh -f general/http/restful.sim
|
./test.sh -f general/http/restful.sim
|
||||||
./test.sh -f general/http/restful_insert.sim
|
./test.sh -f general/http/restful_insert.sim
|
||||||
./test.sh -f general/http/restful_limit.sim
|
./test.sh -f general/http/restful_limit.sim
|
||||||
|
|
Loading…
Reference in New Issue