提交 49cf75d7 编写于 作者: T tickduan

Merge branch 'develop' into compress_float

...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
static SBnThread tsBnThread; static SBnThread tsBnThread;
static void *bnThreadFunc(void *arg) { static void *bnThreadFunc(void *arg) {
setThreadName("bnThreadd");
while (1) { while (1) {
pthread_mutex_lock(&tsBnThread.mutex); pthread_mutex_lock(&tsBnThread.mutex);
if (tsBnThread.stop) { if (tsBnThread.stop) {
......
...@@ -110,6 +110,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff ...@@ -110,6 +110,7 @@ int32_t tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOff
void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta); void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta);
void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf); void tscSortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf);
int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo); int tscSortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo);
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows);
void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo); void tscDestroyBoundColumnInfo(SParsedDataColInfo* pColInfo);
void doRetrieveSubqueryData(SSchedMsg *pMsg); void doRetrieveSubqueryData(SSchedMsg *pMsg);
......
...@@ -138,6 +138,7 @@ typedef struct STableDataBlocks { ...@@ -138,6 +138,7 @@ typedef struct STableDataBlocks {
uint32_t size; uint32_t size;
STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache STableMeta *pTableMeta; // the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
char *pData; char *pData;
bool cloned;
SParsedDataColInfo boundColumnInfo; SParsedDataColInfo boundColumnInfo;
...@@ -411,6 +412,7 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s ...@@ -411,6 +412,7 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s
int32_t tscValidateSqlInfo(SSqlObj *pSql, struct SSqlInfo *pInfo); int32_t tscValidateSqlInfo(SSqlObj *pSql, struct SSqlInfo *pInfo);
int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows);
extern int32_t sentinel; extern int32_t sentinel;
extern SHashObj *tscVgroupMap; extern SHashObj *tscVgroupMap;
extern SHashObj *tscTableMetaInfo; extern SHashObj *tscTableMetaInfo;
......
...@@ -946,3 +946,34 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI ...@@ -946,3 +946,34 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
return JNI_SUCCESS; return JNI_SUCCESS;
} }
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertLinesImp(JNIEnv *env, jobject jobj,
jobjectArray lines, jlong conn) {
TAOS *taos = (TAOS *)conn;
if (taos == NULL) {
jniError("jobj:%p, connection already closed", jobj);
return JNI_CONNECTION_NULL;
}
int numLines = (*env)->GetArrayLength(env, lines);
char** c_lines = calloc(numLines, sizeof(char*));
for (int i = 0; i < numLines; ++i) {
jstring line = (jstring) ((*env)->GetObjectArrayElement(env, lines, i));
c_lines[i] = (char*)(*env)->GetStringUTFChars(env, line, 0);
}
int code = taos_insert_lines(taos, c_lines, numLines);
for (int i = 0; i < numLines; ++i) {
jstring line = (jstring) ((*env)->GetObjectArrayElement(env, lines, i));
(*env)->ReleaseStringUTFChars(env, line, c_lines[i]);
}
if (code != TSDB_CODE_SUCCESS) {
jniError("jobj:%p, conn:%p, code:%s", jobj, taos, tstrerror(code));
return JNI_TDENGINE_ERROR;
}
return code;
}
\ No newline at end of file
...@@ -1056,7 +1056,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3 ...@@ -1056,7 +1056,7 @@ int32_t tscAllocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int3
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows) { int32_t FORCE_INLINE tsSetBlockInfo(SSubmitBlk *pBlocks, const STableMeta *pTableMeta, int32_t numOfRows) {
pBlocks->tid = pTableMeta->id.tid; pBlocks->tid = pTableMeta->id.tid;
pBlocks->uid = pTableMeta->id.uid; pBlocks->uid = pTableMeta->id.uid;
pBlocks->sversion = pTableMeta->sversion; pBlocks->sversion = pTableMeta->sversion;
...@@ -1904,7 +1904,6 @@ int tsInsertInitialCheck(SSqlObj *pSql) { ...@@ -1904,7 +1904,6 @@ int tsInsertInitialCheck(SSqlObj *pSql) {
int tsParseSql(SSqlObj *pSql, bool initial) { int tsParseSql(SSqlObj *pSql, bool initial) {
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
if (!initial) { if (!initial) {
tscDebug("0x%"PRIx64" resume to parse sql: %s", pSql->self, pCmd->insertParam.sql); tscDebug("0x%"PRIx64" resume to parse sql: %s", pSql->self, pCmd->insertParam.sql);
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "tscLog.h" #include "tscLog.h"
#include "taos.h" #include "taos.h"
typedef struct { typedef struct {
char sTableName[TSDB_TABLE_NAME_LEN]; char sTableName[TSDB_TABLE_NAME_LEN];
SHashObj* tagHash; SHashObj* tagHash;
...@@ -33,7 +34,7 @@ typedef struct { ...@@ -33,7 +34,7 @@ typedef struct {
char* value; char* value;
//=================================== //===================================
SSchema* schema; size_t fieldSchemaIdx;
} TAOS_SML_KV; } TAOS_SML_KV;
typedef struct { typedef struct {
...@@ -48,9 +49,17 @@ typedef struct { ...@@ -48,9 +49,17 @@ typedef struct {
int fieldNum; int fieldNum;
//================================ //================================
SSmlSTableSchema* schema; size_t schemaIdx;
} TAOS_SML_DATA_POINT; } TAOS_SML_DATA_POINT;
typedef enum {
SML_TIME_STAMP_NOW,
SML_TIME_STAMP_SECONDS,
SML_TIME_STAMP_MILLI_SECONDS,
SML_TIME_STAMP_MICRO_SECONDS,
SML_TIME_STAMP_NANO_SECONDS
} SMLTimeStampType;
//================================================================================================= //=================================================================================================
int compareSmlColKv(const void* p1, const void* p2) { int compareSmlColKv(const void* p1, const void* p2) {
...@@ -117,10 +126,12 @@ static int32_t getFieldBytesFromSmlKv(TAOS_SML_KV* kv, int32_t* bytes) { ...@@ -117,10 +126,12 @@ static int32_t getFieldBytesFromSmlKv(TAOS_SML_KV* kv, int32_t* bytes) {
static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* array) { static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* array) {
SSchema* pField = NULL; SSchema* pField = NULL;
SSchema** ppField = taosHashGet(hash, smlKv->key, strlen(smlKv->key)); size_t* pFieldIdx = taosHashGet(hash, smlKv->key, strlen(smlKv->key));
size_t fieldIdx = -1;
int32_t code = 0; int32_t code = 0;
if (ppField) { if (pFieldIdx) {
pField = *ppField; fieldIdx = *pFieldIdx;
pField = taosArrayGet(array, fieldIdx);
if (pField->type != smlKv->type) { if (pField->type != smlKv->type) {
tscError("type mismatch. key %s, type %d. type before %d", smlKv->key, smlKv->type, pField->type); tscError("type mismatch. key %s, type %d. type before %d", smlKv->key, smlKv->type, pField->type);
...@@ -149,10 +160,11 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra ...@@ -149,10 +160,11 @@ static int32_t buildSmlKvSchema(TAOS_SML_KV* smlKv, SHashObj* hash, SArray* arra
field.bytes = bytes; field.bytes = bytes;
pField = taosArrayPush(array, &field); pField = taosArrayPush(array, &field);
taosHashPut(hash, field.name, tagKeyLen, &pField, POINTER_BYTES); fieldIdx = taosArrayGetSize(array) - 1;
taosHashPut(hash, field.name, tagKeyLen, &fieldIdx, sizeof(fieldIdx));
} }
smlKv->schema = pField; smlKv->fieldSchemaIdx = fieldIdx;
return 0; return 0;
} }
...@@ -165,10 +177,12 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -165,10 +177,12 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
for (int i = 0; i < numPoint; ++i) { for (int i = 0; i < numPoint; ++i) {
TAOS_SML_DATA_POINT* point = &points[i]; TAOS_SML_DATA_POINT* point = &points[i];
size_t stableNameLen = strlen(point->stableName); size_t stableNameLen = strlen(point->stableName);
SSmlSTableSchema** ppStableSchema = taosHashGet(sname2shema, point->stableName, stableNameLen); size_t* pStableIdx = taosHashGet(sname2shema, point->stableName, stableNameLen);
SSmlSTableSchema* pStableSchema = NULL; SSmlSTableSchema* pStableSchema = NULL;
if (ppStableSchema) { size_t stableIdx = -1;
pStableSchema= *ppStableSchema; if (pStableIdx) {
pStableSchema= taosArrayGet(stableSchemas, *pStableIdx);
stableIdx = *pStableIdx;
} else { } else {
SSmlSTableSchema schema; SSmlSTableSchema schema;
strncpy(schema.sTableName, point->stableName, stableNameLen); strncpy(schema.sTableName, point->stableName, stableNameLen);
...@@ -179,7 +193,8 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -179,7 +193,8 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
schema.fieldHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); schema.fieldHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
pStableSchema = taosArrayPush(stableSchemas, &schema); pStableSchema = taosArrayPush(stableSchemas, &schema);
taosHashPut(sname2shema, schema.sTableName, stableNameLen, &pStableSchema, POINTER_BYTES); stableIdx = taosArrayGetSize(stableSchemas) - 1;
taosHashPut(sname2shema, schema.sTableName, stableNameLen, &stableIdx, sizeof(size_t));
} }
for (int j = 0; j < point->tagNum; ++j) { for (int j = 0; j < point->tagNum; ++j) {
...@@ -200,7 +215,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -200,7 +215,7 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
} }
} }
point->schema = pStableSchema; point->schemaIdx = stableIdx;
} }
size_t numStables = taosArrayGetSize(stableSchemas); size_t numStables = taosArrayGetSize(stableSchemas);
...@@ -221,11 +236,12 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint, ...@@ -221,11 +236,12 @@ static int32_t buildDataPointSchemas(TAOS_SML_DATA_POINT* points, int numPoint,
return 0; return 0;
} }
static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash, bool isTag, char sTableName[], static int32_t generateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash, SArray* dbAttrArray, bool isTag, char sTableName[],
SSchemaAction* action, bool* actionNeeded) { SSchemaAction* action, bool* actionNeeded) {
SSchema** ppDbAttr = taosHashGet(dbAttrHash, pointColField->name, strlen(pointColField->name)); size_t* pDbIndex = taosHashGet(dbAttrHash, pointColField->name, strlen(pointColField->name));
if (ppDbAttr) { if (pDbIndex) {
SSchema* dbAttr = *ppDbAttr; SSchema* dbAttr = taosArrayGet(dbAttrArray, *pDbIndex);
assert(strcasecmp(dbAttr->name, pointColField->name) == 0);
if (pointColField->type != dbAttr->type) { if (pointColField->type != dbAttr->type) {
tscError("point type and db type mismatch. key: %s. point type: %d, db type: %d", pointColField->name, tscError("point type and db type mismatch. key: %s. point type: %d, db type: %d", pointColField->name,
pointColField->type, dbAttr->type); pointColField->type, dbAttr->type);
...@@ -282,9 +298,9 @@ static int32_t buildColumnDescription(SSchema* field, ...@@ -282,9 +298,9 @@ static int32_t buildColumnDescription(SSchema* field,
static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) { static int32_t applySchemaAction(TAOS* taos, SSchemaAction* action) {
int32_t code = 0; int32_t code = 0;
int32_t capacity = TSDB_MAX_BINARY_LEN;
int32_t outBytes = 0; int32_t outBytes = 0;
char *result = (char *)calloc(1, capacity); char *result = (char *)calloc(1, tsMaxSQLStringLen+1);
int32_t capacity = tsMaxSQLStringLen + 1;
tscDebug("apply schema action: %d", action->action); tscDebug("apply schema action: %d", action->action);
switch (action->action) { switch (action->action) {
...@@ -437,8 +453,9 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) { ...@@ -437,8 +453,9 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
tstrncpy(field.name, tableMeta->schema[i].name, strlen(tableMeta->schema[i].name)+1); tstrncpy(field.name, tableMeta->schema[i].name, strlen(tableMeta->schema[i].name)+1);
field.type = tableMeta->schema[i].type; field.type = tableMeta->schema[i].type;
field.bytes = tableMeta->schema[i].bytes; field.bytes = tableMeta->schema[i].bytes;
SSchema* pField = taosArrayPush(schema->fields, &field); taosArrayPush(schema->fields, &field);
taosHashPut(schema->fieldHash, field.name, strlen(field.name), &pField, POINTER_BYTES); size_t fieldIndex = taosArrayGetSize(schema->fields) - 1;
taosHashPut(schema->fieldHash, field.name, strlen(field.name), &fieldIndex, sizeof(fieldIndex));
} }
for (int i=0; i<tableMeta->tableInfo.numOfTags; ++i) { for (int i=0; i<tableMeta->tableInfo.numOfTags; ++i) {
...@@ -447,8 +464,9 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) { ...@@ -447,8 +464,9 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) {
tstrncpy(field.name, tableMeta->schema[j].name, strlen(tableMeta->schema[j].name)+1); tstrncpy(field.name, tableMeta->schema[j].name, strlen(tableMeta->schema[j].name)+1);
field.type = tableMeta->schema[j].type; field.type = tableMeta->schema[j].type;
field.bytes = tableMeta->schema[j].bytes; field.bytes = tableMeta->schema[j].bytes;
SSchema* pField = taosArrayPush(schema->tags, &field); taosArrayPush(schema->tags, &field);
taosHashPut(schema->tagHash, field.name, strlen(field.name), &pField, POINTER_BYTES); size_t tagIndex = taosArrayGetSize(schema->tags) - 1;
taosHashPut(schema->tagHash, field.name, strlen(field.name), &tagIndex, sizeof(tagIndex));
} }
tscDebug("load table meta succeed. %s, columns number: %d, tag number: %d, precision: %d", tscDebug("load table meta succeed. %s, columns number: %d, tag number: %d, precision: %d",
tableName, tableMeta->tableInfo.numOfColumns, tableMeta->tableInfo.numOfTags, schema->precision); tableName, tableMeta->tableInfo.numOfColumns, tableMeta->tableInfo.numOfTags, schema->precision);
...@@ -476,6 +494,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { ...@@ -476,6 +494,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
code = loadTableMeta(taos, pointSchema->sTableName, &dbSchema); code = loadTableMeta(taos, pointSchema->sTableName, &dbSchema);
if (code != 0) { if (code != 0) {
tscError("reconcile point schema failed. can not create %s", pointSchema->sTableName); tscError("reconcile point schema failed. can not create %s", pointSchema->sTableName);
return code;
} else { } else {
pointSchema->precision = dbSchema.precision; pointSchema->precision = dbSchema.precision;
destroySmlSTableSchema(&dbSchema); destroySmlSTableSchema(&dbSchema);
...@@ -491,7 +510,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { ...@@ -491,7 +510,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
SSchema* pointTag = taosArrayGet(pointSchema->tags, j); SSchema* pointTag = taosArrayGet(pointSchema->tags, j);
SSchemaAction schemaAction = {0}; SSchemaAction schemaAction = {0};
bool actionNeeded = false; bool actionNeeded = false;
generateSchemaAction(pointTag, dbTagHash, true, pointSchema->sTableName, &schemaAction, &actionNeeded); generateSchemaAction(pointTag, dbTagHash, dbSchema.tags, true, pointSchema->sTableName, &schemaAction, &actionNeeded);
if (actionNeeded) { if (actionNeeded) {
applySchemaAction(taos, &schemaAction); applySchemaAction(taos, &schemaAction);
} }
...@@ -505,7 +524,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { ...@@ -505,7 +524,7 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
SSchema* pointCol = taosArrayGet(pointSchema->fields, j); SSchema* pointCol = taosArrayGet(pointSchema->fields, j);
SSchemaAction schemaAction = {0}; SSchemaAction schemaAction = {0};
bool actionNeeded = false; bool actionNeeded = false;
generateSchemaAction(pointCol, dbFieldHash, false, pointSchema->sTableName, &schemaAction, &actionNeeded); generateSchemaAction(pointCol, dbFieldHash, dbSchema.fields,false, pointSchema->sTableName, &schemaAction, &actionNeeded);
if (actionNeeded) { if (actionNeeded) {
applySchemaAction(taos, &schemaAction); applySchemaAction(taos, &schemaAction);
} }
...@@ -522,7 +541,8 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { ...@@ -522,7 +541,8 @@ static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) {
return 0; return 0;
} }
static int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, int* tableNameLen) { static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, int* tableNameLen) {
tscDebug("taos_sml_insert get child table name through md5");
qsort(point->tags, point->tagNum, sizeof(TAOS_SML_KV), compareSmlColKv); qsort(point->tags, point->tagNum, sizeof(TAOS_SML_KV), compareSmlColKv);
SStringBuilder sb; memset(&sb, 0, sizeof(sb)); SStringBuilder sb; memset(&sb, 0, sizeof(sb));
...@@ -552,8 +572,8 @@ static int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, in ...@@ -552,8 +572,8 @@ static int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, in
static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, const char* sTableName, SArray* tagsSchema, SArray* tagsBind) { static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, const char* sTableName, SArray* tagsSchema, SArray* tagsBind) {
size_t numTags = taosArrayGetSize(tagsSchema); size_t numTags = taosArrayGetSize(tagsSchema);
char sql[TSDB_MAX_BINARY_LEN] = {0}; char* sql = malloc(tsMaxSQLStringLen+1);
int freeBytes = TSDB_MAX_BINARY_LEN; int freeBytes = tsMaxSQLStringLen + 1;
sprintf(sql, "create table if not exists %s using %s", cTableName, sTableName); sprintf(sql, "create table if not exists %s using %s", cTableName, sTableName);
snprintf(sql+strlen(sql), freeBytes-strlen(sql), "("); snprintf(sql+strlen(sql), freeBytes-strlen(sql), "(");
...@@ -569,12 +589,15 @@ static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, co ...@@ -569,12 +589,15 @@ static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, co
snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,");
} }
snprintf(sql + strlen(sql) - 1, freeBytes-strlen(sql)+1, ")"); snprintf(sql + strlen(sql) - 1, freeBytes-strlen(sql)+1, ")");
sql[strlen(sql)] = '\0';
tscDebug("create table : %s", sql); tscDebug("create table : %s", sql);
TAOS_STMT* stmt = taos_stmt_init(taos); TAOS_STMT* stmt = taos_stmt_init(taos);
int32_t code; int32_t code;
code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql)); code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql));
free(sql);
if (code != 0) { if (code != 0) {
tscError("%s", taos_stmt_errstr(stmt)); tscError("%s", taos_stmt_errstr(stmt));
return code; return code;
...@@ -592,14 +615,18 @@ static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, co ...@@ -592,14 +615,18 @@ static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, co
return code; return code;
} }
taos_stmt_close(stmt); code = taos_stmt_close(stmt);
return 0; if (code != 0) {
tscError("%s", taos_stmt_errstr(stmt));
return code;
}
return code;
} }
static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* colsSchema, SArray* rowsBind) { static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* colsSchema, SArray* rowsBind) {
size_t numCols = taosArrayGetSize(colsSchema); size_t numCols = taosArrayGetSize(colsSchema);
char sql[TSDB_MAX_BINARY_LEN]; char* sql = malloc(tsMaxSQLStringLen+1);
int32_t freeBytes = TSDB_MAX_BINARY_LEN; int32_t freeBytes = tsMaxSQLStringLen + 1 ;
sprintf(sql, "insert into ? ("); sprintf(sql, "insert into ? (");
for (int i = 0; i < numCols; ++i) { for (int i = 0; i < numCols; ++i) {
...@@ -612,6 +639,7 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols ...@@ -612,6 +639,7 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,"); snprintf(sql+strlen(sql), freeBytes-strlen(sql), "?,");
} }
snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")"); snprintf(sql + strlen(sql)-1, freeBytes-strlen(sql)+1, ")");
sql[strlen(sql)] = '\0';
tscDebug("insert rows %zu into child table %s. ", taosArrayGetSize(rowsBind), cTableName); tscDebug("insert rows %zu into child table %s. ", taosArrayGetSize(rowsBind), cTableName);
...@@ -621,6 +649,8 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols ...@@ -621,6 +649,8 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
TAOS_STMT* stmt = taos_stmt_init(taos); TAOS_STMT* stmt = taos_stmt_init(taos);
code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql)); code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql));
free(sql);
if (code != 0) { if (code != 0) {
tscError("%s", taos_stmt_errstr(stmt)); tscError("%s", taos_stmt_errstr(stmt));
return code; return code;
...@@ -665,23 +695,26 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols ...@@ -665,23 +695,26 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols
return code; return code;
} }
static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int numPoints, SHashObj* cname2points) { static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int numPoints,
SHashObj* cname2points, SArray* stableSchemas) {
for (int32_t i = 0; i < numPoints; ++i) { for (int32_t i = 0; i < numPoints; ++i) {
TAOS_SML_DATA_POINT * point = points + i; TAOS_SML_DATA_POINT * point = points + i;
if (!point->childTableName) { if (!point->childTableName) {
char childTableName[TSDB_TABLE_NAME_LEN]; char childTableName[TSDB_TABLE_NAME_LEN];
int32_t tableNameLen = TSDB_TABLE_NAME_LEN; int32_t tableNameLen = TSDB_TABLE_NAME_LEN;
getChildTableName(point, childTableName, &tableNameLen); getSmlMd5ChildTableName(point, childTableName, &tableNameLen);
point->childTableName = calloc(1, tableNameLen+1); point->childTableName = calloc(1, tableNameLen+1);
strncpy(point->childTableName, childTableName, tableNameLen); strncpy(point->childTableName, childTableName, tableNameLen);
point->childTableName[tableNameLen] = '\0'; point->childTableName[tableNameLen] = '\0';
} }
SSmlSTableSchema* stableSchema = taosArrayGet(stableSchemas, point->schemaIdx);
for (int j = 0; j < point->tagNum; ++j) { for (int j = 0; j < point->tagNum; ++j) {
TAOS_SML_KV* kv = point->tags + j; TAOS_SML_KV* kv = point->tags + j;
if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) { if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) {
int64_t ts = *(int64_t*)(kv->value); int64_t ts = *(int64_t*)(kv->value);
ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, point->schema->precision); ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, stableSchema->precision);
*(int64_t*)(kv->value) = ts; *(int64_t*)(kv->value) = ts;
} }
} }
...@@ -690,7 +723,7 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu ...@@ -690,7 +723,7 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu
TAOS_SML_KV* kv = point->fields + j; TAOS_SML_KV* kv = point->fields + j;
if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) { if (kv->type == TSDB_DATA_TYPE_TIMESTAMP) {
int64_t ts = *(int64_t*)(kv->value); int64_t ts = *(int64_t*)(kv->value);
ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, point->schema->precision); ts = convertTimePrecision(ts, TSDB_TIME_PRECISION_NANO, stableSchema->precision);
*(int64_t*)(kv->value) = ts; *(int64_t*)(kv->value) = ts;
} }
} }
...@@ -709,10 +742,12 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu ...@@ -709,10 +742,12 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu
return 0; return 0;
} }
static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints) { static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints, SArray* stableSchemas) {
int32_t code = TSDB_CODE_SUCCESS;
SHashObj* cname2points = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), SHashObj* cname2points = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY),
true, false); true, false);
arrangePointsByChildTableName(points, numPoints, cname2points); arrangePointsByChildTableName(points, numPoints, cname2points, stableSchemas);
int isNullColBind = TSDB_TRUE; int isNullColBind = TSDB_TRUE;
SArray** pCTablePoints = taosHashIterate(cname2points, NULL); SArray** pCTablePoints = taosHashIterate(cname2points, NULL);
...@@ -720,8 +755,9 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num ...@@ -720,8 +755,9 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
SArray* cTablePoints = *pCTablePoints; SArray* cTablePoints = *pCTablePoints;
TAOS_SML_DATA_POINT * point = taosArrayGetP(cTablePoints, 0); TAOS_SML_DATA_POINT * point = taosArrayGetP(cTablePoints, 0);
size_t numTags = taosArrayGetSize(point->schema->tags); SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx);
size_t numCols = taosArrayGetSize(point->schema->fields); size_t numTags = taosArrayGetSize(sTableSchema->tags);
size_t numCols = taosArrayGetSize(sTableSchema->fields);
SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND));
taosArraySetSize(tagBinds, numTags); taosArraySetSize(tagBinds, numTags);
...@@ -731,8 +767,7 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num ...@@ -731,8 +767,7 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
} }
for (int j = 0; j < point->tagNum; ++j) { for (int j = 0; j < point->tagNum; ++j) {
TAOS_SML_KV* kv = point->tags + j; TAOS_SML_KV* kv = point->tags + j;
size_t idx = TARRAY_ELEM_IDX(point->schema->tags, kv->schema); TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx);
TAOS_BIND* bind = taosArrayGet(tagBinds, idx);
bind->buffer_type = kv->type; bind->buffer_type = kv->type;
bind->length = malloc(sizeof(uintptr_t*)); bind->length = malloc(sizeof(uintptr_t*));
*bind->length = kv->length; *bind->length = kv->length;
...@@ -747,14 +782,17 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num ...@@ -747,14 +782,17 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
point = taosArrayGetP(cTablePoints, i); point = taosArrayGetP(cTablePoints, i);
TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND));
if (colBinds == NULL) {
tscError("taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, "
"num of rows: %zu, num of cols: %zu", rows, numCols);
}
for (int j = 0; j < numCols; ++j) { for (int j = 0; j < numCols; ++j) {
TAOS_BIND* bind = colBinds + j; TAOS_BIND* bind = colBinds + j;
bind->is_null = &isNullColBind; bind->is_null = &isNullColBind;
} }
for (int j = 0; j < point->fieldNum; ++j) { for (int j = 0; j < point->fieldNum; ++j) {
TAOS_SML_KV* kv = point->fields + j; TAOS_SML_KV* kv = point->fields + j;
size_t idx = TARRAY_ELEM_IDX(point->schema->fields, kv->schema); TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx;
TAOS_BIND* bind = colBinds + idx;
bind->buffer_type = kv->type; bind->buffer_type = kv->type;
bind->length = malloc(sizeof(uintptr_t*)); bind->length = malloc(sizeof(uintptr_t*));
*bind->length = kv->length; *bind->length = kv->length;
...@@ -764,14 +802,21 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num ...@@ -764,14 +802,21 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
taosArrayPush(rowsBind, &colBinds); taosArrayPush(rowsBind, &colBinds);
} }
creatChildTableIfNotExists(taos, point->childTableName, point->stableName, point->schema->tags, tagBinds); code = creatChildTableIfNotExists(taos, point->childTableName, point->stableName, sTableSchema->tags, tagBinds);
if (code == 0) {
code = insertChildTableBatch(taos, point->childTableName, sTableSchema->fields, rowsBind);
if (code != 0) {
tscError("insert into child table %s failed. error %s", point->childTableName, tstrerror(code));
}
} else {
tscError("Create Child Table %s failed, error %s", point->childTableName, tstrerror(code));
}
for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) {
TAOS_BIND* bind = taosArrayGet(tagBinds, i); TAOS_BIND* bind = taosArrayGet(tagBinds, i);
free(bind->length); free(bind->length);
} }
taosArrayDestroy(tagBinds); taosArrayDestroy(tagBinds);
insertChildTableBatch(taos, point->childTableName, point->schema->fields, rowsBind);
for (int i = 0; i < rows; ++i) { for (int i = 0; i < rows; ++i) {
TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i);
for (int j = 0; j < numCols; ++j) { for (int j = 0; j < numCols; ++j) {
...@@ -782,12 +827,14 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num ...@@ -782,12 +827,14 @@ static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t num
} }
taosArrayDestroy(rowsBind); taosArrayDestroy(rowsBind);
taosArrayDestroy(cTablePoints); taosArrayDestroy(cTablePoints);
if (code != 0) {
break;
}
pCTablePoints = taosHashIterate(cname2points, pCTablePoints); pCTablePoints = taosHashIterate(cname2points, pCTablePoints);
} }
taosHashCleanup(cname2points); taosHashCleanup(cname2points);
return 0; return code;
} }
int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
...@@ -808,7 +855,7 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { ...@@ -808,7 +855,7 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) {
goto clean_up; goto clean_up;
} }
code = insertPoints(taos, points, numPoint); code = insertPoints(taos, points, numPoint, stableSchemas);
if (code != 0) { if (code != 0) {
tscError("error insert points : %s", tstrerror(code)); tscError("error insert points : %s", tstrerror(code));
} }
...@@ -825,305 +872,886 @@ clean_up: ...@@ -825,305 +872,886 @@ clean_up:
//========================================================================= //=========================================================================
typedef enum { /* Field Escape charaters
LP_ITEM_TAG, 1: measurement Comma,Space
LP_ITEM_FIELD 2: tag_key, tag_value, field_key Comma,Equal Sign,Space
} LPItemKind; 3: field_value Double quote,Backslash
*/
static void escapeSpecialCharacter(uint8_t field, const char **pos) {
const char *cur = *pos;
if (*cur != '\\') {
return;
}
switch (field) {
case 1:
switch (*(cur + 1)) {
case ',':
case ' ':
cur++;
break;
default:
break;
}
break;
case 2:
switch (*(cur + 1)) {
case ',':
case ' ':
case '=':
cur++;
break;
default:
break;
}
break;
case 3:
switch (*(cur + 1)) {
case '"':
case '\\':
cur++;
break;
default:
break;
}
break;
default:
break;
}
*pos = cur;
}
typedef struct { static bool isValidInteger(char *str) {
SStrToken keyToken; char *c = str;
SStrToken valueToken; if (*c != '+' && *c != '-' && !isdigit(*c)) {
return false;
}
c++;
while (*c != '\0') {
if (!isdigit(*c)) {
return false;
}
c++;
}
return true;
}
char key[TSDB_COL_NAME_LEN]; static bool isValidFloat(char *str) {
int8_t type; char *c = str;
int16_t length; uint8_t has_dot, has_exp, has_sign;
has_dot = 0;
has_exp = 0;
has_sign = 0;
if (*c != '+' && *c != '-' && *c != '.' && !isdigit(*c)) {
return false;
}
if (*c == '.' && isdigit(*(c + 1))) {
has_dot = 1;
}
c++;
while (*c != '\0') {
if (!isdigit(*c)) {
switch (*c) {
case '.': {
if (!has_dot && !has_exp && isdigit(*(c + 1))) {
has_dot = 1;
} else {
return false;
}
break;
}
case 'e':
case 'E': {
if (!has_exp && isdigit(*(c - 1)) &&
(isdigit(*(c + 1)) ||
*(c + 1) == '+' ||
*(c + 1) == '-')) {
has_exp = 1;
} else {
return false;
}
break;
}
case '+':
case '-': {
if (!has_sign && has_exp && isdigit(*(c + 1))) {
has_sign = 1;
} else {
return false;
}
break;
}
default: {
return false;
}
}
}
c++;
} //while
return true;
}
char* value; static bool isTinyInt(char *pVal, uint16_t len) {
}SLPItem; if (len <= 2) {
return false;
}
if (!strcmp(&pVal[len - 2], "i8")) {
//printf("Type is int8(%s)\n", pVal);
return true;
}
return false;
}
typedef struct { static bool isTinyUint(char *pVal, uint16_t len) {
SStrToken measToken; if (len <= 2) {
SStrToken tsToken; return false;
}
if (pVal[0] == '-') {
return false;
}
if (!strcmp(&pVal[len - 2], "u8")) {
//printf("Type is uint8(%s)\n", pVal);
return true;
}
return false;
}
char sTableName[TSDB_TABLE_NAME_LEN]; static bool isSmallInt(char *pVal, uint16_t len) {
SArray* tags; if (len <= 3) {
SArray* fields; return false;
int64_t ts; }
if (!strcmp(&pVal[len - 3], "i16")) {
//printf("Type is int16(%s)\n", pVal);
return true;
}
return false;
}
} SLPPoint; static bool isSmallUint(char *pVal, uint16_t len) {
if (len <= 3) {
return false;
}
if (pVal[0] == '-') {
return false;
}
if (strcmp(&pVal[len - 3], "u16") == 0) {
//printf("Type is uint16(%s)\n", pVal);
return true;
}
return false;
}
typedef enum { static bool isInt(char *pVal, uint16_t len) {
LP_MEASUREMENT, if (len <= 3) {
LP_TAG_KEY, return false;
LP_TAG_VALUE,
LP_FIELD_KEY,
LP_FIELD_VALUE
} LPPart;
int32_t scanToCommaOrSpace(SStrToken s, int32_t start, int32_t* index, LPPart part) {
for (int32_t i = start; i < s.n; ++i) {
if (s.z[i] == ',' || s.z[i] == ' ') {
*index = i;
return 0;
} }
if (strcmp(&pVal[len - 3], "i32") == 0) {
//printf("Type is int32(%s)\n", pVal);
return true;
} }
return -1; return false;
} }
int32_t scanToEqual(SStrToken s, int32_t start, int32_t* index) { static bool isUint(char *pVal, uint16_t len) {
for (int32_t i = start; i < s.n; ++i) { if (len <= 3) {
if (s.z[i] == '=') { return false;
*index = i; }
return 0; if (pVal[0] == '-') {
return false;
} }
if (strcmp(&pVal[len - 3], "u32") == 0) {
//printf("Type is uint32(%s)\n", pVal);
return true;
} }
return -1; return false;
} }
int32_t setPointMeasurement(SLPPoint* point, SStrToken token) { static bool isBigInt(char *pVal, uint16_t len) {
point->measToken = token; if (len <= 3) {
if (point->measToken.n < TSDB_TABLE_NAME_LEN) { return false;
strncpy(point->sTableName, point->measToken.z, point->measToken.n);
point->sTableName[point->measToken.n] = '\0';
} }
return 0; if (strcmp(&pVal[len - 3], "i64") == 0) {
//printf("Type is int64(%s)\n", pVal);
return true;
}
return false;
} }
int32_t setItemKey(SLPItem* item, SStrToken key, LPPart part) { static bool isBigUint(char *pVal, uint16_t len) {
item->keyToken = key; if (len <= 3) {
if (item->keyToken.n < TSDB_COL_NAME_LEN) { return false;
strncpy(item->key, item->keyToken.z, item->keyToken.n);
item->key[item->keyToken.n] = '\0';
} }
return 0; if (pVal[0] == '-') {
return false;
}
if (strcmp(&pVal[len - 3], "u64") == 0) {
//printf("Type is uint64(%s)\n", pVal);
return true;
}
return false;
} }
int32_t setItemValue(SLPItem* item, SStrToken value, LPPart part) { static bool isFloat(char *pVal, uint16_t len) {
item->valueToken = value; if (len <= 3) {
return 0; return false;
}
if (strcmp(&pVal[len - 3], "f32") == 0) {
//printf("Type is float(%s)\n", pVal);
return true;
}
return false;
} }
int32_t parseItemValue(SLPItem* item, LPItemKind kind) { static bool isDouble(char *pVal, uint16_t len) {
char* sv = item->valueToken.z; if (len <= 3) {
char* last = item->valueToken.z + item->valueToken.n - 1; return false;
if (isdigit(sv[0]) || sv[0] == '-') {
if (*last == 'i') {
item->type = TSDB_DATA_TYPE_BIGINT;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(int64_t*)(item->value) = strtoll(sv, &endptr, 10);
} else if (*last == 'u') {
item->type = TSDB_DATA_TYPE_UBIGINT;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(uint64_t*)(item->value) = (uint64_t)strtoull(sv, &endptr, 10);
} else if (*last == 'b') {
item->type = TSDB_DATA_TYPE_TINYINT;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(int8_t*)(item->value) = (int8_t)strtoll(sv, &endptr, 10);
} else if (*last == 's') {
item->type = TSDB_DATA_TYPE_SMALLINT;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(int16_t*)(item->value) = (int16_t)strtoll(sv, &endptr, 10);
} else if (*last == 'w') {
item->type = TSDB_DATA_TYPE_INT;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(int32_t*)(item->value) = (int32_t)strtoll(sv, &endptr, 10);
} else if (*last == 'f') {
item->type = TSDB_DATA_TYPE_FLOAT;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(float*)(item->value) = (float)strtold(sv, &endptr);
} else {
item->type = TSDB_DATA_TYPE_DOUBLE;
item->length = (int16_t)tDataTypes[item->type].bytes;
item->value = malloc(item->length);
char* endptr = NULL;
*(double*)(item->value) = strtold(sv, &endptr);
}
} else if ((sv[0] == 'L' && sv[1] =='"') || sv[0] == '"' ) {
if (sv[0] == 'L') {
item->type = TSDB_DATA_TYPE_NCHAR;
uint32_t bytes = item->valueToken.n - 3;
item->length = bytes;
item->value = malloc(bytes);
memcpy(item->value, sv+2, bytes);
} else if (sv[0]=='"'){
item->type = TSDB_DATA_TYPE_BINARY;
uint32_t bytes = item->valueToken.n - 2;
item->length = bytes;
item->value = malloc(bytes);
memcpy(item->value, sv+1, bytes);
}
} else if (sv[0] == 't' || sv[0] == 'f' || sv[0]=='T' || sv[0] == 'F') {
item->type = TSDB_DATA_TYPE_BOOL;
item->length = tDataTypes[item->type].bytes;
item->value = malloc(tDataTypes[item->type].bytes);
*(uint8_t*)(item->value) = tolower(sv[0])=='t' ? TSDB_TRUE : TSDB_FALSE;
} }
return 0; if (strcmp(&pVal[len - 3], "f64") == 0) {
//printf("Type is double(%s)\n", pVal);
return true;
}
return false;
} }
int32_t compareLPItemKey(const void* p1, const void* p2) { static bool isBool(char *pVal, uint16_t len, bool *bVal) {
const SLPItem* t1 = p1; if ((len == 1) &&
const SLPItem* t2 = p2; (pVal[len - 1] == 't' ||
uint32_t min = (t1->keyToken.n < t2->keyToken.n) ? t1->keyToken.n : t2->keyToken.n; pVal[len - 1] == 'T')) {
int res = strncmp(t1->keyToken.z, t2->keyToken.z, min); //printf("Type is bool(%c)\n", pVal[len - 1]);
if (res != 0) { *bVal = true;
return res; return true;
}
if ((len == 1) &&
(pVal[len - 1] == 'f' ||
pVal[len - 1] == 'F')) {
//printf("Type is bool(%c)\n", pVal[len - 1]);
*bVal = false;
return true;
}
if((len == 4) &&
(!strcmp(&pVal[len - 4], "true") ||
!strcmp(&pVal[len - 4], "True") ||
!strcmp(&pVal[len - 4], "TRUE"))) {
//printf("Type is bool(%s)\n", &pVal[len - 4]);
*bVal = true;
return true;
}
if((len == 5) &&
(!strcmp(&pVal[len - 5], "false") ||
!strcmp(&pVal[len - 5], "False") ||
!strcmp(&pVal[len - 5], "FALSE"))) {
//printf("Type is bool(%s)\n", &pVal[len - 5]);
*bVal = false;
return true;
}
return false;
}
static bool isBinary(char *pVal, uint16_t len) {
//binary: "abc"
if (len < 2) {
return false;
}
//binary
if (pVal[0] == '"' && pVal[len - 1] == '"') {
//printf("Type is binary(%s)\n", pVal);
return true;
}
return false;
}
static bool isNchar(char *pVal, uint16_t len) {
//nchar: L"abc"
if (len < 3) {
return false;
}
if (pVal[0] == 'L' && pVal[1] == '"' && pVal[len - 1] == '"') {
//printf("Type is nchar(%s)\n", pVal);
return true;
}
return false;
}
static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) {
if (len == 0) {
return true;
}
if ((len == 1) && pVal[0] == '0') {
*tsType = SML_TIME_STAMP_NOW;
//printf("Type is timestamp(%s)\n", pVal);
return true;
}
if (len < 2) {
return false;
}
//No appendix use usec as default
if (isdigit(pVal[len - 1]) && isdigit(pVal[len - 2])) {
*tsType = SML_TIME_STAMP_MICRO_SECONDS;
//printf("Type is timestamp(%s)\n", pVal);
return true;
}
if (pVal[len - 1] == 's') {
switch (pVal[len - 2]) {
case 'm':
*tsType = SML_TIME_STAMP_MILLI_SECONDS;
break;
case 'u':
*tsType = SML_TIME_STAMP_MICRO_SECONDS;
break;
case 'n':
*tsType = SML_TIME_STAMP_NANO_SECONDS;
break;
default:
if (isdigit(pVal[len - 2])) {
*tsType = SML_TIME_STAMP_SECONDS;
break;
} else { } else {
return (int)(t1->keyToken.n) - (int)(t2->keyToken.n); return false;
} }
}
//printf("Type is timestamp(%s)\n", pVal);
return true;
}
return false;
} }
int32_t setPointTimeStamp(SLPPoint* point, SStrToken tsToken) { //len does not include '\0' from value.
point->tsToken = tsToken; static bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
return 0; uint16_t len) {
if (len <= 0) {
return false;
}
//integer number
if (isTinyInt(value, len)) {
pVal->type = TSDB_DATA_TYPE_TINYINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 2] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
int8_t val = (int8_t)strtoll(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isTinyUint(value, len)) {
pVal->type = TSDB_DATA_TYPE_UTINYINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 2] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
uint8_t val = (uint8_t)strtoul(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isSmallInt(value, len)) {
pVal->type = TSDB_DATA_TYPE_SMALLINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
int16_t val = (int16_t)strtoll(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isSmallUint(value, len)) {
pVal->type = TSDB_DATA_TYPE_USMALLINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
uint16_t val = (uint16_t)strtoul(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
//memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isInt(value, len)) {
pVal->type = TSDB_DATA_TYPE_INT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
int32_t val = (int32_t)strtoll(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isUint(value, len)) {
pVal->type = TSDB_DATA_TYPE_UINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
uint32_t val = (uint32_t)strtoul(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isBigInt(value, len)) {
pVal->type = TSDB_DATA_TYPE_BIGINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
int64_t val = (int64_t)strtoll(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isBigUint(value, len)) {
pVal->type = TSDB_DATA_TYPE_UBIGINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidInteger(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
uint64_t val = (uint64_t)strtoul(value, NULL, 10);
memcpy(pVal->value, &val, pVal->length);
return true;
}
//floating number
if (isFloat(value, len)) {
pVal->type = TSDB_DATA_TYPE_FLOAT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidFloat(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
float val = (float)strtold(value, NULL);
memcpy(pVal->value, &val, pVal->length);
return true;
}
if (isDouble(value, len)) {
pVal->type = TSDB_DATA_TYPE_DOUBLE;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
value[len - 3] = '\0';
if (!isValidFloat(value)) {
return false;
}
pVal->value = calloc(pVal->length, 1);
double val = (double)strtold(value, NULL);
memcpy(pVal->value, &val, pVal->length);
return true;
}
//binary
if (isBinary(value, len)) {
pVal->type = TSDB_DATA_TYPE_BINARY;
pVal->length = len - 2;
pVal->value = calloc(pVal->length, 1);
//copy after "
memcpy(pVal->value, value + 1, pVal->length);
return true;
}
//nchar
if (isNchar(value, len)) {
pVal->type = TSDB_DATA_TYPE_NCHAR;
pVal->length = len - 3;
pVal->value = calloc(pVal->length, 1);
//copy after L"
memcpy(pVal->value, value + 2, pVal->length);
return true;
}
//bool
bool bVal;
if (isBool(value, len, &bVal)) {
pVal->type = TSDB_DATA_TYPE_BOOL;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
pVal->value = calloc(pVal->length, 1);
memcpy(pVal->value, &bVal, pVal->length);
return true;
}
//Handle default(no appendix) as float
if (isValidInteger(value) || isValidFloat(value)) {
pVal->type = TSDB_DATA_TYPE_FLOAT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
pVal->value = calloc(pVal->length, 1);
float val = (float)strtold(value, NULL);
memcpy(pVal->value, &val, pVal->length);
return true;
}
return false;
} }
int32_t parsePointTime(SLPPoint* point) { static int32_t getTimeStampValue(char *value, uint16_t len,
if (point->tsToken.n <= 0) { SMLTimeStampType type, int64_t *ts) {
point->ts = taosGetTimestampNs();
if (len >= 2) {
for (int i = 0; i < len - 2; ++i) {
if(!isdigit(value[i])) {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
}
}
//No appendix or no timestamp given (len = 0)
if (len >= 1 && isdigit(value[len - 1]) && type != SML_TIME_STAMP_NOW) {
type = SML_TIME_STAMP_MICRO_SECONDS;
}
if (len != 0) {
*ts = (int64_t)strtoll(value, NULL, 10);
} else { } else {
char* endptr = NULL; type = SML_TIME_STAMP_NOW;
point->ts = strtoll(point->tsToken.z, &endptr, 10);
char* last = point->tsToken.z + point->tsToken.n - 1;
if (*last == 's') {
point->ts *= (int64_t)1e9;
} else if (*last == 'a') {
point->ts *= (int64_t)1e6;
} else if (*last == 'u') {
point->ts *= (int64_t)1e3;
} else if (*last == 'b') {
point->ts *= 1;
} }
switch (type) {
case SML_TIME_STAMP_NOW: {
*ts = taosGetTimestampNs();
break;
} }
return 0; case SML_TIME_STAMP_SECONDS: {
*ts = (int64_t)(*ts * 1e9);
break;
}
case SML_TIME_STAMP_MILLI_SECONDS: {
*ts = convertTimePrecision(*ts, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_NANO);
break;
}
case SML_TIME_STAMP_MICRO_SECONDS: {
*ts = convertTimePrecision(*ts, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO);
break;
}
case SML_TIME_STAMP_NANO_SECONDS: {
*ts = *ts * 1;
break;
}
default: {
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
}
return TSDB_CODE_SUCCESS;
} }
int32_t tscParseLine(SStrToken line, SLPPoint* point) { static int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
int32_t pos = 0; uint16_t len) {
int32_t ret;
SMLTimeStampType type;
int64_t tsVal;
int32_t start = 0; if (!isTimeStamp(value, len, &type)) {
int32_t err = scanToCommaOrSpace(line, start, &pos, LP_MEASUREMENT); return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
if (err != 0) {
tscError("a");
return err;
} }
SStrToken measurement = {.z = line.z+start, .n = pos-start}; ret = getTimeStampValue(value, len, type, &tsVal);
setPointMeasurement(point, measurement); if (ret) {
point->tags = taosArrayInit(64, sizeof(SLPItem)); return ret;
start = pos; }
while (line.z[start] == ',') { tscDebug("Timestamp after conversion:%"PRId64, tsVal);
SLPItem item;
start++; pVal->type = TSDB_DATA_TYPE_TIMESTAMP;
err = scanToEqual(line, start, &pos); pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
if (err != 0) { pVal->value = calloc(pVal->length, 1);
tscError("b"); memcpy(pVal->value, &tsVal, pVal->length);
goto error; return TSDB_CODE_SUCCESS;
}
static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index) {
const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS;
int len = 0;
char key[] = "_ts";
char *value = NULL;
start = cur = *index;
*pTS = calloc(1, sizeof(TAOS_SML_KV));
while(*cur != '\0') {
cur++;
len++;
} }
SStrToken tagKey = {.z = line.z + start, .n = pos-start}; if (len > 0) {
setItemKey(&item, tagKey, LP_TAG_KEY); value = calloc(len + 1, 1);
memcpy(value, start, len);
}
start = pos + 1; ret = convertSmlTimeStamp(*pTS, value, len);
err = scanToCommaOrSpace(line, start, &pos, LP_TAG_VALUE); if (ret) {
if (err != 0) { free(value);
tscError("c"); free(*pTS);
goto error; return ret;
} }
free(value);
SStrToken tagValue = {.z = line.z + start, .n = pos-start}; (*pTS)->key = calloc(sizeof(key), 1);
setItemValue(&item, tagValue, LP_TAG_VALUE); memcpy((*pTS)->key, key, sizeof(key));
return ret;
}
parseItemValue(&item, LP_ITEM_TAG); static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index) {
taosArrayPush(point->tags, &item); const char *cur = *index;
char key[TSDB_COL_NAME_LEN];
uint16_t len = 0;
start = pos; //key field cannot start with digit
if (isdigit(*cur)) {
tscError("Tag key cannnot start with digit\n");
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
while (*cur != '\0') {
if (len > TSDB_COL_NAME_LEN) {
tscDebug("Key field cannot exceeds 65 characters");
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
//unescaped '=' identifies a tag key
if (*cur == '=' && *(cur - 1) != '\\') {
break;
}
//Escape special character
if (*cur == '\\') {
escapeSpecialCharacter(2, &cur);
} }
key[len] = *cur;
cur++;
len++;
}
key[len] = '\0';
taosArraySort(point->tags, compareLPItemKey); pKV->key = calloc(len + 1, 1);
memcpy(pKV->key, key, len + 1);
//tscDebug("Key:%s|len:%d", pKV->key, len);
*index = cur + 1;
return TSDB_CODE_SUCCESS;
}
point->fields = taosArrayInit(64, sizeof(SLPItem));
start++; static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
do { bool *is_last_kv) {
SLPItem item; const char *start, *cur;
char *value = NULL;
uint16_t len = 0;
start = cur = *index;
err = scanToEqual(line, start, &pos); while (1) {
if (err != 0) { // unescaped ',' or ' ' or '\0' identifies a value
goto error; if ((*cur == ',' || *cur == ' ' || *cur == '\0') && *(cur - 1) != '\\') {
//unescaped ' ' or '\0' indicates end of value
*is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false;
break;
}
//Escape special character
if (*cur == '\\') {
escapeSpecialCharacter(2, &cur);
}
cur++;
len++;
} }
SStrToken fieldKey = {.z = line.z + start, .n = pos- start};
setItemKey(&item, fieldKey, LP_FIELD_KEY);
start = pos + 1; value = calloc(len + 1, 1);
err = scanToCommaOrSpace(line, start, &pos, LP_FIELD_VALUE); memcpy(value, start, len);
if (err != 0) { value[len] = '\0';
goto error; if (!convertSmlValueType(pKV, value, len)) {
//free previous alocated key field
free(pKV->key);
free(value);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
SStrToken fieldValue = {.z = line.z + start, .n = pos - start}; free(value);
setItemValue(&item, fieldValue, LP_TAG_VALUE);
parseItemValue(&item, LP_ITEM_FIELD); *index = (*cur == '\0') ? cur : cur + 1;
taosArrayPush(point->fields, &item); return TSDB_CODE_SUCCESS;
}
start = pos + 1; static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index,
} while (line.z[pos] == ','); uint8_t *has_tags) {
const char *cur = *index;
uint16_t len = 0;
pSml->stableName = calloc(TSDB_TABLE_NAME_LEN, 1);
if (isdigit(*cur)) {
tscError("Measurement field cannnot start with digit");
free(pSml->stableName);
pSml->stableName = NULL;
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
while (*cur != '\0') {
if (len > TSDB_TABLE_NAME_LEN) {
tscError("Measurement field cannot exceeds 193 characters");
free(pSml->stableName);
pSml->stableName = NULL;
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
}
//first unescaped comma or space identifies measurement
//if space detected first, meaning no tag in the input
if (*cur == ',' && *(cur - 1) != '\\') {
*has_tags = 1;
break;
}
if (*cur == ' ' && *(cur - 1) != '\\') {
break;
}
//Comma, Space, Backslash needs to be escaped if any
if (*cur == '\\') {
escapeSpecialCharacter(1, &cur);
}
pSml->stableName[len] = *cur;
cur++;
len++;
}
pSml->stableName[len] = '\0';
*index = cur + 1;
tscDebug("Stable name in measurement:%s|len:%d", pSml->stableName, len);
return TSDB_CODE_SUCCESS;
}
static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
const char **index, bool isField, TAOS_SML_DATA_POINT* smlData) {
const char *cur = *index;
int32_t ret = TSDB_CODE_SUCCESS;
TAOS_SML_KV *pkv;
bool is_last_kv = false;
int32_t capacity = 0;
if (isField) {
capacity = 64;
*pKVs = calloc(capacity, sizeof(TAOS_SML_KV));
// leave space for timestamp;
pkv = *pKVs;
pkv++;
} else {
capacity = 8;
*pKVs = calloc(capacity, sizeof(TAOS_SML_KV));
pkv = *pKVs;
}
while (*cur != '\0') {
ret = parseSmlKey(pkv, &cur);
if (ret) {
tscError("Unable to parse key field");
goto error;
}
ret = parseSmlValue(pkv, &cur, &is_last_kv);
if (ret) {
tscError("Unable to parse value field");
goto error;
}
if (!isField &&
(strcasecmp(pkv->key, "ID") == 0) && pkv->type == TSDB_DATA_TYPE_BINARY) {
smlData->childTableName = malloc( pkv->length + 1);
memcpy(smlData->childTableName, pkv->value, pkv->length);
smlData->childTableName[pkv->length] = '\0';
free(pkv->key);
free(pkv->value);
} else {
*num_kvs += 1;
}
if (is_last_kv) {
//tscDebug("last key-value field detected");
goto done;
}
taosArraySort(point->fields, compareLPItemKey); //reallocate addtional memory for more kvs
TAOS_SML_KV *more_kvs = NULL;
SStrToken tsToken = {.z = line.z+start, .n = line.n-start}; if (isField) {
setPointTimeStamp(point, tsToken); if ((*num_kvs + 2) > capacity) {
parsePointTime(point); capacity *= 3; capacity /= 2;
more_kvs = realloc(*pKVs, capacity * sizeof(TAOS_SML_KV));
} else {
more_kvs = *pKVs;
}
} else {
if ((*num_kvs + 1) > capacity) {
capacity *= 3; capacity /= 2;
more_kvs = realloc(*pKVs, capacity * sizeof(TAOS_SML_KV));
} else {
more_kvs = *pKVs;
}
}
if (!more_kvs) {
goto error;
}
*pKVs = more_kvs;
//move pKV points to next TAOS_SML_KV block
if (isField) {
pkv = *pKVs + *num_kvs + 1;
} else {
pkv = *pKVs + *num_kvs;
}
}
goto done; goto done;
error: error:
// free array return ret;
return err; done:
done: *index = cur;
return 0; return ret;
} }
static void moveTimeStampToFirstKv(TAOS_SML_DATA_POINT** smlData, TAOS_SML_KV *ts) {
TAOS_SML_KV* tsField = (*smlData)->fields;
tsField->length = ts->length;
tsField->type = ts->type;
tsField->value = malloc(ts->length);
tsField->key = malloc(strlen(ts->key) + 1);
memcpy(tsField->key, ts->key, strlen(ts->key) + 1);
memcpy(tsField->value, ts->value, ts->length);
(*smlData)->fieldNum = (*smlData)->fieldNum + 1;
free(ts->key);
free(ts->value);
free(ts);
}
int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* failedLines) { int32_t tscParseLine(const char* sql, TAOS_SML_DATA_POINT* smlData) {
for (int32_t i = 0; i < numLines; ++i) { const char* index = sql;
SStrToken tkLine = {.z = lines[i], .n = (uint32_t)strlen(lines[i])}; int32_t ret = TSDB_CODE_SUCCESS;
SLPPoint point; uint8_t has_tags = 0;
tscParseLine(tkLine, &point); TAOS_SML_KV *timestamp = NULL;
taosArrayPush(points, &point);
ret = parseSmlMeasurement(smlData, &index, &has_tags);
if (ret) {
tscError("Unable to parse measurement");
return ret;
} }
return 0; tscDebug("Parse measurement finished, has_tags:%d", has_tags);
}
void destroyLPPoint(void* p) { //Parse Tags
SLPPoint* lpPoint = p; if (has_tags) {
for (int i=0; i<taosArrayGetSize(lpPoint->fields); ++i) { ret = parseSmlKvPairs(&smlData->tags, &smlData->tagNum, &index, false, smlData);
SLPItem* item = taosArrayGet(lpPoint->fields, i); if (ret) {
free(item->value); tscError("Unable to parse tag");
return ret;
}
} }
taosArrayDestroy(lpPoint->fields); tscDebug("Parse tags finished, num of tags:%d", smlData->tagNum);
for (int i=0; i<taosArrayGetSize(lpPoint->tags); ++i) { //Parse fields
SLPItem* item = taosArrayGet(lpPoint->tags, i); ret = parseSmlKvPairs(&smlData->fields, &smlData->fieldNum, &index, true, smlData);
free(item->value); if (ret) {
tscError("Unable to parse field");
return ret;
} }
taosArrayDestroy(lpPoint->tags); tscDebug("Parse fields finished, num of fields:%d", smlData->fieldNum);
//Parse timestamp
ret = parseSmlTimeStamp(&timestamp, &index);
if (ret) {
tscError("Unable to parse timestamp");
return ret;
}
moveTimeStampToFirstKv(&smlData, timestamp);
tscDebug("Parse timestamp finished");
return TSDB_CODE_SUCCESS;
} }
//=========================================================================
void destroySmlDataPoint(TAOS_SML_DATA_POINT* point) { void destroySmlDataPoint(TAOS_SML_DATA_POINT* point) {
for (int i=0; i<point->tagNum; ++i) { for (int i=0; i<point->tagNum; ++i) {
free((point->tags+i)->key); free((point->tags+i)->key);
...@@ -1139,76 +1767,67 @@ void destroySmlDataPoint(TAOS_SML_DATA_POINT* point) { ...@@ -1139,76 +1767,67 @@ void destroySmlDataPoint(TAOS_SML_DATA_POINT* point) {
free(point->childTableName); free(point->childTableName);
} }
int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { int32_t tscParseLines(char* lines[], int numLines, SArray* points, SArray* failedLines) {
SArray* lpPoints = taosArrayInit(numLines, sizeof(SLPPoint)); for (int32_t i = 0; i < numLines; ++i) {
tscParseLines(lines, numLines, lpPoints, NULL); TAOS_SML_DATA_POINT point = {0};
int32_t code = tscParseLine(lines[i], &point);
if (code != TSDB_CODE_SUCCESS) {
tscError("data point line parse failed. line %d : %s", i, lines[i]);
destroySmlDataPoint(&point);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} else {
tscDebug("data point line parse success. line %d", i);
}
size_t numPoints = taosArrayGetSize(lpPoints); taosArrayPush(points, &point);
TAOS_SML_DATA_POINT* points = calloc(numPoints, sizeof(TAOS_SML_DATA_POINT)); }
for (int i = 0; i < numPoints; ++i) { return 0;
SLPPoint* lpPoint = taosArrayGet(lpPoints, i); }
TAOS_SML_DATA_POINT* point = points+i;
point->stableName = calloc(1, strlen(lpPoint->sTableName)+1);
strncpy(point->stableName, lpPoint->sTableName, strlen(lpPoint->sTableName));
point->stableName[strlen(lpPoint->sTableName)] = '\0';
size_t lpTagSize = taosArrayGetSize(lpPoint->tags);
point->tags = calloc(lpTagSize, sizeof(TAOS_SML_KV));
point->tagNum = (int)lpTagSize;
for (int j=0; j<lpTagSize; ++j) {
SLPItem* lpTag = taosArrayGet(lpPoint->tags, j);
TAOS_SML_KV* tagKv = point->tags + j;
size_t kenLen = strlen(lpTag->key); int taos_insert_lines(TAOS* taos, char* lines[], int numLines) {
tagKv->key = calloc(1, kenLen+1); int32_t code = 0;
strncpy(tagKv->key, lpTag->key, kenLen);
tagKv->key[kenLen] = '\0';
tagKv->type = lpTag->type; if (numLines <= 0 || numLines > 65536) {
tagKv->length = lpTag->length; tscError("taos_insert_lines numLines should be between 1 and 65536. numLines: %d", numLines);
tagKv->value = malloc(tagKv->length); code = TSDB_CODE_TSC_APP_ERROR;
memcpy(tagKv->value, lpTag->value, tagKv->length); return code;
} }
size_t lpFieldsSize = taosArrayGetSize(lpPoint->fields); for (int i = 0; i < numLines; ++i) {
point->fields = calloc(lpFieldsSize + 1, sizeof(TAOS_SML_KV)); if (lines[i] == NULL) {
point->fieldNum = (int)(lpFieldsSize + 1); tscError("taos_insert_lines line %d is NULL", i);
code = TSDB_CODE_TSC_APP_ERROR;
TAOS_SML_KV* tsField = point->fields + 0; return code;
char tsKey[256]; }
snprintf(tsKey, 256, "_%s_ts", point->stableName); }
size_t tsKeyLen = strlen(tsKey);
tsField->key = calloc(1, tsKeyLen+1);
strncpy(tsField->key, tsKey, tsKeyLen);
tsField->key[tsKeyLen] = '\0';
tsField->type = TSDB_DATA_TYPE_TIMESTAMP;
tsField->length = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
tsField->value = malloc(tsField->length);
memcpy(tsField->value, &(lpPoint->ts), tsField->length);
for (int j=0; j<lpFieldsSize; ++j) { SArray* lpPoints = taosArrayInit(numLines, sizeof(TAOS_SML_DATA_POINT));
SLPItem* lpField = taosArrayGet(lpPoint->fields, j); if (lpPoints == NULL) {
TAOS_SML_KV* fieldKv = point->fields + j + 1; tscError("taos_insert_lines failed to allocate memory");
return TSDB_CODE_TSC_OUT_OF_MEMORY;
}
size_t kenLen = strlen(lpField->key); tscDebug("taos_insert_lines begin inserting %d lines, first line: %s", numLines, lines[0]);
fieldKv->key = calloc(1, kenLen+1); code = tscParseLines(lines, numLines, lpPoints, NULL);
strncpy(fieldKv->key, lpField->key, kenLen); size_t numPoints = taosArrayGetSize(lpPoints);
fieldKv->key[kenLen] = '\0';
fieldKv->type = lpField->type; if (code != 0) {
fieldKv->length = lpField->length; goto cleanup;
fieldKv->value = malloc(fieldKv->length);
memcpy(fieldKv->value, lpField->value, fieldKv->length);
}
} }
taos_sml_insert(taos, points, (int)numPoints); TAOS_SML_DATA_POINT* points = TARRAY_GET_START(lpPoints);
code = taos_sml_insert(taos, points, (int)numPoints);
if (code != 0) {
tscError("taos_sml_insert error: %s", tstrerror((code)));
}
cleanup:
tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code);
for (int i=0; i<numPoints; ++i) { for (int i=0; i<numPoints; ++i) {
destroySmlDataPoint(points+i); destroySmlDataPoint(points+i);
} }
free(points);
taosArrayDestroyEx(lpPoints, destroyLPPoint); taosArrayDestroy(lpPoints);
return 0; return code;
} }
...@@ -47,6 +47,7 @@ typedef struct SNormalStmt { ...@@ -47,6 +47,7 @@ typedef struct SNormalStmt {
typedef struct SMultiTbStmt { typedef struct SMultiTbStmt {
bool nameSet; bool nameSet;
bool tagSet; bool tagSet;
bool subSet;
uint64_t currentUid; uint64_t currentUid;
char *sqlstr; char *sqlstr;
uint32_t tbNum; uint32_t tbNum;
...@@ -54,6 +55,7 @@ typedef struct SMultiTbStmt { ...@@ -54,6 +55,7 @@ typedef struct SMultiTbStmt {
SStrToken stbname; SStrToken stbname;
SStrToken values; SStrToken values;
SArray *tags; SArray *tags;
STableDataBlocks *lastBlock;
SHashObj *pTableHash; SHashObj *pTableHash;
SHashObj *pTableBlockHashList; // data block for each table SHashObj *pTableBlockHashList; // data block for each table
} SMultiTbStmt; } SMultiTbStmt;
...@@ -347,7 +349,7 @@ int32_t fillTablesColumnsNull(SSqlObj* pSql) { ...@@ -347,7 +349,7 @@ int32_t fillTablesColumnsNull(SSqlObj* pSql) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// functions for insertion statement preparation // functions for insertion statement preparation
static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, TAOS_BIND* bind, int32_t colNum) { static FORCE_INLINE int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, TAOS_BIND* bind, int32_t colNum) {
if (bind->is_null != NULL && *(bind->is_null)) { if (bind->is_null != NULL && *(bind->is_null)) {
setNull(data + param->offset, param->type, param->bytes); setNull(data + param->offset, param->type, param->bytes);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -746,25 +748,25 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, ...@@ -746,25 +748,25 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
size = 1; *(uint8_t *)(data + param->offset) = *(uint8_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_USMALLINT:
size = 2; *(uint16_t *)(data + param->offset) = *(uint16_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UINT:
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
size = 4; *(uint32_t *)(data + param->offset) = *(uint32_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_UBIGINT:
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
size = 8; *(uint64_t *)(data + param->offset) = *(uint64_t *)bind->buffer;
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
...@@ -790,7 +792,6 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, ...@@ -790,7 +792,6 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
return TSDB_CODE_TSC_INVALID_VALUE; return TSDB_CODE_TSC_INVALID_VALUE;
} }
memcpy(data + param->offset, bind->buffer, size);
if (param->offset == 0) { if (param->offset == 0) {
if (tsCheckTimestamp(pBlock, data + param->offset) != TSDB_CODE_SUCCESS) { if (tsCheckTimestamp(pBlock, data + param->offset) != TSDB_CODE_SUCCESS) {
tscError("invalid timestamp"); tscError("invalid timestamp");
...@@ -801,6 +802,58 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param, ...@@ -801,6 +802,58 @@ static int doBindParam(STableDataBlocks* pBlock, char* data, SParamInfo* param,
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t insertStmtGenLastBlock(STableDataBlocks** lastBlock, STableDataBlocks* pBlock) {
*lastBlock = (STableDataBlocks*)malloc(sizeof(STableDataBlocks));
memcpy(*lastBlock, pBlock, sizeof(STableDataBlocks));
(*lastBlock)->cloned = true;
(*lastBlock)->pData = NULL;
(*lastBlock)->ordered = true;
(*lastBlock)->prevTS = INT64_MIN;
(*lastBlock)->size = sizeof(SSubmitBlk);
(*lastBlock)->tsSource = -1;
return TSDB_CODE_SUCCESS;
}
static int32_t insertStmtGenBlock(STscStmt* pStmt, STableDataBlocks** pBlock, STableMeta* pTableMeta, SName* name) {
int32_t code = 0;
if (pStmt->mtb.lastBlock == NULL) {
tscError("no previous data block");
return TSDB_CODE_TSC_APP_ERROR;
}
int32_t msize = tscGetTableMetaSize(pTableMeta);
int32_t tsize = sizeof(STableDataBlocks) + msize;
void *t = malloc(tsize);
*pBlock = t;
memcpy(*pBlock, pStmt->mtb.lastBlock, sizeof(STableDataBlocks));
t = (char *)t + sizeof(STableDataBlocks);
(*pBlock)->pTableMeta = t;
memcpy((*pBlock)->pTableMeta, pTableMeta, msize);
(*pBlock)->pData = malloc((*pBlock)->nAllocSize);
(*pBlock)->vgId = (*pBlock)->pTableMeta->vgId;
tNameAssign(&(*pBlock)->tableName, name);
SSubmitBlk* blk = (SSubmitBlk*)(*pBlock)->pData;
memset(blk, 0, sizeof(*blk));
code = tsSetBlockInfo(blk, pTableMeta, 0);
if (code != TSDB_CODE_SUCCESS) {
STMT_RET(code);
}
return TSDB_CODE_SUCCESS;
}
static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) { static int doBindBatchParam(STableDataBlocks* pBlock, SParamInfo* param, TAOS_MULTI_BIND* bind, int32_t rowNum) {
if (bind->buffer_type != param->type || !isValidDataType(param->type)) { if (bind->buffer_type != param->type || !isValidDataType(param->type)) {
...@@ -1227,11 +1280,11 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) { ...@@ -1227,11 +1280,11 @@ int stmtParseInsertTbTags(SSqlObj* pSql, STscStmt* pStmt) {
pStmt->mtb.tbname = sToken; pStmt->mtb.tbname = sToken;
pStmt->mtb.nameSet = false; pStmt->mtb.nameSet = false;
if (pStmt->mtb.pTableHash == NULL) { if (pStmt->mtb.pTableHash == NULL) {
pStmt->mtb.pTableHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); pStmt->mtb.pTableHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false);
} }
if (pStmt->mtb.pTableBlockHashList == NULL) { if (pStmt->mtb.pTableBlockHashList == NULL) {
pStmt->mtb.pTableBlockHashList = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); pStmt->mtb.pTableBlockHashList = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false);
} }
pStmt->mtb.tagSet = true; pStmt->mtb.tagSet = true;
...@@ -1522,6 +1575,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { ...@@ -1522,6 +1575,7 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) {
int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) { int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags) {
STscStmt* pStmt = (STscStmt*)stmt; STscStmt* pStmt = (STscStmt*)stmt;
int32_t code = 0;
if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) { if (stmt == NULL || pStmt->pSql == NULL || pStmt->taos == NULL) {
STMT_RET(TSDB_CODE_TSC_DISCONNECTED); STMT_RET(TSDB_CODE_TSC_DISCONNECTED);
...@@ -1559,6 +1613,11 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1559,6 +1613,11 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData; SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData;
pCmd->batchSize = pBlk->numOfRows; pCmd->batchSize = pBlk->numOfRows;
if (pBlk->numOfRows == 0) {
(*t1)->prevTS = INT64_MIN;
}
tsSetBlockInfo(pBlk, (*t1)->pTableMeta, pBlk->numOfRows);
taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES); taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES);
...@@ -1566,6 +1625,51 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1566,6 +1625,51 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
STMT_RET(TSDB_CODE_SUCCESS); STMT_RET(TSDB_CODE_SUCCESS);
} }
if (pStmt->mtb.subSet && taosHashGetSize(pStmt->mtb.pTableHash) > 0) {
STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(pCmd, 0);
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
char sTableName[TSDB_TABLE_FNAME_LEN];
strncpy(sTableName, pTableMeta->sTableName, sizeof(sTableName));
SStrToken tname = {0};
tname.type = TK_STRING;
tname.z = (char *)name;
tname.n = (uint32_t)strlen(name);
SName fullname = {0};
tscSetTableFullName(&fullname, &tname, pSql);
memcpy(&pTableMetaInfo->name, &fullname, sizeof(fullname));
code = tscGetTableMeta(pSql, pTableMetaInfo);
if (code != TSDB_CODE_SUCCESS) {
STMT_RET(code);
}
pTableMeta = pTableMetaInfo->pTableMeta;
if (strcmp(sTableName, pTableMeta->sTableName)) {
tscError("0x%"PRIx64" only tables belongs to one stable is allowed", pSql->self);
STMT_RET(TSDB_CODE_TSC_APP_ERROR);
}
STableDataBlocks* pBlock = NULL;
insertStmtGenBlock(pStmt, &pBlock, pTableMeta, &pTableMetaInfo->name);
pCmd->batchSize = 0;
pStmt->mtb.currentUid = pTableMeta->id.uid;
pStmt->mtb.tbNum++;
taosHashPut(pCmd->insertParam.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES);
taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES);
taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid));
tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid);
STMT_RET(TSDB_CODE_SUCCESS);
}
if (pStmt->mtb.tagSet) { if (pStmt->mtb.tagSet) {
pStmt->mtb.tbname = tscReplaceStrToken(&pSql->sqlstr, &pStmt->mtb.tbname, name); pStmt->mtb.tbname = tscReplaceStrToken(&pSql->sqlstr, &pStmt->mtb.tbname, name);
} else { } else {
...@@ -1594,7 +1698,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1594,7 +1698,7 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
pCmd->insertParam.pTableBlockHashList = hashList; pCmd->insertParam.pTableBlockHashList = hashList;
} }
int32_t code = tsParseSql(pStmt->pSql, true); code = tsParseSql(pStmt->pSql, true);
if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_TSC_ACTION_IN_PROGRESS) {
// wait for the callback function to post the semaphore // wait for the callback function to post the semaphore
tsem_wait(&pStmt->pSql->rspSem); tsem_wait(&pStmt->pSql->rspSem);
...@@ -1622,6 +1726,10 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1622,6 +1726,10 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES); taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES);
taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid));
if (pStmt->mtb.lastBlock == NULL) {
insertStmtGenLastBlock(&pStmt->mtb.lastBlock, pBlock);
}
tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid); tscDebug("0x%"PRIx64" table:%s is prepared, uid:%" PRIx64, pSql->self, name, pStmt->mtb.currentUid);
} }
...@@ -1629,7 +1737,17 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags ...@@ -1629,7 +1737,17 @@ int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags
} }
int taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name) {
STscStmt* pStmt = (STscStmt*)stmt;
pStmt->mtb.subSet = true;
return taos_stmt_set_tbname_tags(stmt, name, NULL);
}
int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
STscStmt* pStmt = (STscStmt*)stmt;
pStmt->mtb.subSet = false;
return taos_stmt_set_tbname_tags(stmt, name, NULL); return taos_stmt_set_tbname_tags(stmt, name, NULL);
} }
...@@ -1653,6 +1771,7 @@ int taos_stmt_close(TAOS_STMT* stmt) { ...@@ -1653,6 +1771,7 @@ int taos_stmt_close(TAOS_STMT* stmt) {
if (pStmt->pSql && pStmt->pSql->res.code != 0) { if (pStmt->pSql && pStmt->pSql->res.code != 0) {
rmMeta = true; rmMeta = true;
} }
tscDestroyDataBlock(pStmt->mtb.lastBlock, rmMeta);
pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta); pStmt->mtb.pTableBlockHashList = tscDestroyBlockHashTable(pStmt->mtb.pTableBlockHashList, rmMeta);
taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList); taosHashCleanup(pStmt->pSql->cmd.insertParam.pTableBlockHashList);
pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL; pStmt->pSql->cmd.insertParam.pTableBlockHashList = NULL;
...@@ -1687,6 +1806,8 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) { ...@@ -1687,6 +1806,8 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
pStmt->last = STMT_BIND; pStmt->last = STMT_BIND;
tscDebug("tableId:%" PRIu64 ", try to bind one row", pStmt->mtb.currentUid);
STMT_RET(insertStmtBindParam(pStmt, bind)); STMT_RET(insertStmtBindParam(pStmt, bind));
} else { } else {
STMT_RET(normalStmtBindParam(pStmt, bind)); STMT_RET(normalStmtBindParam(pStmt, bind));
......
...@@ -2023,6 +2023,11 @@ static int32_t checkForUdf(SSqlObj* pSql, SQueryInfo* pQueryInfo, SArray* pSelec ...@@ -2023,6 +2023,11 @@ static int32_t checkForUdf(SSqlObj* pSql, SQueryInfo* pQueryInfo, SArray* pSelec
*/ */
static SUdfInfo* isValidUdf(SArray* pUdfInfo, const char* name, int32_t len) { static SUdfInfo* isValidUdf(SArray* pUdfInfo, const char* name, int32_t len) {
if(pUdfInfo == NULL){
tscError("udfinfo is null");
return NULL;
}
size_t t = taosArrayGetSize(pUdfInfo); size_t t = taosArrayGetSize(pUdfInfo);
for(int32_t i = 0; i < t; ++i) { for(int32_t i = 0; i < t; ++i) {
SUdfInfo* pUdf = taosArrayGet(pUdfInfo, i); SUdfInfo* pUdf = taosArrayGet(pUdfInfo, i);
......
...@@ -1517,12 +1517,6 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) { ...@@ -1517,12 +1517,6 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
} }
tfree(pDataBlock->pData); tfree(pDataBlock->pData);
tfree(pDataBlock->params);
// free the refcount for metermeta
if (pDataBlock->pTableMeta != NULL) {
tfree(pDataBlock->pTableMeta);
}
if (removeMeta) { if (removeMeta) {
char name[TSDB_TABLE_FNAME_LEN] = {0}; char name[TSDB_TABLE_FNAME_LEN] = {0};
...@@ -1531,7 +1525,17 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) { ...@@ -1531,7 +1525,17 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); taosHashRemove(tscTableMetaInfo, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
} }
if (!pDataBlock->cloned) {
tfree(pDataBlock->params);
// free the refcount for metermeta
if (pDataBlock->pTableMeta != NULL) {
tfree(pDataBlock->pTableMeta);
}
tscDestroyBoundColumnInfo(&pDataBlock->boundColumnInfo); tscDestroyBoundColumnInfo(&pDataBlock->boundColumnInfo);
}
tfree(pDataBlock); tfree(pDataBlock);
} }
...@@ -1710,12 +1714,14 @@ int32_t tscCreateDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOff ...@@ -1710,12 +1714,14 @@ int32_t tscCreateDataBlock(size_t defaultSize, int32_t rowSize, int32_t startOff
dataBuf->nAllocSize = dataBuf->headerSize * 2; dataBuf->nAllocSize = dataBuf->headerSize * 2;
} }
dataBuf->pData = calloc(1, dataBuf->nAllocSize); //dataBuf->pData = calloc(1, dataBuf->nAllocSize);
dataBuf->pData = malloc(dataBuf->nAllocSize);
if (dataBuf->pData == NULL) { if (dataBuf->pData == NULL) {
tscError("failed to allocated memory, reason:%s", strerror(errno)); tscError("failed to allocated memory, reason:%s", strerror(errno));
tfree(dataBuf); tfree(dataBuf);
return TSDB_CODE_TSC_OUT_OF_MEMORY; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
memset(dataBuf->pData, 0, sizeof(SSubmitBlk));
//Here we keep the tableMeta to avoid it to be remove by other threads. //Here we keep the tableMeta to avoid it to be remove by other threads.
dataBuf->pTableMeta = tscTableMetaDup(pTableMeta); dataBuf->pTableMeta = tscTableMetaDup(pTableMeta);
...@@ -1956,16 +1962,14 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) { ...@@ -1956,16 +1962,14 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeBlockMap) { static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeBlockMap) {
pInsertParam->numOfTables = (int32_t) taosHashGetSize(pInsertParam->pTableBlockHashList); pInsertParam->numOfTables = (int32_t) taosHashGetSize(pInsertParam->pTableBlockHashList);
if (pInsertParam->pTableNameList == NULL) { if (pInsertParam->pTableNameList == NULL) {
pInsertParam->pTableNameList = calloc(pInsertParam->numOfTables, POINTER_BYTES); pInsertParam->pTableNameList = malloc(pInsertParam->numOfTables * POINTER_BYTES);
} else {
memset(pInsertParam->pTableNameList, 0, pInsertParam->numOfTables * POINTER_BYTES);
} }
STableDataBlocks **p1 = taosHashIterate(pInsertParam->pTableBlockHashList, NULL); STableDataBlocks **p1 = taosHashIterate(pInsertParam->pTableBlockHashList, NULL);
int32_t i = 0; int32_t i = 0;
while(p1) { while(p1) {
STableDataBlocks* pBlocks = *p1; STableDataBlocks* pBlocks = *p1;
tfree(pInsertParam->pTableNameList[i]); //tfree(pInsertParam->pTableNameList[i]);
pInsertParam->pTableNameList[i++] = tNameDup(&pBlocks->tableName); pInsertParam->pTableNameList[i++] = tNameDup(&pBlocks->tableName);
p1 = taosHashIterate(pInsertParam->pTableBlockHashList, p1); p1 = taosHashIterate(pInsertParam->pTableBlockHashList, p1);
...@@ -2009,14 +2013,12 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl ...@@ -2009,14 +2013,12 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta); int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize + sizeof(STColumn) * tscGetNumOfColumns(pOneTableBlock->pTableMeta);
if (dataBuf->nAllocSize < destSize) { if (dataBuf->nAllocSize < destSize) {
while (dataBuf->nAllocSize < destSize) { dataBuf->nAllocSize = (uint32_t)(destSize * 1.5);
dataBuf->nAllocSize = (uint32_t)(dataBuf->nAllocSize * 1.5);
}
char* tmp = realloc(dataBuf->pData, dataBuf->nAllocSize); char* tmp = realloc(dataBuf->pData, dataBuf->nAllocSize);
if (tmp != NULL) { if (tmp != NULL) {
dataBuf->pData = tmp; dataBuf->pData = tmp;
memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size); //memset(dataBuf->pData + dataBuf->size, 0, dataBuf->nAllocSize - dataBuf->size);
} else { // failed to allocate memory, free already allocated memory and return error code } else { // failed to allocate memory, free already allocated memory and return error code
tscError("0x%"PRIx64" failed to allocate memory for merging submit block, size:%d", pInsertParam->objectId, dataBuf->nAllocSize); tscError("0x%"PRIx64" failed to allocate memory for merging submit block, size:%d", pInsertParam->objectId, dataBuf->nAllocSize);
...@@ -3559,6 +3561,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t ...@@ -3559,6 +3561,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
pNew->pTscObj = pSql->pTscObj; pNew->pTscObj = pSql->pTscObj;
pNew->signature = pNew; pNew->signature = pNew;
pNew->sqlstr = strdup(pSql->sqlstr); pNew->sqlstr = strdup(pSql->sqlstr);
tsem_init(&pNew->rspSem, 0, 0);
SSqlCmd* pnCmd = &pNew->cmd; SSqlCmd* pnCmd = &pNew->cmd;
memcpy(pnCmd, pCmd, sizeof(SSqlCmd)); memcpy(pnCmd, pCmd, sizeof(SSqlCmd));
...@@ -3919,7 +3922,7 @@ bool tscIsUpdateQuery(SSqlObj* pSql) { ...@@ -3919,7 +3922,7 @@ bool tscIsUpdateQuery(SSqlObj* pSql) {
} }
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
return ((pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) || TSDB_SQL_USE_DB == pCmd->command); return ((pCmd->command >= TSDB_SQL_INSERT && pCmd->command <= TSDB_SQL_DROP_DNODE) || TSDB_SQL_RESET_CACHE == pCmd->command || TSDB_SQL_USE_DB == pCmd->command);
} }
char* tscGetSqlStr(SSqlObj* pSql) { char* tscGetSqlStr(SSqlObj* pSql) {
...@@ -4384,7 +4387,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta) { ...@@ -4384,7 +4387,7 @@ STableMeta* tscTableMetaDup(STableMeta* pTableMeta) {
assert(pTableMeta != NULL); assert(pTableMeta != NULL);
size_t size = tscGetTableMetaSize(pTableMeta); size_t size = tscGetTableMetaSize(pTableMeta);
STableMeta* p = calloc(1, size); STableMeta* p = malloc(size);
memcpy(p, pTableMeta, size); memcpy(p, pTableMeta, size);
return p; return p;
} }
...@@ -4768,15 +4771,6 @@ static void freeContent(void* p) { ...@@ -4768,15 +4771,6 @@ static void freeContent(void* p) {
tfree(ptr); tfree(ptr);
} }
static int32_t contCompare(const void* p1, const void* p2) {
int32_t ret = strcmp(p1, p2);
if (ret == 0) {
return 0;
} else {
return ret > 0 ? 1:-1;
}
}
int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray) { int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t length, SArray* pNameArray) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
...@@ -4824,7 +4818,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt ...@@ -4824,7 +4818,7 @@ int tscTransferTableNameList(SSqlObj *pSql, const char *pNameList, int32_t lengt
} }
taosArraySort(pNameArray, nameComparFn); taosArraySort(pNameArray, nameComparFn);
taosArrayRemoveDuplicate(pNameArray, contCompare, freeContent); taosArrayRemoveDuplicate(pNameArray, nameComparFn, freeContent);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -306,7 +306,7 @@ bool tIsValidName(const SName* name) { ...@@ -306,7 +306,7 @@ bool tIsValidName(const SName* name) {
SName* tNameDup(const SName* name) { SName* tNameDup(const SName* name) {
assert(name != NULL); assert(name != NULL);
SName* p = calloc(1, sizeof(SName)); SName* p = malloc(sizeof(SName));
memcpy(p, name, sizeof(SName)); memcpy(p, name, sizeof(SName));
return p; return p;
} }
......
...@@ -37,13 +37,6 @@ ...@@ -37,13 +37,6 @@
<maven.test.jvmargs></maven.test.jvmargs> <maven.test.jvmargs></maven.test.jvmargs>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<!-- for restful -->
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
...@@ -52,12 +45,18 @@ ...@@ -52,12 +45,18 @@
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
<version>1.2.58</version> <version>1.2.76</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>30.0-jre</version> <version>30.1.1-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -171,11 +171,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -171,11 +171,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
// do nothing // do nothing
} }
@Override private void checkResultSetTypeAndResultSetConcurrency(int resultSetType, int resultSetConcurrency) throws SQLException {
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
switch (resultSetType) { switch (resultSetType) {
case ResultSet.TYPE_FORWARD_ONLY: case ResultSet.TYPE_FORWARD_ONLY:
break; break;
...@@ -194,7 +190,14 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -194,7 +190,14 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
default: default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
} }
}
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
checkResultSetTypeAndResultSetConcurrency(resultSetType, resultSetConcurrency);
return createStatement(); return createStatement();
} }
...@@ -203,24 +206,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti ...@@ -203,24 +206,7 @@ public abstract class AbstractConnection extends WrapperImpl implements Connecti
if (isClosed()) if (isClosed())
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_CONNECTION_CLOSED);
switch (resultSetType) { checkResultSetTypeAndResultSetConcurrency(resultSetType, resultSetConcurrency);
case ResultSet.TYPE_FORWARD_ONLY:
break;
case ResultSet.TYPE_SCROLL_INSENSITIVE:
case ResultSet.TYPE_SCROLL_SENSITIVE:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
switch (resultSetConcurrency) {
case ResultSet.CONCUR_READ_ONLY:
break;
case ResultSet.CONCUR_UPDATABLE:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNSUPPORTED_METHOD);
default:
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_VARIABLE);
}
return prepareStatement(sql); return prepareStatement(sql);
} }
......
...@@ -326,7 +326,7 @@ public class EmptyResultSet implements ResultSet { ...@@ -326,7 +326,7 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getFetchDirection() throws SQLException { public int getFetchDirection() throws SQLException {
return 0; return ResultSet.FETCH_FORWARD;
} }
@Override @Override
...@@ -341,12 +341,12 @@ public class EmptyResultSet implements ResultSet { ...@@ -341,12 +341,12 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getType() throws SQLException { public int getType() throws SQLException {
return 0; return ResultSet.TYPE_FORWARD_ONLY;
} }
@Override @Override
public int getConcurrency() throws SQLException { public int getConcurrency() throws SQLException {
return 0; return ResultSet.CONCUR_READ_ONLY;
} }
@Override @Override
...@@ -746,7 +746,7 @@ public class EmptyResultSet implements ResultSet { ...@@ -746,7 +746,7 @@ public class EmptyResultSet implements ResultSet {
@Override @Override
public int getHoldability() throws SQLException { public int getHoldability() throws SQLException {
return 0; return ResultSet.CLOSE_CURSORS_AT_COMMIT;
} }
@Override @Override
......
...@@ -40,7 +40,7 @@ public class TSDBErrorNumbers { ...@@ -40,7 +40,7 @@ public class TSDBErrorNumbers {
public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet public static final int ERROR_JNI_FETCH_END = 0x2358; // fetch to the end of resultSet
public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed public static final int ERROR_JNI_OUT_OF_MEMORY = 0x2359; // JNI alloc memory failed
private static final Set<Integer> errorNumbers = new HashSet(); private static final Set<Integer> errorNumbers = new HashSet<>();
static { static {
errorNumbers.add(ERROR_CONNECTION_CLOSED); errorNumbers.add(ERROR_CONNECTION_CLOSED);
......
...@@ -348,4 +348,13 @@ public class TSDBJNIConnector { ...@@ -348,4 +348,13 @@ public class TSDBJNIConnector {
} }
private native int closeStmt(long stmt, long con); private native int closeStmt(long stmt, long con);
public void insertLines(String[] lines) throws SQLException {
int code = insertLinesImp(lines, this.taos);
if (code != TSDBConstants.JNI_SUCCESS) {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to insertLines");
}
}
private native int insertLinesImp(String[] lines, long conn);
} }
...@@ -61,7 +61,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet { ...@@ -61,7 +61,7 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
return; return;
// parse row data // parse row data
for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) { for (int rowIndex = 0; rowIndex < data.size(); rowIndex++) {
List<Object> row = new ArrayList(); List<Object> row = new ArrayList<>();
JSONArray jsonRow = data.getJSONArray(rowIndex); JSONArray jsonRow = data.getJSONArray(rowIndex);
for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) { for (int colIndex = 0; colIndex < this.metaData.getColumnCount(); colIndex++) {
row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type)); row.add(parseColumnData(jsonRow, colIndex, columns.get(colIndex).taos_type));
......
...@@ -9,6 +9,7 @@ import org.apache.http.client.protocol.HttpClientContext; ...@@ -9,6 +9,7 @@ import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.conn.ConnectionKeepAliveStrategy; import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeaderElementIterator; import org.apache.http.message.BasicHeaderElementIterator;
...@@ -34,7 +35,11 @@ public class HttpClientPoolUtil { ...@@ -34,7 +35,11 @@ public class HttpClientPoolUtil {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE); connectionManager.setDefaultMaxPerRoute(DEFAULT_MAX_PER_ROUTE);
connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL); connectionManager.setMaxTotal(DEFAULT_MAX_TOTAL);
httpClient = HttpClients.custom().setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY).setConnectionManager(connectionManager).build(); httpClient = HttpClients.custom()
.setKeepAliveStrategy(DEFAULT_KEEP_ALIVE_STRATEGY)
.setConnectionManager(connectionManager)
.setRetryHandler(new DefaultHttpRequestRetryHandler(3, true))
.build();
} }
} }
......
...@@ -4,14 +4,14 @@ public class OSUtils { ...@@ -4,14 +4,14 @@ public class OSUtils {
private static final String OS = System.getProperty("os.name").toLowerCase(); private static final String OS = System.getProperty("os.name").toLowerCase();
public static boolean isWindows() { public static boolean isWindows() {
return OS.indexOf("win") >= 0; return OS.contains("win");
} }
public static boolean isMac() { public static boolean isMac() {
return OS.indexOf("mac") >= 0; return OS.contains("mac");
} }
public static boolean isLinux() { public static boolean isLinux() {
return OS.indexOf("nux") >= 0; return OS.contains("nux");
} }
} }
...@@ -16,7 +16,7 @@ package com.taosdata.jdbc.utils; ...@@ -16,7 +16,7 @@ package com.taosdata.jdbc.utils;
public class SqlSyntaxValidator { public class SqlSyntaxValidator {
private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe"}; private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe", "reset"};
private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"}; private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"};
private static final String[] querySQL = {"select", "show", "describe"}; private static final String[] querySQL = {"select", "show", "describe"};
...@@ -61,29 +61,11 @@ public class SqlSyntaxValidator { ...@@ -61,29 +61,11 @@ public class SqlSyntaxValidator {
public static boolean isUseSql(String sql) { public static boolean isUseSql(String sql) {
return sql.trim().toLowerCase().startsWith("use"); return sql.trim().toLowerCase().startsWith("use");
// || sql.trim().toLowerCase().matches("create\\s*database.*") || sql.toLowerCase().toLowerCase().matches("drop\\s*database.*");
}
public static boolean isShowSql(String sql) {
return sql.trim().toLowerCase().startsWith("show");
}
public static boolean isDescribeSql(String sql) {
return sql.trim().toLowerCase().startsWith("describe");
}
public static boolean isInsertSql(String sql) {
return sql.trim().toLowerCase().startsWith("insert") || sql.trim().toLowerCase().startsWith("import");
} }
public static boolean isSelectSql(String sql) { public static boolean isSelectSql(String sql) {
return sql.trim().toLowerCase().startsWith("select"); return sql.trim().toLowerCase().startsWith("select");
} }
public static boolean isShowDatabaseSql(String sql) {
return sql.trim().toLowerCase().matches("show\\s*databases");
}
} }
...@@ -7,9 +7,9 @@ import java.util.concurrent.atomic.AtomicLong; ...@@ -7,9 +7,9 @@ import java.util.concurrent.atomic.AtomicLong;
public class TaosInfo implements TaosInfoMBean { public class TaosInfo implements TaosInfoMBean {
private static volatile TaosInfo instance; private static volatile TaosInfo instance;
private AtomicLong connect_open = new AtomicLong(); private final AtomicLong connect_open = new AtomicLong();
private AtomicLong connect_close = new AtomicLong(); private final AtomicLong connect_close = new AtomicLong();
private AtomicLong statement_count = new AtomicLong(); private final AtomicLong statement_count = new AtomicLong();
static { static {
try { try {
......
...@@ -22,8 +22,7 @@ import java.util.stream.IntStream; ...@@ -22,8 +22,7 @@ import java.util.stream.IntStream;
public class Utils { public class Utils {
private static Pattern ptn = Pattern.compile(".*?'"); private static final Pattern ptn = Pattern.compile(".*?'");
private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter(); private static final DateTimeFormatter milliSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSS").toFormatter();
private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter(); private static final DateTimeFormatter microSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSS").toFormatter();
private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter(); private static final DateTimeFormatter nanoSecFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss.SSSSSSSSS").toFormatter();
...@@ -74,7 +73,7 @@ public class Utils { ...@@ -74,7 +73,7 @@ public class Utils {
public static String escapeSingleQuota(String origin) { public static String escapeSingleQuota(String origin) {
Matcher m = ptn.matcher(origin); Matcher m = ptn.matcher(origin);
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
int end = 0; int end = 0;
while (m.find()) { while (m.find()) {
end = m.end(); end = m.end();
...@@ -87,7 +86,7 @@ public class Utils { ...@@ -87,7 +86,7 @@ public class Utils {
sb.append(seg); sb.append(seg);
} }
} else { // len > 1 } else { // len > 1
sb.append(seg.substring(0, seg.length() - 2)); sb.append(seg, 0, seg.length() - 2);
char lastcSec = seg.charAt(seg.length() - 2); char lastcSec = seg.charAt(seg.length() - 2);
if (lastcSec == '\\') { if (lastcSec == '\\') {
sb.append("\\'"); sb.append("\\'");
...@@ -195,7 +194,7 @@ public class Utils { ...@@ -195,7 +194,7 @@ public class Utils {
public static String formatTimestamp(Timestamp timestamp) { public static String formatTimestamp(Timestamp timestamp) {
int nanos = timestamp.getNanos(); int nanos = timestamp.getNanos();
if (nanos % 1000000l != 0) if (nanos % 1000000L != 0)
return timestamp.toLocalDateTime().format(microSecFormatter); return timestamp.toLocalDateTime().format(microSecFormatter);
return timestamp.toLocalDateTime().format(milliSecFormatter); return timestamp.toLocalDateTime().format(milliSecFormatter);
} }
......
...@@ -5,7 +5,6 @@ import org.junit.Assert; ...@@ -5,7 +5,6 @@ import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import javax.management.OperationsException;
import java.sql.*; import java.sql.*;
import java.util.Properties; import java.util.Properties;
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.SQLWarning; import java.sql.SQLWarning;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.lang.management.ManagementFactory; import static org.junit.Assert.assertEquals;
import java.lang.management.RuntimeMXBean; import static org.junit.Assert.assertTrue;
import java.lang.management.ThreadMXBean;
public class TSDBJNIConnectorTest { public class TSDBJNIConnectorTest {
...@@ -114,6 +114,10 @@ public class TSDBJNIConnectorTest { ...@@ -114,6 +114,10 @@ public class TSDBJNIConnectorTest {
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL); throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
} }
// close statement // close statement
connector.executeQuery("use d");
String[] lines = new String[] {"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"};
connector.insertLines(lines);
// close connection // close connection
connector.closeConnection(); connector.closeConnection();
......
package com.taosdata.jdbc; package com.taosdata.jdbc;
import com.taosdata.jdbc.rs.RestfulParameterMetaData;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
......
...@@ -2,7 +2,6 @@ package com.taosdata.jdbc; ...@@ -2,7 +2,6 @@ package com.taosdata.jdbc;
import org.junit.*; import org.junit.*;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -26,7 +25,7 @@ public class TSDBPreparedStatementTest { ...@@ -26,7 +25,7 @@ public class TSDBPreparedStatementTest {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
pstmt_insert.setInt(2, 2); pstmt_insert.setInt(2, 2);
pstmt_insert.setLong(3, 3l); pstmt_insert.setLong(3, 3L);
pstmt_insert.setFloat(4, 3.14f); pstmt_insert.setFloat(4, 3.14f);
pstmt_insert.setDouble(5, 3.1415); pstmt_insert.setDouble(5, 3.1415);
pstmt_insert.setShort(6, (short) 6); pstmt_insert.setShort(6, (short) 6);
...@@ -53,8 +52,8 @@ public class TSDBPreparedStatementTest { ...@@ -53,8 +52,8 @@ public class TSDBPreparedStatementTest {
Assert.assertEquals(ts, rs.getTimestamp(1).getTime()); Assert.assertEquals(ts, rs.getTimestamp(1).getTime());
Assert.assertEquals(2, rs.getInt(2)); Assert.assertEquals(2, rs.getInt(2));
Assert.assertEquals(2, rs.getInt("f1")); Assert.assertEquals(2, rs.getInt("f1"));
Assert.assertEquals(3l, rs.getLong(3)); Assert.assertEquals(3L, rs.getLong(3));
Assert.assertEquals(3l, rs.getLong("f2")); Assert.assertEquals(3L, rs.getLong("f2"));
Assert.assertEquals(3.14f, rs.getFloat(4), 0.0); Assert.assertEquals(3.14f, rs.getFloat(4), 0.0);
Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0); Assert.assertEquals(3.14f, rs.getFloat("f3"), 0.0);
Assert.assertEquals(3.1415, rs.getDouble(5), 0.0); Assert.assertEquals(3.1415, rs.getDouble(5), 0.0);
...@@ -312,14 +311,14 @@ public class TSDBPreparedStatementTest { ...@@ -312,14 +311,14 @@ public class TSDBPreparedStatementTest {
Random r = new Random(); Random r = new Random();
s.setTableName("weather_test"); s.setTableName("weather_test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s2.add(null); s2.add(null);
...@@ -330,7 +329,7 @@ public class TSDBPreparedStatementTest { ...@@ -330,7 +329,7 @@ public class TSDBPreparedStatementTest {
s.setNString(1, s2, 4); s.setNString(1, s2, 4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Float> s3 = new ArrayList<Float>(); ArrayList<Float> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s3.add(null); s3.add(null);
...@@ -341,7 +340,7 @@ public class TSDBPreparedStatementTest { ...@@ -341,7 +340,7 @@ public class TSDBPreparedStatementTest {
s.setFloat(2, s3); s.setFloat(2, s3);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Double> s4 = new ArrayList<Double>(); ArrayList<Double> s4 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s4.add(null); s4.add(null);
...@@ -352,7 +351,7 @@ public class TSDBPreparedStatementTest { ...@@ -352,7 +351,7 @@ public class TSDBPreparedStatementTest {
s.setDouble(3, s4); s.setDouble(3, s4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<Long> ts2 = new ArrayList<Long>(); ArrayList<Long> ts2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
ts2.add(null); ts2.add(null);
...@@ -379,13 +378,13 @@ public class TSDBPreparedStatementTest { ...@@ -379,13 +378,13 @@ public class TSDBPreparedStatementTest {
if (i % random == 0) { if (i % random == 0) {
sb.add(null); sb.add(null);
} else { } else {
sb.add(i % 2 == 0 ? true : false); sb.add(i % 2 == 0);
} }
} }
s.setBoolean(6, sb); s.setBoolean(6, sb);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s5 = new ArrayList<String>(); ArrayList<String> s5 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s5.add(null); s5.add(null);
...@@ -424,14 +423,14 @@ public class TSDBPreparedStatementTest { ...@@ -424,14 +423,14 @@ public class TSDBPreparedStatementTest {
Random r = new Random(); Random r = new Random();
s.setTableName("weather_test"); s.setTableName("weather_test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s2.add(null); s2.add(null);
...@@ -442,7 +441,7 @@ public class TSDBPreparedStatementTest { ...@@ -442,7 +441,7 @@ public class TSDBPreparedStatementTest {
s.setNString(1, s2, 4); s.setNString(1, s2, 4);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s3 = new ArrayList<String>(); ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
if (i % random == 0) { if (i % random == 0) {
s3.add(null); s3.add(null);
...@@ -471,7 +470,7 @@ public class TSDBPreparedStatementTest { ...@@ -471,7 +470,7 @@ public class TSDBPreparedStatementTest {
public void bindDataWithSingleTagTest() throws SQLException { public void bindDataWithSingleTagTest() throws SQLException {
Statement stmt = conn.createStatement(); Statement stmt = conn.createStatement();
String types[] = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"}; String[] types = new String[]{"tinyint", "smallint", "int", "bigint", "bool", "float", "double", "binary(10)", "nchar(10)"};
for (String type : types) { for (String type : types) {
stmt.execute("drop table if exists weather_test"); stmt.execute("drop table if exists weather_test");
...@@ -510,21 +509,21 @@ public class TSDBPreparedStatementTest { ...@@ -510,21 +509,21 @@ public class TSDBPreparedStatementTest {
} }
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
int random = 10 + r.nextInt(5); int random = 10 + r.nextInt(5);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s2.add("分支" + i % 4); s2.add("分支" + i % 4);
} }
s.setNString(1, s2, 10); s.setNString(1, s2, 10);
random = 10 + r.nextInt(5); random = 10 + r.nextInt(5);
ArrayList<String> s3 = new ArrayList<String>(); ArrayList<String> s3 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s3.add("test" + i % 4); s3.add("test" + i % 4);
} }
...@@ -561,13 +560,13 @@ public class TSDBPreparedStatementTest { ...@@ -561,13 +560,13 @@ public class TSDBPreparedStatementTest {
s.setTagString(1, "test"); s.setTagString(1, "test");
ArrayList<Long> ts = new ArrayList<Long>(); ArrayList<Long> ts = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
ts.add(System.currentTimeMillis() + i); ts.add(System.currentTimeMillis() + i);
} }
s.setTimestamp(0, ts); s.setTimestamp(0, ts);
ArrayList<String> s2 = new ArrayList<String>(); ArrayList<String> s2 = new ArrayList<>();
for (int i = 0; i < numOfRows; i++) { for (int i = 0; i < numOfRows; i++) {
s2.add("test" + i % 4); s2.add("test" + i % 4);
} }
...@@ -788,7 +787,7 @@ public class TSDBPreparedStatementTest { ...@@ -788,7 +787,7 @@ public class TSDBPreparedStatementTest {
public void setBigDecimal() throws SQLException { public void setBigDecimal() throws SQLException {
// given // given
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
BigDecimal bigDecimal = new BigDecimal(3.14444); BigDecimal bigDecimal = new BigDecimal("3.14444");
// when // when
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
...@@ -999,7 +998,7 @@ public class TSDBPreparedStatementTest { ...@@ -999,7 +998,7 @@ public class TSDBPreparedStatementTest {
long ts = System.currentTimeMillis(); long ts = System.currentTimeMillis();
pstmt_insert.setTimestamp(1, new Timestamp(ts)); pstmt_insert.setTimestamp(1, new Timestamp(ts));
pstmt_insert.setInt(2, 2); pstmt_insert.setInt(2, 2);
pstmt_insert.setLong(3, 3l); pstmt_insert.setLong(3, 3L);
pstmt_insert.setFloat(4, 3.14f); pstmt_insert.setFloat(4, 3.14f);
pstmt_insert.setDouble(5, 3.1415); pstmt_insert.setDouble(5, 3.1415);
pstmt_insert.setShort(6, (short) 6); pstmt_insert.setShort(6, (short) 6);
......
...@@ -95,13 +95,13 @@ public class TSDBResultSetTest { ...@@ -95,13 +95,13 @@ public class TSDBResultSetTest {
@Test @Test
public void getBigDecimal() throws SQLException { public void getBigDecimal() throws SQLException {
BigDecimal f1 = rs.getBigDecimal("f1"); BigDecimal f1 = rs.getBigDecimal("f1");
Assert.assertEquals(1609430400000l, f1.longValue()); Assert.assertEquals(1609430400000L, f1.longValue());
BigDecimal f2 = rs.getBigDecimal("f2"); BigDecimal f2 = rs.getBigDecimal("f2");
Assert.assertEquals(1, f2.intValue()); Assert.assertEquals(1, f2.intValue());
BigDecimal f3 = rs.getBigDecimal("f3"); BigDecimal f3 = rs.getBigDecimal("f3");
Assert.assertEquals(100l, f3.longValue()); Assert.assertEquals(100L, f3.longValue());
BigDecimal f4 = rs.getBigDecimal("f4"); BigDecimal f4 = rs.getBigDecimal("f4");
Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f); Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f);
...@@ -125,13 +125,13 @@ public class TSDBResultSetTest { ...@@ -125,13 +125,13 @@ public class TSDBResultSetTest {
Assert.assertEquals(1, Ints.fromByteArray(f2)); Assert.assertEquals(1, Ints.fromByteArray(f2));
byte[] f3 = rs.getBytes("f3"); byte[] f3 = rs.getBytes("f3");
Assert.assertEquals(100l, Longs.fromByteArray(f3)); Assert.assertEquals(100L, Longs.fromByteArray(f3));
byte[] f4 = rs.getBytes("f4"); byte[] f4 = rs.getBytes("f4");
Assert.assertEquals(3.1415f, Float.valueOf(new String(f4)), 0.000000f); Assert.assertEquals(3.1415f, Float.parseFloat(new String(f4)), 0.000000f);
byte[] f5 = rs.getBytes("f5"); byte[] f5 = rs.getBytes("f5");
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); Assert.assertEquals(3.1415926, Double.parseDouble(new String(f5)), 0.000000f);
byte[] f6 = rs.getBytes("f6"); byte[] f6 = rs.getBytes("f6");
Assert.assertTrue(Arrays.equals("abc".getBytes(), f6)); Assert.assertTrue(Arrays.equals("abc".getBytes(), f6));
...@@ -223,7 +223,7 @@ public class TSDBResultSetTest { ...@@ -223,7 +223,7 @@ public class TSDBResultSetTest {
Object f3 = rs.getObject("f3"); Object f3 = rs.getObject("f3");
Assert.assertEquals(Long.class, f3.getClass()); Assert.assertEquals(Long.class, f3.getClass());
Assert.assertEquals(100l, f3); Assert.assertEquals(100L, f3);
Object f4 = rs.getObject("f4"); Object f4 = rs.getObject("f4");
Assert.assertEquals(Float.class, f4.getClass()); Assert.assertEquals(Float.class, f4.getClass());
...@@ -421,7 +421,7 @@ public class TSDBResultSetTest { ...@@ -421,7 +421,7 @@ public class TSDBResultSetTest {
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
public void updateLong() throws SQLException { public void updateLong() throws SQLException {
rs.updateLong(1, 1l); rs.updateLong(1, 1L);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
...@@ -3,12 +3,13 @@ package com.taosdata.jdbc.cases; ...@@ -3,12 +3,13 @@ package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.io.IOException;
import java.sql.*; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties; import java.util.Properties;
public class BadLocaleSettingTest { public class BadLocaleSettingTest {
......
package com.taosdata.jdbc.cases; package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBDriver;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -9,13 +10,13 @@ import java.util.Properties; ...@@ -9,13 +10,13 @@ import java.util.Properties;
public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
private static String host1 = "192.168.17.156"; private static final String host1 = "192.168.17.156";
private static String user1 = "root"; private static final String user1 = "root";
private static String password1 = "tqueue"; private static final String password1 = "tqueue";
private Connection conn1; private Connection conn1;
private static String host2 = "192.168.17.82"; private static final String host2 = "192.168.17.82";
private static String user2 = "root"; private static final String user2 = "root";
private static String password2 = "taosdata"; private static final String password2 = "taosdata";
private Connection conn2; private Connection conn2;
@Test @Test
...@@ -30,6 +31,7 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest { ...@@ -30,6 +31,7 @@ public class ConnectMultiTaosdByRestfulWithDifferentTokenTest {
try (Statement stmt = connection.createStatement()) { try (Statement stmt = connection.createStatement()) {
ResultSet rs = stmt.executeQuery("select server_status()"); ResultSet rs = stmt.executeQuery("select server_status()");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
Assert.assertNotNull(meta);
while (rs.next()) { while (rs.next()) {
} }
} catch (SQLException e) { } catch (SQLException e) {
......
...@@ -13,7 +13,7 @@ import java.util.Properties; ...@@ -13,7 +13,7 @@ import java.util.Properties;
public class DriverAutoloadTest { public class DriverAutoloadTest {
private Properties properties; private Properties properties;
private String host = "127.0.0.1"; private final String host = "127.0.0.1";
@Test @Test
public void testRestful() throws SQLException { public void testRestful() throws SQLException {
......
...@@ -13,9 +13,9 @@ import java.util.Random; ...@@ -13,9 +13,9 @@ import java.util.Random;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class InsertDbwithoutUseDbTest { public class InsertDbwithoutUseDbTest {
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Properties properties; private static Properties properties;
private static Random random = new Random(System.currentTimeMillis()); private static final Random random = new Random(System.currentTimeMillis());
@Test @Test
public void case001() throws ClassNotFoundException, SQLException { public void case001() throws ClassNotFoundException, SQLException {
......
...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterJniTest { ...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterJniTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static String dbName = "spec_char_test"; private static final String dbName = "spec_char_test";
private static String tbname1 = "test"; private static final String tbname1 = "test";
private static String tbname2 = "weather"; private static final String tbname2 = "weather";
private static String special_character_str_1 = "$asd$$fsfsf$"; private static final String special_character_str_1 = "$asd$$fsfsf$";
private static String special_character_str_2 = "\\\\asdfsfsf\\\\"; private static final String special_character_str_2 = "\\\\asdfsfsf\\\\";
private static String special_character_str_3 = "\\\\asdfsfsf\\"; private static final String special_character_str_3 = "\\\\asdfsfsf\\";
private static String special_character_str_4 = "?asd??fsf?sf?"; private static final String special_character_str_4 = "?asd??fsf?sf?";
private static String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$"; private static final String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$";
@Test @Test
public void testCase01() throws SQLException { public void testCase01() throws SQLException {
......
...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterRestfulTest { ...@@ -8,14 +8,14 @@ public class InsertSpecialCharacterRestfulTest {
private static final String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static Connection conn; private static Connection conn;
private static String dbName = "spec_char_test"; private static final String dbName = "spec_char_test";
private static String tbname1 = "test"; private static final String tbname1 = "test";
private static String tbname2 = "weather"; private static final String tbname2 = "weather";
private static String special_character_str_1 = "$asd$$fsfsf$"; private static final String special_character_str_1 = "$asd$$fsfsf$";
private static String special_character_str_2 = "\\\\asdfsfsf\\\\"; private static final String special_character_str_2 = "\\\\asdfsfsf\\\\";
private static String special_character_str_3 = "\\\\asdfsfsf\\"; private static final String special_character_str_3 = "\\\\asdfsfsf\\";
private static String special_character_str_4 = "?asd??fsf?sf?"; private static final String special_character_str_4 = "?asd??fsf?sf?";
private static String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$"; private static final String special_character_str_5 = "?#sd@$f(('<(s[P)>\"){]}f?s[]{}%vaew|\"fsfs^a&d*jhg)(j))(f@~!?$";
@Test @Test
public void testCase01() throws SQLException { public void testCase01() throws SQLException {
......
...@@ -8,13 +8,13 @@ import java.util.Properties; ...@@ -8,13 +8,13 @@ import java.util.Properties;
public class InvalidResultSetPointerTest { public class InvalidResultSetPointerTest {
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
private static final String dbName = "test"; private static final String dbName = "test";
private static final String stbName = "stb"; private static final String stbName = "stb";
private static final String tbName = "tb"; private static final String tbName = "tb";
private static Connection connection; private static Connection connection;
private static int numOfSTb = 30000; private static final int numOfSTb = 30000;
private static int numOfTb = 3; private static final int numOfTb = 3;
private static int numOfThreads = 100; private static int numOfThreads = 100;
@Test @Test
...@@ -74,7 +74,7 @@ public class InvalidResultSetPointerTest { ...@@ -74,7 +74,7 @@ public class InvalidResultSetPointerTest {
b = numOfSTb % numOfThreads; b = numOfSTb % numOfThreads;
} }
multiThreadingClass instance[] = new multiThreadingClass[numOfThreads]; multiThreadingClass[] instance = new multiThreadingClass[numOfThreads];
int last = 0; int last = 0;
for (int i = 0; i < numOfThreads; i++) { for (int i = 0; i < numOfThreads; i++) {
......
...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit; ...@@ -9,8 +9,7 @@ import java.util.concurrent.TimeUnit;
public class MultiThreadsWithSameStatementTest { public class MultiThreadsWithSameStatementTest {
private static class Service {
private class Service {
public Connection conn; public Connection conn;
public Statement stmt; public Statement stmt;
......
package com.taosdata.jdbc.cases;
import com.taosdata.jdbc.TSDBDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.sql.*;
import java.util.Properties;
import static org.junit.Assert.assertEquals;
public class ResetQueryCacheTest {
static Connection connection;
static Statement statement;
static String host = "127.0.0.1";
@Before
public void init() {
try {
Properties properties = new Properties();
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties);
statement = connection.createStatement();
} catch (SQLException e) {
return;
}
}
@Test
public void testResetQueryCache() throws SQLException {
String resetSql = "reset query cache";
statement.execute(resetSql);
}
@After
public void close() {
try {
if (statement != null)
statement.close();
if (connection != null)
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
...@@ -16,9 +16,9 @@ import static org.junit.Assert.assertEquals; ...@@ -16,9 +16,9 @@ import static org.junit.Assert.assertEquals;
public class StableTest { public class StableTest {
private static Connection connection; private static Connection connection;
private static String dbName = "test"; private static final String dbName = "test";
private static String stbName = "st"; private static final String stbName = "st";
private static String host = "127.0.0.1"; private static final String host = "127.0.0.1";
@BeforeClass @BeforeClass
public static void createDatabase() { public static void createDatabase() {
......
...@@ -25,7 +25,7 @@ public class TaosInfoMonitorTest { ...@@ -25,7 +25,7 @@ public class TaosInfoMonitorTest {
return null; return null;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
connectionList.stream().forEach(conn -> { connectionList.forEach(conn -> {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("show databases"); ResultSet rs = stmt.executeQuery("show databases");
while (rs.next()) { while (rs.next()) {
...@@ -37,7 +37,7 @@ public class TaosInfoMonitorTest { ...@@ -37,7 +37,7 @@ public class TaosInfoMonitorTest {
} }
}); });
connectionList.stream().forEach(conn -> { connectionList.forEach(conn -> {
try { try {
conn.close(); conn.close();
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);
......
...@@ -22,7 +22,7 @@ public class TimestampPrecisionInNanoInJniTest { ...@@ -22,7 +22,7 @@ public class TimestampPrecisionInNanoInJniTest {
private static final long timestamp3 = (timestamp1 + 10) * 1000_000 + 123456; private static final long timestamp3 = (timestamp1 + 10) * 1000_000 + 123456;
private static final Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); private static final Format format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private static final String date1 = format.format(new Date(timestamp1)); private static final String date1 = format.format(new Date(timestamp1));
private static final String date4 = format.format(new Date(timestamp1 + 10l)); private static final String date4 = format.format(new Date(timestamp1 + 10L));
private static final String date2 = date1 + "123455"; private static final String date2 = date1 + "123455";
private static final String date3 = date4 + "123456"; private static final String date3 = date4 + "123456";
......
...@@ -44,7 +44,7 @@ public class UnsignedNumberJniTest { ...@@ -44,7 +44,7 @@ public class UnsignedNumberJniTest {
Assert.assertEquals(127, rs.getByte(2)); Assert.assertEquals(127, rs.getByte(2));
Assert.assertEquals(32767, rs.getShort(3)); Assert.assertEquals(32767, rs.getShort(3));
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807l, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -45,7 +45,7 @@ public class UnsignedNumberRestfulTest { ...@@ -45,7 +45,7 @@ public class UnsignedNumberRestfulTest {
Assert.assertEquals(127, rs.getByte(2)); Assert.assertEquals(127, rs.getByte(2));
Assert.assertEquals(32767, rs.getShort(3)); Assert.assertEquals(32767, rs.getShort(3));
Assert.assertEquals(2147483647, rs.getInt(4)); Assert.assertEquals(2147483647, rs.getInt(4));
Assert.assertEquals(9223372036854775807l, rs.getLong(5)); Assert.assertEquals(9223372036854775807L, rs.getLong(5));
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -95,13 +95,13 @@ public class RestfulResultSetTest { ...@@ -95,13 +95,13 @@ public class RestfulResultSetTest {
public void getBigDecimal() throws SQLException { public void getBigDecimal() throws SQLException {
BigDecimal f1 = rs.getBigDecimal("f1"); BigDecimal f1 = rs.getBigDecimal("f1");
long actual = (f1 == null) ? 0 : f1.longValue(); long actual = (f1 == null) ? 0 : f1.longValue();
Assert.assertEquals(1609430400000l, actual); Assert.assertEquals(1609430400000L, actual);
BigDecimal f2 = rs.getBigDecimal("f2"); BigDecimal f2 = rs.getBigDecimal("f2");
Assert.assertEquals(1, f2.intValue()); Assert.assertEquals(1, f2.intValue());
BigDecimal f3 = rs.getBigDecimal("f3"); BigDecimal f3 = rs.getBigDecimal("f3");
Assert.assertEquals(100l, f3.longValue()); Assert.assertEquals(100L, f3.longValue());
BigDecimal f4 = rs.getBigDecimal("f4"); BigDecimal f4 = rs.getBigDecimal("f4");
Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f); Assert.assertEquals(3.1415f, f4.floatValue(), 0.00000f);
...@@ -125,13 +125,13 @@ public class RestfulResultSetTest { ...@@ -125,13 +125,13 @@ public class RestfulResultSetTest {
Assert.assertEquals(1, Ints.fromByteArray(f2)); Assert.assertEquals(1, Ints.fromByteArray(f2));
byte[] f3 = rs.getBytes("f3"); byte[] f3 = rs.getBytes("f3");
Assert.assertEquals(100l, Longs.fromByteArray(f3)); Assert.assertEquals(100L, Longs.fromByteArray(f3));
byte[] f4 = rs.getBytes("f4"); byte[] f4 = rs.getBytes("f4");
Assert.assertEquals(3.1415f, Float.valueOf(new String(f4)), 0.000000f); Assert.assertEquals(3.1415f, Float.parseFloat(new String(f4)), 0.000000f);
byte[] f5 = rs.getBytes("f5"); byte[] f5 = rs.getBytes("f5");
Assert.assertEquals(3.1415926, Double.valueOf(new String(f5)), 0.000000f); Assert.assertEquals(3.1415926, Double.parseDouble(new String(f5)), 0.000000f);
byte[] f6 = rs.getBytes("f6"); byte[] f6 = rs.getBytes("f6");
Assert.assertEquals("abc", new String(f6)); Assert.assertEquals("abc", new String(f6));
...@@ -222,7 +222,7 @@ public class RestfulResultSetTest { ...@@ -222,7 +222,7 @@ public class RestfulResultSetTest {
Object f3 = rs.getObject("f3"); Object f3 = rs.getObject("f3");
Assert.assertEquals(Long.class, f3.getClass()); Assert.assertEquals(Long.class, f3.getClass());
Assert.assertEquals(100l, f3); Assert.assertEquals(100L, f3);
Object f4 = rs.getObject("f4"); Object f4 = rs.getObject("f4");
Assert.assertEquals(Float.class, f4.getClass()); Assert.assertEquals(Float.class, f4.getClass());
...@@ -434,7 +434,7 @@ public class RestfulResultSetTest { ...@@ -434,7 +434,7 @@ public class RestfulResultSetTest {
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
public void updateLong() throws SQLException { public void updateLong() throws SQLException {
rs.updateLong(1, 1l); rs.updateLong(1, 1L);
} }
@Test(expected = SQLFeatureNotSupportedException.class) @Test(expected = SQLFeatureNotSupportedException.class)
......
...@@ -10,17 +10,17 @@ public class OSUtilsTest { ...@@ -10,17 +10,17 @@ public class OSUtilsTest {
@Test @Test
public void inWindows() { public void inWindows() {
Assert.assertEquals(OS.indexOf("win") >= 0, OSUtils.isWindows()); Assert.assertEquals(OS.contains("win"), OSUtils.isWindows());
} }
@Test @Test
public void isMac() { public void isMac() {
Assert.assertEquals(OS.indexOf("mac") >= 0, OSUtils.isMac()); Assert.assertEquals(OS.contains("mac"), OSUtils.isMac());
} }
@Test @Test
public void isLinux() { public void isLinux() {
Assert.assertEquals(OS.indexOf("nux") >= 0, OSUtils.isLinux()); Assert.assertEquals(OS.contains("nux"), OSUtils.isLinux());
} }
@Before @Before
......
...@@ -21,47 +21,4 @@ public class TimestampUtil { ...@@ -21,47 +21,4 @@ public class TimestampUtil {
SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat); SimpleDateFormat sdf = new SimpleDateFormat(datetimeFormat);
return sdf.format(new Date(time)); return sdf.format(new Date(time));
} }
public static class TimeTuple {
public Long start;
public Long end;
public Long timeGap;
TimeTuple(long start, long end, long timeGap) {
this.start = start;
this.end = end;
this.timeGap = timeGap;
}
}
public static TimeTuple range(long start, long timeGap, long size) {
long now = System.currentTimeMillis();
if (timeGap < 1)
timeGap = 1;
if (start == 0)
start = now - size * timeGap;
// 如果size小于1异常
if (size < 1)
throw new IllegalArgumentException("size less than 1.");
// 如果timeGap为1,已经超长,需要前移start
if (start + size > now) {
start = now - size;
return new TimeTuple(start, now, 1);
}
long end = start + (long) (timeGap * size);
if (end > now) {
//压缩timeGap
end = now;
double gap = (end - start) / (size * 1.0f);
if (gap < 1.0f) {
timeGap = 1;
start = end - size;
} else {
timeGap = (long) gap;
end = start + (long) (timeGap * size);
}
}
return new TimeTuple(start, end, timeGap);
}
} }
...@@ -3,8 +3,6 @@ package com.taosdata.jdbc.utils; ...@@ -3,8 +3,6 @@ package com.taosdata.jdbc.utils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream; import java.util.stream.Stream;
public class UtilsTest { public class UtilsTest {
...@@ -19,14 +17,14 @@ public class UtilsTest { ...@@ -19,14 +17,14 @@ public class UtilsTest {
Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news);
// given // given
s = "\'''''a\\'"; s = "'''''a\\'";
// when // when
news = Utils.escapeSingleQuota(s); news = Utils.escapeSingleQuota(s);
// then // then
Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news); Assert.assertEquals("\\'\\'\\'\\'\\'a\\'", news);
// given // given
s = "\'\'\'\''a\\'"; s = "'''''a\\'";
// when // when
news = Utils.escapeSingleQuota(s); news = Utils.escapeSingleQuota(s);
// then // then
......
...@@ -403,6 +403,20 @@ class CTaosInterface(object): ...@@ -403,6 +403,20 @@ class CTaosInterface(object):
""" """
return CTaosInterface.libtaos.taos_affected_rows(result) return CTaosInterface.libtaos.taos_affected_rows(result)
@staticmethod
def insertLines(connection, lines):
'''
insert through lines protocol
@lines: list of str
@rtype: tsdb error codes
'''
numLines = len(lines)
c_lines_type = ctypes.c_char_p*numLines
c_lines = c_lines_type()
for i in range(numLines):
c_lines[i] = ctypes.c_char_p(lines[i].encode('utf-8'))
return CTaosInterface.libtaos.taos_insert_lines(connection, c_lines, ctypes.c_int(numLines))
@staticmethod @staticmethod
def subscribe(connection, restart, topic, sql, interval): def subscribe(connection, restart, topic, sql, interval):
"""Create a subscription """Create a subscription
......
...@@ -66,6 +66,14 @@ class TDengineConnection(object): ...@@ -66,6 +66,14 @@ class TDengineConnection(object):
self._conn, restart, topic, sql, interval) self._conn, restart, topic, sql, interval)
return TDengineSubscription(sub) return TDengineSubscription(sub)
def insertLines(self, lines):
"""
insert lines through line protocol
"""
if self._conn is None:
return None
return CTaosInterface.insertLines(self._conn, lines)
def cursor(self): def cursor(self):
"""Return a new Cursor object using the connection. """Return a new Cursor object using the connection.
""" """
......
...@@ -151,6 +151,8 @@ static void *dnodeProcessMPeerQueue(void *param) { ...@@ -151,6 +151,8 @@ static void *dnodeProcessMPeerQueue(void *param) {
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("dnodeMPeerQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsMPeerQset, &type, (void **)&pPeerMsg, &unUsed) == 0) { if (taosReadQitemFromQset(tsMPeerQset, &type, (void **)&pPeerMsg, &unUsed) == 0) {
dDebug("qset:%p, mnode peer got no message from qset, exiting", tsMPeerQset); dDebug("qset:%p, mnode peer got no message from qset, exiting", tsMPeerQset);
......
...@@ -155,6 +155,8 @@ static void *dnodeProcessMReadQueue(void *param) { ...@@ -155,6 +155,8 @@ static void *dnodeProcessMReadQueue(void *param) {
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("dnodeMReadQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsMReadQset, &type, (void **)&pRead, &unUsed) == 0) { if (taosReadQitemFromQset(tsMReadQset, &type, (void **)&pRead, &unUsed) == 0) {
dDebug("qset:%p, mnode read got no message from qset, exiting", tsMReadQset); dDebug("qset:%p, mnode read got no message from qset, exiting", tsMReadQset);
......
...@@ -169,6 +169,8 @@ static void *dnodeProcessMWriteQueue(void *param) { ...@@ -169,6 +169,8 @@ static void *dnodeProcessMWriteQueue(void *param) {
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("dnodeMWriteQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsMWriteQset, &type, (void **)&pWrite, &unUsed) == 0) { if (taosReadQitemFromQset(tsMWriteQset, &type, (void **)&pWrite, &unUsed) == 0) {
dDebug("qset:%p, mnode write got no message from qset, exiting", tsMWriteQset); dDebug("qset:%p, mnode write got no message from qset, exiting", tsMWriteQset);
......
...@@ -245,6 +245,8 @@ static void* telemetryThread(void* param) { ...@@ -245,6 +245,8 @@ static void* telemetryThread(void* param) {
clock_gettime(CLOCK_REALTIME, &end); clock_gettime(CLOCK_REALTIME, &end);
end.tv_sec += 300; // wait 5 minutes before send first report end.tv_sec += 300; // wait 5 minutes before send first report
setThreadName("telemetryThrd");
while (!tsExit) { while (!tsExit) {
int r = 0; int r = 0;
struct timespec ts = end; struct timespec ts = end;
......
...@@ -103,6 +103,8 @@ static void *dnodeProcessMgmtQueue(void *wparam) { ...@@ -103,6 +103,8 @@ static void *dnodeProcessMgmtQueue(void *wparam) {
int32_t qtype; int32_t qtype;
void * handle; void * handle;
setThreadName("dnodeMgmtQ");
while (1) { while (1) {
if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pMgmt, &handle) == 0) { if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pMgmt, &handle) == 0) {
dDebug("qdnode mgmt got no message from qset:%p, , exit", pPool->qset); dDebug("qdnode mgmt got no message from qset:%p, , exit", pPool->qset);
......
...@@ -118,6 +118,11 @@ static void *dnodeProcessReadQueue(void *wparam) { ...@@ -118,6 +118,11 @@ static void *dnodeProcessReadQueue(void *wparam) {
SVReadMsg * pRead; SVReadMsg * pRead;
int32_t qtype; int32_t qtype;
void * pVnode; void * pVnode;
char name[16];
memset(name, 0, 16);
snprintf(name, 16, "%s-dnReadQ", pPool->name);
setThreadName(name);
while (1) { while (1) {
if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pRead, &pVnode) == 0) { if (taosReadQitemFromQset(pPool->qset, &qtype, (void **)&pRead, &pVnode) == 0) {
......
...@@ -191,6 +191,8 @@ static void *dnodeProcessVWriteQueue(void *wparam) { ...@@ -191,6 +191,8 @@ static void *dnodeProcessVWriteQueue(void *wparam) {
taosBlockSIGPIPE(); taosBlockSIGPIPE();
dDebug("dnode vwrite worker:%d is running", pWorker->workerId); dDebug("dnode vwrite worker:%d is running", pWorker->workerId);
setThreadName("dnodeWriteQ");
while (1) { while (1) {
numOfMsgs = taosReadAllQitemsFromQset(pWorker->qset, pWorker->qall, &pVnode); numOfMsgs = taosReadAllQitemsFromQset(pWorker->qset, pWorker->qall, &pVnode);
if (numOfMsgs == 0) { if (numOfMsgs == 0) {
......
...@@ -91,6 +91,8 @@ static void *dnodeOpenVnode(void *param) { ...@@ -91,6 +91,8 @@ static void *dnodeOpenVnode(void *param) {
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum); dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
setThreadName("dnodeOpenVnode");
for (int32_t v = 0; v < pThread->vnodeNum; ++v) { for (int32_t v = 0; v < pThread->vnodeNum; ++v) {
int32_t vgId = pThread->vnodeList[v]; int32_t vgId = pThread->vnodeList[v];
snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId, tsOpenVnodes, tsTotalVnodes); snprintf(stepDesc, TSDB_STEP_DESC_LEN, "vgId:%d, start to restore, %d of %d have been opened", vgId, tsOpenVnodes, tsTotalVnodes);
......
...@@ -111,10 +111,12 @@ typedef struct TAOS_MULTI_BIND { ...@@ -111,10 +111,12 @@ typedef struct TAOS_MULTI_BIND {
} TAOS_MULTI_BIND; } TAOS_MULTI_BIND;
DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos);
DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length);
DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags); DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT* stmt, const char* name, TAOS_BIND* tags);
DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name); DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name);
DLL_EXPORT int taos_stmt_set_sub_tbname(TAOS_STMT* stmt, const char* name);
DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert); DLL_EXPORT int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert);
DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums); DLL_EXPORT int taos_stmt_num_params(TAOS_STMT *stmt, int *nums);
int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes); int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes);
......
...@@ -101,6 +101,7 @@ int32_t* taosGetErrno(); ...@@ -101,6 +101,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_TSC_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0218) //"Table does not exist") #define TSDB_CODE_TSC_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0218) //"Table does not exist")
#define TSDB_CODE_TSC_EXCEED_SQL_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0219) //"SQL statement too long check maxSQLLength config") #define TSDB_CODE_TSC_EXCEED_SQL_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0219) //"SQL statement too long check maxSQLLength config")
#define TSDB_CODE_TSC_FILE_EMPTY TAOS_DEF_ERROR_CODE(0, 0x021A) //"File is empty") #define TSDB_CODE_TSC_FILE_EMPTY TAOS_DEF_ERROR_CODE(0, 0x021A) //"File is empty")
#define TSDB_CODE_TSC_LINE_SYNTAX_ERROR TAOS_DEF_ERROR_CODE(0, 0x021B) //"Syntax error in Line")
// mnode // mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed")
......
...@@ -104,6 +104,8 @@ static void shellFreeTbnames() { ...@@ -104,6 +104,8 @@ static void shellFreeTbnames() {
static void *shellCheckThreadFp(void *arg) { static void *shellCheckThreadFp(void *arg) {
ShellThreadObj *pThread = (ShellThreadObj *)arg; ShellThreadObj *pThread = (ShellThreadObj *)arg;
setThreadName("shellCheckThrd");
int32_t interval = tbNum / pThread->totalThreads + 1; int32_t interval = tbNum / pThread->totalThreads + 1;
int32_t start = pThread->threadIndex * interval; int32_t start = pThread->threadIndex * interval;
int32_t end = (pThread->threadIndex + 1) * interval; int32_t end = (pThread->threadIndex + 1) * interval;
......
...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) { ...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) {
TAOS *con = (TAOS *)arg; TAOS *con = (TAOS *)arg;
setThreadName("shellLoopQuery");
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(MAX_COMMAND_SIZE);
......
...@@ -223,6 +223,8 @@ static void shellSourceFile(TAOS *con, char *fptr) { ...@@ -223,6 +223,8 @@ static void shellSourceFile(TAOS *con, char *fptr) {
void* shellImportThreadFp(void *arg) void* shellImportThreadFp(void *arg)
{ {
ShellThreadObj *pThread = (ShellThreadObj*)arg; ShellThreadObj *pThread = (ShellThreadObj*)arg;
setThreadName("shellImportThrd");
for (int f = 0; f < shellSQLFileNum; ++f) { for (int f = 0; f < shellSQLFileNum; ++f) {
if (f % pThread->totalThreads == pThread->threadIndex) { if (f % pThread->totalThreads == pThread->threadIndex) {
char *SQLFileName = shellSQLFiles[f]; char *SQLFileName = shellSQLFiles[f];
......
...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) { ...@@ -336,6 +336,8 @@ void *shellLoopQuery(void *arg) {
TAOS *con = (TAOS *)arg; TAOS *con = (TAOS *)arg;
setThreadName("shellLoopQuery");
pthread_cleanup_push(cleanup_handler, NULL); pthread_cleanup_push(cleanup_handler, NULL);
char *command = malloc(MAX_COMMAND_SIZE); char *command = malloc(MAX_COMMAND_SIZE);
......
...@@ -26,6 +26,8 @@ void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { ...@@ -26,6 +26,8 @@ void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) {
} }
void *cancelHandler(void *arg) { void *cancelHandler(void *arg) {
setThreadName("cancelHandler");
while(1) { while(1) {
if (tsem_wait(&cancelSem) != 0) { if (tsem_wait(&cancelSem) != 0) {
taosMsleep(10); taosMsleep(10);
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
/* /*
when in some thread query return error, thread don't exit, but return, otherwise coredump in other thread. when in some thread query return error, thread don't exit, but return, otherwise coredump in other thread.
*/ */
#include <stdint.h> #include <stdint.h>
#include <taos.h> #include <taos.h>
...@@ -24,24 +24,24 @@ ...@@ -24,24 +24,24 @@
#define CURL_STATICLIB #define CURL_STATICLIB
#ifdef LINUX #ifdef LINUX
#include <argp.h> #include <argp.h>
#include <inttypes.h> #include <inttypes.h>
#ifndef _ALPINE #ifndef _ALPINE
#include <error.h> #include <error.h>
#endif #endif
#include <pthread.h> #include <pthread.h>
#include <semaphore.h> #include <semaphore.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <wordexp.h> #include <wordexp.h>
#include <regex.h> #include <regex.h>
#else #else
#include <regex.h> #include <regex.h>
#include <stdio.h> #include <stdio.h>
#endif #endif
#include <assert.h> #include <assert.h>
...@@ -55,6 +55,11 @@ ...@@ -55,6 +55,11 @@
#define STMT_IFACE_ENABLED 1 #define STMT_IFACE_ENABLED 1
#define NANO_SECOND_ENABLED 1 #define NANO_SECOND_ENABLED 1
#define SET_THREADNAME_ENABLED 1
#if SET_THREADNAME_ENABLED == 0
#define setThreadName(name)
#endif
#define REQ_EXTRA_BUF_LEN 1024 #define REQ_EXTRA_BUF_LEN 1024
#define RESP_BUF_LEN 4096 #define RESP_BUF_LEN 4096
...@@ -71,9 +76,9 @@ extern char configDir[]; ...@@ -71,9 +76,9 @@ extern char configDir[];
#define HEAD_BUFF_LEN TSDB_MAX_COLUMNS*24 // 16*MAX_COLUMNS + (192+32)*2 + insert into .. #define HEAD_BUFF_LEN TSDB_MAX_COLUMNS*24 // 16*MAX_COLUMNS + (192+32)*2 + insert into ..
#define COL_BUFFER_LEN (TSDB_MAX_BYTES_PER_ROW - 50) #define BUFFER_SIZE TSDB_MAX_ALLOWED_SQL_LEN
#define BUFFER_SIZE (50 + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_MAX_BYTES_PER_ROW + TSDB_MAX_TAGS_LEN)
#define COND_BUF_LEN (BUFFER_SIZE - 30) #define COND_BUF_LEN (BUFFER_SIZE - 30)
#define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS)
#define MAX_USERNAME_SIZE 64 #define MAX_USERNAME_SIZE 64
#define MAX_PASSWORD_SIZE 64 #define MAX_PASSWORD_SIZE 64
#define MAX_HOSTNAME_SIZE 64 #define MAX_HOSTNAME_SIZE 64
...@@ -90,7 +95,7 @@ extern char configDir[]; ...@@ -90,7 +95,7 @@ extern char configDir[];
#define MAX_SUPER_TABLE_COUNT 200 #define MAX_SUPER_TABLE_COUNT 200
#define MAX_QUERY_SQL_COUNT 100 #define MAX_QUERY_SQL_COUNT 100
#define MAX_QUERY_SQL_LENGTH 1024 #define MAX_QUERY_SQL_LENGTH BUFFER_SIZE
#define MAX_DATABASE_COUNT 256 #define MAX_DATABASE_COUNT 256
#define INPUT_BUF_LEN 256 #define INPUT_BUF_LEN 256
...@@ -480,7 +485,7 @@ typedef unsigned __int32 uint32_t; ...@@ -480,7 +485,7 @@ typedef unsigned __int32 uint32_t;
#pragma comment ( lib, "ws2_32.lib" ) #pragma comment ( lib, "ws2_32.lib" )
// Some old MinGW/CYGWIN distributions don't define this: // Some old MinGW/CYGWIN distributions don't define this:
#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING #ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004 #define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
#endif // ENABLE_VIRTUAL_TERMINAL_PROCESSING #endif // ENABLE_VIRTUAL_TERMINAL_PROCESSING
static HANDLE g_stdoutHandle; static HANDLE g_stdoutHandle;
...@@ -2367,7 +2372,25 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) { ...@@ -2367,7 +2372,25 @@ static char* getTagValueFromTagSample(SSuperTable* stbInfo, int tagUsePos) {
return dataBuf; return dataBuf;
} }
static char* generateTagVaulesForStb(SSuperTable* stbInfo, int32_t tableSeq) { static char *generateBinaryNCharTagValues(int64_t tableSeq, uint32_t len)
{
char* buf = (char*)calloc(len, 1);
if (NULL == buf) {
printf("calloc failed! size:%d\n", len);
return NULL;
}
if (tableSeq % 2) {
tstrncpy(buf, "beijing", len);
} else {
tstrncpy(buf, "shanghai", len);
}
//rand_string(buf, stbInfo->tags[i].dataLen);
return buf;
}
static char* generateTagValuesForStb(SSuperTable* stbInfo, int64_t tableSeq) {
char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1); char* dataBuf = (char*)calloc(TSDB_MAX_SQL_LEN+1, 1);
if (NULL == dataBuf) { if (NULL == dataBuf) {
printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1); printf("calloc failed! size:%d\n", TSDB_MAX_SQL_LEN+1);
...@@ -2388,70 +2411,62 @@ static char* generateTagVaulesForStb(SSuperTable* stbInfo, int32_t tableSeq) { ...@@ -2388,70 +2411,62 @@ static char* generateTagVaulesForStb(SSuperTable* stbInfo, int32_t tableSeq) {
return NULL; return NULL;
} }
int tagBufLen = stbInfo->tags[i].dataLen + 1; int32_t tagBufLen = stbInfo->tags[i].dataLen + 1;
char* buf = (char*)calloc(tagBufLen, 1); char *buf = generateBinaryNCharTagValues(tableSeq, tagBufLen);
if (NULL == buf) { if (NULL == buf) {
printf("calloc failed! size:%d\n", stbInfo->tags[i].dataLen);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; return NULL;
} }
if (tableSeq % 2) {
tstrncpy(buf, "beijing", tagBufLen);
} else {
tstrncpy(buf, "shanghai", tagBufLen);
}
//rand_string(buf, stbInfo->tags[i].dataLen);
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"\'%s\', ", buf); "\'%s\',", buf);
tmfree(buf); tmfree(buf);
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"int", strlen("int"))) { "int", strlen("int"))) {
if ((g_args.demo_mode) && (i == 0)) { if ((g_args.demo_mode) && (i == 0)) {
dataLen += snprintf(dataBuf + dataLen, dataLen += snprintf(dataBuf + dataLen,
TSDB_MAX_SQL_LEN - dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", tableSeq % 10); "%"PRId64",", tableSeq % 10);
} else { } else {
dataLen += snprintf(dataBuf + dataLen, dataLen += snprintf(dataBuf + dataLen,
TSDB_MAX_SQL_LEN - dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", tableSeq); "%"PRId64",", tableSeq);
} }
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"bigint", strlen("bigint"))) { "bigint", strlen("bigint"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%"PRId64", ", rand_bigint()); "%"PRId64",", rand_bigint());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"float", strlen("float"))) { "float", strlen("float"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%f, ", rand_float()); "%f,", rand_float());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"double", strlen("double"))) { "double", strlen("double"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%f, ", rand_double()); "%f,", rand_double());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"smallint", strlen("smallint"))) { "smallint", strlen("smallint"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_smallint()); "%d,", rand_smallint());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"tinyint", strlen("tinyint"))) { "tinyint", strlen("tinyint"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_tinyint()); "%d,", rand_tinyint());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"bool", strlen("bool"))) { "bool", strlen("bool"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%d, ", rand_bool()); "%d,", rand_bool());
} else if (0 == strncasecmp(stbInfo->tags[i].dataType, } else if (0 == strncasecmp(stbInfo->tags[i].dataType,
"timestamp", strlen("timestamp"))) { "timestamp", strlen("timestamp"))) {
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen,
"%"PRId64", ", rand_bigint()); "%"PRId64",", rand_bigint());
} else { } else {
printf("No support data type: %s\n", stbInfo->tags[i].dataType); errorPrint("No support data type: %s\n", stbInfo->tags[i].dataType);
tmfree(dataBuf); tmfree(dataBuf);
return NULL; return NULL;
} }
} }
dataLen -= 2; dataLen -= 1;
dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, ")"); dataLen += snprintf(dataBuf + dataLen, TSDB_MAX_SQL_LEN - dataLen, ")");
return dataBuf; return dataBuf;
} }
...@@ -2682,7 +2697,7 @@ static int getSuperTableFromServer(TAOS * taos, char* dbName, ...@@ -2682,7 +2697,7 @@ static int getSuperTableFromServer(TAOS * taos, char* dbName,
calcRowLen(superTbls); calcRowLen(superTbls);
/* /*
if (TBL_ALREADY_EXISTS == superTbls->childTblExists) { if (TBL_ALREADY_EXISTS == superTbls->childTblExists) {
//get all child table name use cmd: select tbname from superTblName; //get all child table name use cmd: select tbname from superTblName;
int childTblCount = 10000; int childTblCount = 10000;
...@@ -2723,12 +2738,12 @@ static int createSuperTable( ...@@ -2723,12 +2738,12 @@ static int createSuperTable(
if (strcasecmp(dataType, "BINARY") == 0) { if (strcasecmp(dataType, "BINARY") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, len += snprintf(cols + len, COL_BUFFER_LEN - len,
", C%d %s(%d)", colIndex, "BINARY", ",C%d %s(%d)", colIndex, "BINARY",
superTbl->columns[colIndex].dataLen); superTbl->columns[colIndex].dataLen);
lenOfOneRow += superTbl->columns[colIndex].dataLen + 3; lenOfOneRow += superTbl->columns[colIndex].dataLen + 3;
} else if (strcasecmp(dataType, "NCHAR") == 0) { } else if (strcasecmp(dataType, "NCHAR") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, len += snprintf(cols + len, COL_BUFFER_LEN - len,
", C%d %s(%d)", colIndex, "NCHAR", ",C%d %s(%d)", colIndex, "NCHAR",
superTbl->columns[colIndex].dataLen); superTbl->columns[colIndex].dataLen);
lenOfOneRow += superTbl->columns[colIndex].dataLen + 3; lenOfOneRow += superTbl->columns[colIndex].dataLen + 3;
} else if (strcasecmp(dataType, "INT") == 0) { } else if (strcasecmp(dataType, "INT") == 0) {
...@@ -2736,22 +2751,22 @@ static int createSuperTable( ...@@ -2736,22 +2751,22 @@ static int createSuperTable(
len += snprintf(cols + len, COL_BUFFER_LEN - len, len += snprintf(cols + len, COL_BUFFER_LEN - len,
", VOLTAGE INT"); ", VOLTAGE INT");
} else { } else {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", colIndex, "INT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "INT");
} }
lenOfOneRow += 11; lenOfOneRow += 11;
} else if (strcasecmp(dataType, "BIGINT") == 0) { } else if (strcasecmp(dataType, "BIGINT") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s",
colIndex, "BIGINT"); colIndex, "BIGINT");
lenOfOneRow += 21; lenOfOneRow += 21;
} else if (strcasecmp(dataType, "SMALLINT") == 0) { } else if (strcasecmp(dataType, "SMALLINT") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s",
colIndex, "SMALLINT"); colIndex, "SMALLINT");
lenOfOneRow += 6; lenOfOneRow += 6;
} else if (strcasecmp(dataType, "TINYINT") == 0) { } else if (strcasecmp(dataType, "TINYINT") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", colIndex, "TINYINT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "TINYINT");
lenOfOneRow += 4; lenOfOneRow += 4;
} else if (strcasecmp(dataType, "BOOL") == 0) { } else if (strcasecmp(dataType, "BOOL") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", colIndex, "BOOL"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "BOOL");
lenOfOneRow += 6; lenOfOneRow += 6;
} else if (strcasecmp(dataType, "FLOAT") == 0) { } else if (strcasecmp(dataType, "FLOAT") == 0) {
if (g_args.demo_mode) { if (g_args.demo_mode) {
...@@ -2761,16 +2776,16 @@ static int createSuperTable( ...@@ -2761,16 +2776,16 @@ static int createSuperTable(
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", PHASE FLOAT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ", PHASE FLOAT");
} }
} else { } else {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", colIndex, "FLOAT"); len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s", colIndex, "FLOAT");
} }
lenOfOneRow += 22; lenOfOneRow += 22;
} else if (strcasecmp(dataType, "DOUBLE") == 0) { } else if (strcasecmp(dataType, "DOUBLE") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s",
colIndex, "DOUBLE"); colIndex, "DOUBLE");
lenOfOneRow += 42; lenOfOneRow += 42;
} else if (strcasecmp(dataType, "TIMESTAMP") == 0) { } else if (strcasecmp(dataType, "TIMESTAMP") == 0) {
len += snprintf(cols + len, COL_BUFFER_LEN - len, ", C%d %s", len += snprintf(cols + len, COL_BUFFER_LEN - len, ",C%d %s",
colIndex, "TIMESTAMP"); colIndex, "TIMESTAMP");
lenOfOneRow += 21; lenOfOneRow += 21;
} else { } else {
...@@ -2814,17 +2829,17 @@ static int createSuperTable( ...@@ -2814,17 +2829,17 @@ static int createSuperTable(
if (strcasecmp(dataType, "BINARY") == 0) { if (strcasecmp(dataType, "BINARY") == 0) {
if ((g_args.demo_mode) && (tagIndex == 1)) { if ((g_args.demo_mode) && (tagIndex == 1)) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"location BINARY(%d), ", "location BINARY(%d),",
superTbl->tags[tagIndex].dataLen); superTbl->tags[tagIndex].dataLen);
} else { } else {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s(%d), ", tagIndex, "BINARY", "T%d %s(%d),", tagIndex, "BINARY",
superTbl->tags[tagIndex].dataLen); superTbl->tags[tagIndex].dataLen);
} }
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3;
} else if (strcasecmp(dataType, "NCHAR") == 0) { } else if (strcasecmp(dataType, "NCHAR") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s(%d), ", tagIndex, "T%d %s(%d),", tagIndex,
"NCHAR", superTbl->tags[tagIndex].dataLen); "NCHAR", superTbl->tags[tagIndex].dataLen);
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 3;
} else if (strcasecmp(dataType, "INT") == 0) { } else if (strcasecmp(dataType, "INT") == 0) {
...@@ -2833,32 +2848,32 @@ static int createSuperTable( ...@@ -2833,32 +2848,32 @@ static int createSuperTable(
"groupId INT, "); "groupId INT, ");
} else { } else {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "INT"); "T%d %s,", tagIndex, "INT");
} }
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 11; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 11;
} else if (strcasecmp(dataType, "BIGINT") == 0) { } else if (strcasecmp(dataType, "BIGINT") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "BIGINT"); "T%d %s,", tagIndex, "BIGINT");
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 21; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 21;
} else if (strcasecmp(dataType, "SMALLINT") == 0) { } else if (strcasecmp(dataType, "SMALLINT") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "SMALLINT"); "T%d %s,", tagIndex, "SMALLINT");
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 6; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 6;
} else if (strcasecmp(dataType, "TINYINT") == 0) { } else if (strcasecmp(dataType, "TINYINT") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "TINYINT"); "T%d %s,", tagIndex, "TINYINT");
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 4; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 4;
} else if (strcasecmp(dataType, "BOOL") == 0) { } else if (strcasecmp(dataType, "BOOL") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "BOOL"); "T%d %s,", tagIndex, "BOOL");
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 6; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 6;
} else if (strcasecmp(dataType, "FLOAT") == 0) { } else if (strcasecmp(dataType, "FLOAT") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "FLOAT"); "T%d %s,", tagIndex, "FLOAT");
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 22; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 22;
} else if (strcasecmp(dataType, "DOUBLE") == 0) { } else if (strcasecmp(dataType, "DOUBLE") == 0) {
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len,
"t%d %s, ", tagIndex, "DOUBLE"); "T%d %s,", tagIndex, "DOUBLE");
lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 42; lenOfTagOfOneRow += superTbl->tags[tagIndex].dataLen + 42;
} else { } else {
taos_close(taos); taos_close(taos);
...@@ -2868,7 +2883,7 @@ static int createSuperTable( ...@@ -2868,7 +2883,7 @@ static int createSuperTable(
} }
} }
len -= 2; len -= 1;
len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, ")"); len += snprintf(tags + len, TSDB_MAX_TAGS_LEN - len, ")");
superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow; superTbl->lenOfTagOfOneRow = lenOfTagOfOneRow;
...@@ -3025,10 +3040,11 @@ static void* createTable(void *sarg) ...@@ -3025,10 +3040,11 @@ static void* createTable(void *sarg)
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
SSuperTable* superTblInfo = pThreadInfo->superTblInfo; SSuperTable* superTblInfo = pThreadInfo->superTblInfo;
setThreadName("createTable");
uint64_t lastPrintTime = taosGetTimestampMs(); uint64_t lastPrintTime = taosGetTimestampMs();
int buff_len; int buff_len = BUFFER_SIZE;
buff_len = BUFFER_SIZE;
pThreadInfo->buffer = calloc(buff_len, 1); pThreadInfo->buffer = calloc(buff_len, 1);
if (pThreadInfo->buffer == NULL) { if (pThreadInfo->buffer == NULL) {
...@@ -3066,7 +3082,7 @@ static void* createTable(void *sarg) ...@@ -3066,7 +3082,7 @@ static void* createTable(void *sarg)
} }
char* tagsValBuf = NULL; char* tagsValBuf = NULL;
if (0 == superTblInfo->tagSource) { if (0 == superTblInfo->tagSource) {
tagsValBuf = generateTagVaulesForStb(superTblInfo, i); tagsValBuf = generateTagValuesForStb(superTblInfo, i);
} else { } else {
tagsValBuf = getTagValueFromTagSample( tagsValBuf = getTagValueFromTagSample(
superTblInfo, superTblInfo,
...@@ -3254,7 +3270,7 @@ static void createChildTables() { ...@@ -3254,7 +3270,7 @@ static void createChildTables() {
/* /*
Read 10000 lines at most. If more than 10000 lines, continue to read after using Read 10000 lines at most. If more than 10000 lines, continue to read after using
*/ */
static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) { static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) {
size_t n = 0; size_t n = 0;
ssize_t readLen = 0; ssize_t readLen = 0;
...@@ -3322,7 +3338,7 @@ static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) { ...@@ -3322,7 +3338,7 @@ static int readTagFromCsvFileToMem(SSuperTable * superTblInfo) {
/* /*
Read 10000 lines at most. If more than 10000 lines, continue to read after using Read 10000 lines at most. If more than 10000 lines, continue to read after using
*/ */
static int readSampleFromCsvFileToMem( static int readSampleFromCsvFileToMem(
SSuperTable* superTblInfo) { SSuperTable* superTblInfo) {
size_t n = 0; size_t n = 0;
...@@ -5102,7 +5118,8 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k) ...@@ -5102,7 +5118,8 @@ static int32_t execInsert(threadInfo *pThreadInfo, uint32_t k)
#if STMT_IFACE_ENABLED == 1 #if STMT_IFACE_ENABLED == 1
case STMT_IFACE: case STMT_IFACE:
debugPrint("%s() LN%d, stmt=%p", __func__, __LINE__, pThreadInfo->stmt); debugPrint("%s() LN%d, stmt=%p",
__func__, __LINE__, pThreadInfo->stmt);
if (0 != taos_stmt_execute(pThreadInfo->stmt)) { if (0 != taos_stmt_execute(pThreadInfo->stmt)) {
errorPrint("%s() LN%d, failied to execute insert statement\n", errorPrint("%s() LN%d, failied to execute insert statement\n",
__func__, __LINE__); __func__, __LINE__);
...@@ -5318,7 +5335,7 @@ static int generateSQLHeadWithoutStb(char *tableName, ...@@ -5318,7 +5335,7 @@ static int generateSQLHeadWithoutStb(char *tableName,
static int generateStbSQLHead( static int generateStbSQLHead(
SSuperTable* superTblInfo, SSuperTable* superTblInfo,
char *tableName, int32_t tableSeq, char *tableName, int64_t tableSeq,
char *dbName, char *dbName,
char *buffer, int remainderBufLen) char *buffer, int remainderBufLen)
{ {
...@@ -5329,7 +5346,7 @@ static int generateStbSQLHead( ...@@ -5329,7 +5346,7 @@ static int generateStbSQLHead(
if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) { if (AUTO_CREATE_SUBTBL == superTblInfo->autoCreateTable) {
char* tagsValBuf = NULL; char* tagsValBuf = NULL;
if (0 == superTblInfo->tagSource) { if (0 == superTblInfo->tagSource) {
tagsValBuf = generateTagVaulesForStb(superTblInfo, tableSeq); tagsValBuf = generateTagValuesForStb(superTblInfo, tableSeq);
} else { } else {
tagsValBuf = getTagValueFromTagSample( tagsValBuf = getTagValueFromTagSample(
superTblInfo, superTblInfo,
...@@ -5344,7 +5361,7 @@ static int generateStbSQLHead( ...@@ -5344,7 +5361,7 @@ static int generateStbSQLHead(
len = snprintf( len = snprintf(
headBuf, headBuf,
HEAD_BUFF_LEN, HEAD_BUFF_LEN,
"%s.%s using %s.%s tags %s values", "%s.%s using %s.%s TAGS%s values",
dbName, dbName,
tableName, tableName,
dbName, dbName,
...@@ -5650,8 +5667,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind, ...@@ -5650,8 +5667,7 @@ static int32_t prepareStmtBindArrayByType(TAOS_BIND *bind,
*ptr += bind->buffer_length; *ptr += bind->buffer_length;
} else { } else {
errorPrint( "No support data type: %s\n", errorPrint( "No support data type: %s\n", dataType);
dataType);
return -1; return -1;
} }
...@@ -5737,64 +5753,42 @@ static int32_t prepareStmtWithoutStb( ...@@ -5737,64 +5753,42 @@ static int32_t prepareStmtWithoutStb(
return k; return k;
} }
static int32_t prepareStbStmt( static int32_t prepareStbStmtBind(
SSuperTable *stbInfo, char *bindArray, SSuperTable *stbInfo, bool sourceRand,
TAOS_STMT *stmt, int64_t startTime, int32_t recSeq,
char *tableName, uint32_t batch, bool isColumn)
uint64_t insertRows,
uint64_t recordFrom,
int64_t startTime,
int64_t *pSamplePos)
{ {
int ret = taos_stmt_set_tbname(stmt, tableName); char *bindBuffer = calloc(1, g_args.len_of_binary);
if (ret != 0) {
errorPrint("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n",
tableName, ret, taos_errstr(NULL));
return ret;
}
char *bindArray = malloc(sizeof(TAOS_BIND) * (stbInfo->columnCount + 1));
if (bindArray == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind params\n",
__func__, __LINE__, (stbInfo->columnCount + 1));
return -1;
}
bool sourceRand;
if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) {
sourceRand = true;
} else {
sourceRand = false; // from sample data file
}
char *bindBuffer = malloc(g_args.len_of_binary);
if (bindBuffer == NULL) { if (bindBuffer == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n", errorPrint("%s() LN%d, Failed to allocate %d bind buffer\n",
__func__, __LINE__, g_args.len_of_binary); __func__, __LINE__, g_args.len_of_binary);
free(bindArray);
return -1; return -1;
} }
uint32_t k;
for (k = 0; k < batch;) {
/* columnCount + 1 (ts) */
char data[MAX_DATA_SIZE]; char data[MAX_DATA_SIZE];
memset(data, 0, MAX_DATA_SIZE); memset(data, 0, MAX_DATA_SIZE);
char *ptr = data; char *ptr = data;
TAOS_BIND *bind = (TAOS_BIND *)(bindArray + 0);
TAOS_BIND *bind;
if (isColumn) {
int cursor = 0;
for (int i = 0; i < stbInfo->columnCount + 1; i ++) {
bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * i));
if (i == 0) {
int64_t *bind_ts; int64_t *bind_ts;
bind_ts = (int64_t *)ptr; bind_ts = (int64_t *)ptr;
bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP; bind->buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
if (stbInfo->disorderRatio) { if (stbInfo->disorderRatio) {
*bind_ts = startTime + getTSRandTail( *bind_ts = startTime + getTSRandTail(
stbInfo->timeStampStep, k, stbInfo->timeStampStep, recSeq,
stbInfo->disorderRatio, stbInfo->disorderRatio,
stbInfo->disorderRange); stbInfo->disorderRange);
} else { } else {
*bind_ts = startTime + stbInfo->timeStampStep * k; *bind_ts = startTime + stbInfo->timeStampStep * recSeq;
} }
bind->buffer_length = sizeof(int64_t); bind->buffer_length = sizeof(int64_t);
bind->buffer = bind_ts; bind->buffer = bind_ts;
...@@ -5802,19 +5796,15 @@ static int32_t prepareStbStmt( ...@@ -5802,19 +5796,15 @@ static int32_t prepareStbStmt(
bind->is_null = NULL; bind->is_null = NULL;
ptr += bind->buffer_length; ptr += bind->buffer_length;
} else {
int cursor = 0;
for (int i = 0; i < stbInfo->columnCount; i ++) {
bind = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * (i + 1)));
if (sourceRand) { if (sourceRand) {
if ( -1 == prepareStmtBindArrayByType( if ( -1 == prepareStmtBindArrayByType(
bind, bind,
stbInfo->columns[i].dataType, stbInfo->columns[i-1].dataType,
stbInfo->columns[i].dataLen, stbInfo->columns[i-1].dataLen,
&ptr, &ptr,
NULL)) { NULL)) {
free(bindArray);
free(bindBuffer); free(bindBuffer);
return -1; return -1;
} }
...@@ -5835,16 +5825,121 @@ static int32_t prepareStbStmt( ...@@ -5835,16 +5825,121 @@ static int32_t prepareStbStmt(
if ( -1 == prepareStmtBindArrayByType( if ( -1 == prepareStmtBindArrayByType(
bind, bind,
stbInfo->columns[i].dataType, stbInfo->columns[i-1].dataType,
stbInfo->columns[i].dataLen, stbInfo->columns[i-1].dataLen,
&ptr, &ptr,
bindBuffer)) { bindBuffer)) {
free(bindArray);
free(bindBuffer); free(bindBuffer);
return -1; return -1;
} }
} }
} }
}
} else {
TAOS_BIND *tag;
for (int t = 0; t < stbInfo->tagCount; t ++) {
tag = (TAOS_BIND *)((char *)bindArray + (sizeof(TAOS_BIND) * t));
if ( -1 == prepareStmtBindArrayByType(
tag,
stbInfo->tags[t].dataType,
stbInfo->tags[t].dataLen,
&ptr,
NULL)) {
free(bindBuffer);
return -1;
}
}
}
free(bindBuffer);
return 0;
}
static int32_t prepareStbStmt(
SSuperTable *stbInfo,
TAOS_STMT *stmt,
char *tableName,
int64_t tableSeq,
uint32_t batch,
uint64_t insertRows,
uint64_t recordFrom,
int64_t startTime,
int64_t *pSamplePos)
{
int ret;
bool sourceRand;
if (0 == strncasecmp(stbInfo->dataSource, "rand", strlen("rand"))) {
sourceRand = true;
} else {
sourceRand = false; // from sample data file
}
if (AUTO_CREATE_SUBTBL == stbInfo->autoCreateTable) {
char* tagsValBuf = NULL;
bool tagRand;
if (0 == stbInfo->tagSource) {
tagRand = true;
tagsValBuf = generateTagValuesForStb(stbInfo, tableSeq);
} else {
tagRand = false;
tagsValBuf = getTagValueFromTagSample(
stbInfo,
tableSeq % stbInfo->tagSampleCount);
}
if (NULL == tagsValBuf) {
errorPrint("%s() LN%d, tag buf failed to allocate memory\n",
__func__, __LINE__);
return -1;
}
char *tagsArray = calloc(1, sizeof(TAOS_BIND) * stbInfo->tagCount);
if (NULL == tagsArray) {
tmfree(tagsValBuf);
errorPrint("%s() LN%d, tag buf failed to allocate memory\n",
__func__, __LINE__);
return -1;
}
if (-1 == prepareStbStmtBind(
tagsArray, stbInfo, tagRand, -1, -1, false /* is tag */)) {
free(tagsArray);
return -1;
}
ret = taos_stmt_set_tbname_tags(stmt, tableName, (TAOS_BIND *)tagsArray);
tmfree(tagsValBuf);
tmfree((char *)tagsArray);
} else {
ret = taos_stmt_set_tbname(stmt, tableName);
}
if (ret != 0) {
errorPrint("failed to execute taos_stmt_set_tbname(%s). return 0x%x. reason: %s\n",
tableName, ret, taos_errstr(NULL));
return ret;
}
char *bindArray = calloc(1, sizeof(TAOS_BIND) * (stbInfo->columnCount + 1));
if (bindArray == NULL) {
errorPrint("%s() LN%d, Failed to allocate %d bind params\n",
__func__, __LINE__, (stbInfo->columnCount + 1));
return -1;
}
uint32_t k;
for (k = 0; k < batch;) {
/* columnCount + 1 (ts) */
if (-1 == prepareStbStmtBind(bindArray, stbInfo, sourceRand,
startTime, k, true /* is column */)) {
free(bindArray);
return -1;
}
taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray); taos_stmt_bind_param(stmt, (TAOS_BIND *)bindArray);
// if msg > 3MB, break // if msg > 3MB, break
taos_stmt_add_batch(stmt); taos_stmt_add_batch(stmt);
...@@ -5861,7 +5956,6 @@ static int32_t prepareStbStmt( ...@@ -5861,7 +5956,6 @@ static int32_t prepareStbStmt(
} }
} }
free(bindBuffer);
free(bindArray); free(bindArray);
return k; return k;
} }
...@@ -5869,7 +5963,9 @@ static int32_t prepareStbStmt( ...@@ -5869,7 +5963,9 @@ static int32_t prepareStbStmt(
static int32_t prepareStbStmtInterlace( static int32_t prepareStbStmtInterlace(
SSuperTable *stbInfo, SSuperTable *stbInfo,
TAOS_STMT *stmt, TAOS_STMT *stmt,
char *tableName, uint32_t batch, char *tableName,
int64_t tableSeq,
uint32_t batch,
uint64_t insertRows, uint64_t insertRows,
uint64_t recordFrom, uint64_t recordFrom,
int64_t startTime, int64_t startTime,
...@@ -5879,6 +5975,7 @@ static int32_t prepareStbStmtInterlace( ...@@ -5879,6 +5975,7 @@ static int32_t prepareStbStmtInterlace(
stbInfo, stbInfo,
stmt, stmt,
tableName, tableName,
tableSeq,
batch, batch,
insertRows, 0, startTime, insertRows, 0, startTime,
pSamplePos); pSamplePos);
...@@ -5887,7 +5984,9 @@ static int32_t prepareStbStmtInterlace( ...@@ -5887,7 +5984,9 @@ static int32_t prepareStbStmtInterlace(
static int32_t prepareStbStmtProgressive( static int32_t prepareStbStmtProgressive(
SSuperTable *stbInfo, SSuperTable *stbInfo,
TAOS_STMT *stmt, TAOS_STMT *stmt,
char *tableName, uint32_t batch, char *tableName,
int64_t tableSeq,
uint32_t batch,
uint64_t insertRows, uint64_t insertRows,
uint64_t recordFrom, uint64_t recordFrom,
int64_t startTime, int64_t startTime,
...@@ -5897,6 +5996,7 @@ static int32_t prepareStbStmtProgressive( ...@@ -5897,6 +5996,7 @@ static int32_t prepareStbStmtProgressive(
stbInfo, stbInfo,
stmt, stmt,
tableName, tableName,
tableSeq,
g_args.num_of_RPR, g_args.num_of_RPR,
insertRows, recordFrom, startTime, insertRows, recordFrom, startTime,
pSamplePos); pSamplePos);
...@@ -6097,6 +6197,7 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { ...@@ -6097,6 +6197,7 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) {
superTblInfo, superTblInfo,
pThreadInfo->stmt, pThreadInfo->stmt,
tableName, tableName,
tableSeq,
batchPerTbl, batchPerTbl,
insertRows, i, insertRows, i,
startTime, startTime,
...@@ -6326,6 +6427,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { ...@@ -6326,6 +6427,7 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) {
superTblInfo, superTblInfo,
pThreadInfo->stmt, pThreadInfo->stmt,
tableName, tableName,
tableSeq,
g_args.num_of_RPR, g_args.num_of_RPR,
insertRows, i, start_time, insertRows, i, start_time,
&(pThreadInfo->samplePos)); &(pThreadInfo->samplePos));
...@@ -6428,6 +6530,8 @@ static void* syncWrite(void *sarg) { ...@@ -6428,6 +6530,8 @@ static void* syncWrite(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
SSuperTable* superTblInfo = pThreadInfo->superTblInfo; SSuperTable* superTblInfo = pThreadInfo->superTblInfo;
setThreadName("syncWrite");
uint32_t interlaceRows; uint32_t interlaceRows;
if (superTblInfo) { if (superTblInfo) {
...@@ -6469,7 +6573,7 @@ static void callBack(void *param, TAOS_RES *res, int code) { ...@@ -6469,7 +6573,7 @@ static void callBack(void *param, TAOS_RES *res, int code) {
pstr += sprintf(pstr, "insert into %s.%s%"PRId64" values", pstr += sprintf(pstr, "insert into %s.%s%"PRId64" values",
pThreadInfo->db_name, pThreadInfo->tb_prefix, pThreadInfo->db_name, pThreadInfo->tb_prefix,
pThreadInfo->start_table_from); pThreadInfo->start_table_from);
// if (pThreadInfo->counter >= pThreadInfo->superTblInfo->insertRows) { // if (pThreadInfo->counter >= pThreadInfo->superTblInfo->insertRows) {
if (pThreadInfo->counter >= g_args.num_of_RPR) { if (pThreadInfo->counter >= g_args.num_of_RPR) {
pThreadInfo->start_table_from++; pThreadInfo->start_table_from++;
pThreadInfo->counter = 0; pThreadInfo->counter = 0;
...@@ -6513,6 +6617,8 @@ static void *asyncWrite(void *sarg) { ...@@ -6513,6 +6617,8 @@ static void *asyncWrite(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
SSuperTable* superTblInfo = pThreadInfo->superTblInfo; SSuperTable* superTblInfo = pThreadInfo->superTblInfo;
setThreadName("asyncWrite");
pThreadInfo->st = 0; pThreadInfo->st = 0;
pThreadInfo->et = 0; pThreadInfo->et = 0;
pThreadInfo->lastTs = pThreadInfo->start_time; pThreadInfo->lastTs = pThreadInfo->start_time;
...@@ -6590,6 +6696,8 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -6590,6 +6696,8 @@ static void startMultiThreadInsertData(int threads, char* db_name,
} else { } else {
start_time = 1500000000000; start_time = 1500000000000;
} }
debugPrint("%s() LN%d, start_time= %"PRId64"\n",
__func__, __LINE__, start_time);
int64_t start = taosGetTimestampMs(); int64_t start = taosGetTimestampMs();
...@@ -6619,14 +6727,17 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -6619,14 +6727,17 @@ static void startMultiThreadInsertData(int threads, char* db_name,
int64_t limit; int64_t limit;
uint64_t offset; uint64_t offset;
if ((NULL != g_args.sqlFile) && (superTblInfo->childTblExists == TBL_NO_EXISTS) && if ((NULL != g_args.sqlFile)
((superTblInfo->childTblOffset != 0) || (superTblInfo->childTblLimit >= 0))) { && (superTblInfo->childTblExists == TBL_NO_EXISTS)
&& ((superTblInfo->childTblOffset != 0)
|| (superTblInfo->childTblLimit >= 0))) {
printf("WARNING: offset and limit will not be used since the child tables not exists!\n"); printf("WARNING: offset and limit will not be used since the child tables not exists!\n");
} }
if (superTblInfo->childTblExists == TBL_ALREADY_EXISTS) { if (superTblInfo->childTblExists == TBL_ALREADY_EXISTS) {
if ((superTblInfo->childTblLimit < 0) if ((superTblInfo->childTblLimit < 0)
|| ((superTblInfo->childTblOffset + superTblInfo->childTblLimit) || ((superTblInfo->childTblOffset
+ superTblInfo->childTblLimit)
> (superTblInfo->childTblCount))) { > (superTblInfo->childTblCount))) {
superTblInfo->childTblLimit = superTblInfo->childTblLimit =
superTblInfo->childTblCount - superTblInfo->childTblOffset; superTblInfo->childTblCount - superTblInfo->childTblOffset;
...@@ -6732,7 +6843,8 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -6732,7 +6843,8 @@ static void startMultiThreadInsertData(int threads, char* db_name,
#if STMT_IFACE_ENABLED == 1 #if STMT_IFACE_ENABLED == 1
if ((g_args.iface == STMT_IFACE) if ((g_args.iface == STMT_IFACE)
|| ((superTblInfo) && (superTblInfo->iface == STMT_IFACE))) { || ((superTblInfo)
&& (superTblInfo->iface == STMT_IFACE))) {
int columnCount; int columnCount;
if (superTblInfo) { if (superTblInfo) {
...@@ -6752,7 +6864,7 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -6752,7 +6864,7 @@ static void startMultiThreadInsertData(int threads, char* db_name,
exit(-1); exit(-1);
} }
char buffer[3000]; char buffer[BUFFER_SIZE];
char *pstr = buffer; char *pstr = buffer;
if ((superTblInfo) if ((superTblInfo)
...@@ -6760,7 +6872,8 @@ static void startMultiThreadInsertData(int threads, char* db_name, ...@@ -6760,7 +6872,8 @@ static void startMultiThreadInsertData(int threads, char* db_name,
== superTblInfo->autoCreateTable)) { == superTblInfo->autoCreateTable)) {
pstr += sprintf(pstr, "INSERT INTO ? USING %s TAGS(?", pstr += sprintf(pstr, "INSERT INTO ? USING %s TAGS(?",
superTblInfo->sTblName); superTblInfo->sTblName);
for (int tag = 0; tag < (superTblInfo->tagCount - 1); tag ++ ) { for (int tag = 0; tag < (superTblInfo->tagCount - 1);
tag ++ ) {
pstr += sprintf(pstr, ",?"); pstr += sprintf(pstr, ",?");
} }
pstr += sprintf(pstr, ") VALUES(?"); pstr += sprintf(pstr, ") VALUES(?");
...@@ -6911,6 +7024,7 @@ static void *readTable(void *sarg) { ...@@ -6911,6 +7024,7 @@ static void *readTable(void *sarg) {
#if 1 #if 1
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
TAOS *taos = pThreadInfo->taos; TAOS *taos = pThreadInfo->taos;
setThreadName("readTable");
char command[BUFFER_SIZE] = "\0"; char command[BUFFER_SIZE] = "\0";
uint64_t sTime = pThreadInfo->start_time; uint64_t sTime = pThreadInfo->start_time;
char *tb_prefix = pThreadInfo->tb_prefix; char *tb_prefix = pThreadInfo->tb_prefix;
...@@ -6921,12 +7035,12 @@ static void *readTable(void *sarg) { ...@@ -6921,12 +7035,12 @@ static void *readTable(void *sarg) {
} }
int64_t num_of_DPT; int64_t num_of_DPT;
/* if (pThreadInfo->superTblInfo) { /* if (pThreadInfo->superTblInfo) {
num_of_DPT = pThreadInfo->superTblInfo->insertRows; // nrecords_per_table; num_of_DPT = pThreadInfo->superTblInfo->insertRows; // nrecords_per_table;
} else { } else {
*/ */
num_of_DPT = g_args.num_of_DPT; num_of_DPT = g_args.num_of_DPT;
// } // }
int64_t num_of_tables = pThreadInfo->ntables; // rinfo->end_table_to - rinfo->start_table_from + 1; int64_t num_of_tables = pThreadInfo->ntables; // rinfo->end_table_to - rinfo->start_table_from + 1;
int64_t totalData = num_of_DPT * num_of_tables; int64_t totalData = num_of_DPT * num_of_tables;
...@@ -6983,6 +7097,7 @@ static void *readMetric(void *sarg) { ...@@ -6983,6 +7097,7 @@ static void *readMetric(void *sarg) {
#if 1 #if 1
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
TAOS *taos = pThreadInfo->taos; TAOS *taos = pThreadInfo->taos;
setThreadName("readMetric");
char command[BUFFER_SIZE] = "\0"; char command[BUFFER_SIZE] = "\0";
FILE *fp = fopen(pThreadInfo->filePath, "a"); FILE *fp = fopen(pThreadInfo->filePath, "a");
if (NULL == fp) { if (NULL == fp) {
...@@ -7159,6 +7274,8 @@ static int insertTestProcess() { ...@@ -7159,6 +7274,8 @@ static int insertTestProcess() {
static void *specifiedTableQuery(void *sarg) { static void *specifiedTableQuery(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
setThreadName("specTableQuery");
if (pThreadInfo->taos == NULL) { if (pThreadInfo->taos == NULL) {
TAOS * taos = NULL; TAOS * taos = NULL;
taos = taos_connect(g_queryInfo.host, taos = taos_connect(g_queryInfo.host,
...@@ -7258,6 +7375,8 @@ static void *superTableQuery(void *sarg) { ...@@ -7258,6 +7375,8 @@ static void *superTableQuery(void *sarg) {
char sqlstr[MAX_QUERY_SQL_LENGTH]; char sqlstr[MAX_QUERY_SQL_LENGTH];
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
setThreadName("superTableQuery");
if (pThreadInfo->taos == NULL) { if (pThreadInfo->taos == NULL) {
TAOS * taos = NULL; TAOS * taos = NULL;
taos = taos_connect(g_queryInfo.host, taos = taos_connect(g_queryInfo.host,
...@@ -7480,7 +7599,7 @@ static int queryTestProcess() { ...@@ -7480,7 +7599,7 @@ static int queryTestProcess() {
tmfree((char*)pidsOfSub); tmfree((char*)pidsOfSub);
tmfree((char*)infosOfSub); tmfree((char*)infosOfSub);
// taos_close(taos);// TODO: workaround to use separate taos connection; // taos_close(taos);// TODO: workaround to use separate taos connection;
uint64_t endTs = taosGetTimestampMs(); uint64_t endTs = taosGetTimestampMs();
uint64_t totalQueried = g_queryInfo.specifiedQueryInfo.totalQueried + uint64_t totalQueried = g_queryInfo.specifiedQueryInfo.totalQueried +
...@@ -7560,6 +7679,8 @@ static void *superSubscribe(void *sarg) { ...@@ -7560,6 +7679,8 @@ static void *superSubscribe(void *sarg) {
TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT] = {0}; TAOS_SUB* tsub[MAX_QUERY_SQL_COUNT] = {0};
uint64_t tsubSeq; uint64_t tsubSeq;
setThreadName("superSub");
if (pThreadInfo->ntables > MAX_QUERY_SQL_COUNT) { if (pThreadInfo->ntables > MAX_QUERY_SQL_COUNT) {
errorPrint("The table number(%"PRId64") of the thread is more than max query sql count: %d\n", errorPrint("The table number(%"PRId64") of the thread is more than max query sql count: %d\n",
pThreadInfo->ntables, MAX_QUERY_SQL_COUNT); pThreadInfo->ntables, MAX_QUERY_SQL_COUNT);
...@@ -7704,7 +7825,9 @@ static void *superSubscribe(void *sarg) { ...@@ -7704,7 +7825,9 @@ static void *superSubscribe(void *sarg) {
static void *specifiedSubscribe(void *sarg) { static void *specifiedSubscribe(void *sarg) {
threadInfo *pThreadInfo = (threadInfo *)sarg; threadInfo *pThreadInfo = (threadInfo *)sarg;
// TAOS_SUB* tsub = NULL; // TAOS_SUB* tsub = NULL;
setThreadName("specSub");
if (pThreadInfo->taos == NULL) { if (pThreadInfo->taos == NULL) {
pThreadInfo->taos = taos_connect(g_queryInfo.host, pThreadInfo->taos = taos_connect(g_queryInfo.host,
...@@ -7961,7 +8084,7 @@ static int subscribeTestProcess() { ...@@ -7961,7 +8084,7 @@ static int subscribeTestProcess() {
tmfree((char*)pidsOfStable); tmfree((char*)pidsOfStable);
tmfree((char*)infosOfStable); tmfree((char*)infosOfStable);
// taos_close(taos); // taos_close(taos);
return 0; return 0;
} }
......
...@@ -1474,6 +1474,8 @@ static void* taosDumpOutWorkThreadFp(void *arg) ...@@ -1474,6 +1474,8 @@ static void* taosDumpOutWorkThreadFp(void *arg)
STableRecord tableRecord; STableRecord tableRecord;
int fd; int fd;
setThreadName("dumpOutWorkThrd");
char tmpBuf[4096] = {0}; char tmpBuf[4096] = {0};
sprintf(tmpBuf, ".tables.tmp.%d", pThread->threadIndex); sprintf(tmpBuf, ".tables.tmp.%d", pThread->threadIndex);
fd = open(tmpBuf, O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH); fd = open(tmpBuf, O_RDWR | O_CREAT, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH);
...@@ -2571,6 +2573,8 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset, ...@@ -2571,6 +2573,8 @@ static int taosDumpInOneFile(TAOS* taos, FILE* fp, char* fcharset,
static void* taosDumpInWorkThreadFp(void *arg) static void* taosDumpInWorkThreadFp(void *arg)
{ {
SThreadParaObj *pThread = (SThreadParaObj*)arg; SThreadParaObj *pThread = (SThreadParaObj*)arg;
setThreadName("dumpInWorkThrd");
for (int32_t f = 0; f < g_tsSqlFileNum; ++f) { for (int32_t f = 0; f < g_tsSqlFileNum; ++f) {
if (f % pThread->totalThreads == pThread->threadIndex) { if (f % pThread->totalThreads == pThread->threadIndex) {
char *SQLFileName = g_tsDumpInSqlFiles[f]; char *SQLFileName = g_tsDumpInSqlFiles[f];
......
...@@ -1113,6 +1113,7 @@ static void *sdbWorkerFp(void *pWorker) { ...@@ -1113,6 +1113,7 @@ static void *sdbWorkerFp(void *pWorker) {
void * unUsed; void * unUsed;
taosBlockSIGPIPE(); taosBlockSIGPIPE();
setThreadName("sdbWorker");
while (1) { while (1) {
int32_t numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed); int32_t numOfMsgs = taosReadAllQitemsFromQset(tsSdbWQset, tsSdbWQall, &unUsed);
......
...@@ -210,6 +210,25 @@ extern "C" { ...@@ -210,6 +210,25 @@ extern "C" {
#define PRIzu "zu" #define PRIzu "zu"
#endif #endif
#if defined(_TD_LINUX_64) || defined(_TD_LINUX_32) || defined(_TD_MIPS_64) || defined(_TD_ARM_32) || defined(_TD_ARM_64) || defined(_TD_DARWIN_64)
#if defined(_TD_DARWIN_64)
// MacOS
#if !defined(_GNU_SOURCE)
#define setThreadName(name) do { pthread_setname_np((name)); } while (0)
#else
// pthread_setname_np not defined
#define setThreadName(name)
#endif
#else
// Linux, length of name must <= 16 (the last '\0' included)
#define setThreadName(name) do { prctl(PR_SET_NAME, (name)); } while (0)
#endif
#else
// Windows
#define setThreadName(name)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -85,6 +85,7 @@ extern "C" { ...@@ -85,6 +85,7 @@ extern "C" {
#include <sys/eventfd.h> #include <sys/eventfd.h>
#include <sys/resource.h> #include <sys/resource.h>
#include <sys/sendfile.h> #include <sys/sendfile.h>
#include <sys/prctl.h>
#if !(defined(_ALPINE)) #if !(defined(_ALPINE))
#include <error.h> #include <error.h>
......
...@@ -41,6 +41,8 @@ static semaphore_t sem_exit; ...@@ -41,6 +41,8 @@ static semaphore_t sem_exit;
static void* sem_thread_routine(void *arg) { static void* sem_thread_routine(void *arg) {
(void)arg; (void)arg;
setThreadName("sem_thrd");
sem_port = mach_task_self(); sem_port = mach_task_self();
kern_return_t ret = semaphore_create(sem_port, &sem_exit, SYNC_POLICY_FIFO, 0); kern_return_t ret = semaphore_create(sem_port, &sem_exit, SYNC_POLICY_FIFO, 0);
if (ret != KERN_SUCCESS) { if (ret != KERN_SUCCESS) {
......
...@@ -32,6 +32,7 @@ static volatile int timer_stop = 0; ...@@ -32,6 +32,7 @@ static volatile int timer_stop = 0;
static void* timer_routine(void *arg) { static void* timer_routine(void *arg) {
(void)arg; (void)arg;
setThreadName("timer");
int r = 0; int r = 0;
struct timespec to = {0}; struct timespec to = {0};
......
...@@ -38,6 +38,8 @@ static void *taosProcessAlarmSignal(void *tharg) { ...@@ -38,6 +38,8 @@ static void *taosProcessAlarmSignal(void *tharg) {
struct sigevent sevent = {{0}}; struct sigevent sevent = {{0}};
setThreadName("alarmSignal");
#ifdef _ALPINE #ifdef _ALPINE
sevent.sigev_notify = SIGEV_THREAD; sevent.sigev_notify = SIGEV_THREAD;
sevent.sigev_value.sival_int = syscall(__NR_gettid); sevent.sigev_value.sival_int = syscall(__NR_gettid);
......
...@@ -70,6 +70,8 @@ static void *httpProcessResultQueue(void *param) { ...@@ -70,6 +70,8 @@ static void *httpProcessResultQueue(void *param) {
int32_t type; int32_t type;
void * unUsed; void * unUsed;
setThreadName("httpResultQ");
while (1) { while (1) {
if (taosReadQitemFromQset(tsHttpQset, &type, (void **)&pMsg, &unUsed) == 0) { if (taosReadQitemFromQset(tsHttpQset, &type, (void **)&pMsg, &unUsed) == 0) {
httpDebug("qset:%p, http queue got no message from qset, exiting", tsHttpQset); httpDebug("qset:%p, http queue got no message from qset, exiting", tsHttpQset);
......
...@@ -117,6 +117,7 @@ static void httpProcessHttpData(void *param) { ...@@ -117,6 +117,7 @@ static void httpProcessHttpData(void *param) {
int32_t fdNum; int32_t fdNum;
taosSetMaskSIGPIPE(); taosSetMaskSIGPIPE();
setThreadName("httpData");
while (1) { while (1) {
struct epoll_event events[HTTP_MAX_EVENTS]; struct epoll_event events[HTTP_MAX_EVENTS];
...@@ -208,6 +209,7 @@ static void *httpAcceptHttpConnection(void *arg) { ...@@ -208,6 +209,7 @@ static void *httpAcceptHttpConnection(void *arg) {
int32_t totalFds = 0; int32_t totalFds = 0;
taosSetMaskSIGPIPE(); taosSetMaskSIGPIPE();
setThreadName("httpAcceptConn");
pServer->fd = taosOpenTcpServerSocket(pServer->serverIp, pServer->serverPort); pServer->fd = taosOpenTcpServerSocket(pServer->serverIp, pServer->serverPort);
......
...@@ -114,6 +114,7 @@ int32_t monStartSystem() { ...@@ -114,6 +114,7 @@ int32_t monStartSystem() {
static void *monThreadFunc(void *param) { static void *monThreadFunc(void *param) {
monDebug("starting to initialize monitor module ..."); monDebug("starting to initialize monitor module ...");
setThreadName("monThrd");
while (1) { while (1) {
static int32_t accessTimes = 0; static int32_t accessTimes = 0;
......
...@@ -100,6 +100,8 @@ void mqttPublishCallback(void** unused, struct mqtt_response_publish* published) ...@@ -100,6 +100,8 @@ void mqttPublishCallback(void** unused, struct mqtt_response_publish* published)
} }
void* mqttClientRefresher(void* client) { void* mqttClientRefresher(void* client) {
setThreadName("mqttCliRefresh");
while (tsMqttIsRuning) { while (tsMqttIsRuning) {
mqtt_sync((struct mqtt_client*)client); mqtt_sync((struct mqtt_client*)client);
taosMsleep(100); taosMsleep(100);
......
...@@ -254,7 +254,7 @@ typedef struct tSqlExpr { ...@@ -254,7 +254,7 @@ typedef struct tSqlExpr {
struct SArray *paramList; // function parameters list struct SArray *paramList; // function parameters list
} Expr; } Expr;
uint32_t functionId; // function id, todo remove it int32_t functionId; // function id, todo remove it
SStrToken columnName; // table column info SStrToken columnName; // table column info
tVariant value; // the use input value tVariant value; // the use input value
SStrToken exprToken; // original sql expr string SStrToken exprToken; // original sql expr string
......
...@@ -2427,7 +2427,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool ...@@ -2427,7 +2427,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
if (pQueryAttr->pointInterpQuery && pQueryAttr->interval.interval == 0) { if (pQueryAttr->pointInterpQuery && pQueryAttr->interval.interval == 0) {
if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { if (!QUERY_IS_ASC_QUERY(pQueryAttr)) {
qDebug(msg, pQInfo, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); qDebug(msg, pQInfo->qId, "interp", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
} }
...@@ -2438,7 +2438,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool ...@@ -2438,7 +2438,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
if (pQueryAttr->interval.interval == 0) { if (pQueryAttr->interval.interval == 0) {
if (onlyFirstQuery(pQueryAttr)) { if (onlyFirstQuery(pQueryAttr)) {
if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { if (!QUERY_IS_ASC_QUERY(pQueryAttr)) {
qDebug(msg, pQInfo, "only-first", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey, qDebug(msg, pQInfo->qId, "only-first", pQueryAttr->order.order, TSDB_ORDER_ASC, pQueryAttr->window.skey,
pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
...@@ -2449,7 +2449,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool ...@@ -2449,7 +2449,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
pQueryAttr->needReverseScan = false; pQueryAttr->needReverseScan = false;
} else if (onlyLastQuery(pQueryAttr) && notContainSessionOrStateWindow(pQueryAttr)) { } else if (onlyLastQuery(pQueryAttr) && notContainSessionOrStateWindow(pQueryAttr)) {
if (QUERY_IS_ASC_QUERY(pQueryAttr)) { if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
qDebug(msg, pQInfo, "only-last", pQueryAttr->order.order, TSDB_ORDER_DESC, pQueryAttr->window.skey, qDebug(msg, pQInfo->qId, "only-last", pQueryAttr->order.order, TSDB_ORDER_DESC, pQueryAttr->window.skey,
pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
...@@ -2464,7 +2464,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool ...@@ -2464,7 +2464,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
if (stableQuery) { if (stableQuery) {
if (onlyFirstQuery(pQueryAttr)) { if (onlyFirstQuery(pQueryAttr)) {
if (!QUERY_IS_ASC_QUERY(pQueryAttr)) { if (!QUERY_IS_ASC_QUERY(pQueryAttr)) {
qDebug(msg, pQInfo, "only-first stable", pQueryAttr->order.order, TSDB_ORDER_ASC, qDebug(msg, pQInfo->qId, "only-first stable", pQueryAttr->order.order, TSDB_ORDER_ASC,
pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
...@@ -2475,7 +2475,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool ...@@ -2475,7 +2475,7 @@ static void updateDataCheckOrder(SQInfo *pQInfo, SQueryTableMsg* pQueryMsg, bool
pQueryAttr->needReverseScan = false; pQueryAttr->needReverseScan = false;
} else if (onlyLastQuery(pQueryAttr)) { } else if (onlyLastQuery(pQueryAttr)) {
if (QUERY_IS_ASC_QUERY(pQueryAttr)) { if (QUERY_IS_ASC_QUERY(pQueryAttr)) {
qDebug(msg, pQInfo, "only-last stable", pQueryAttr->order.order, TSDB_ORDER_DESC, qDebug(msg, pQInfo->qId, "only-last stable", pQueryAttr->order.order, TSDB_ORDER_DESC,
pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey); pQueryAttr->window.skey, pQueryAttr->window.ekey, pQueryAttr->window.ekey, pQueryAttr->window.skey);
SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY); SWAP(pQueryAttr->window.skey, pQueryAttr->window.ekey, TSKEY);
...@@ -6594,10 +6594,19 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) { ...@@ -6594,10 +6594,19 @@ static SSDataBlock* hashDistinct(void* param, bool* newgroup) {
if (isNull(val, type)) { if (isNull(val, type)) {
continue; continue;
} }
size_t keyLen = 0;
if (IS_VAR_DATA_TYPE(pOperator->pExpr->base.colType)) {
tstr* var = (tstr*)(val);
keyLen = varDataLen(var);
} else {
keyLen = bytes;
}
int dummy; int dummy;
void* res = taosHashGet(pInfo->pSet, val, bytes); void* res = taosHashGet(pInfo->pSet, val, keyLen);
if (res == NULL) { if (res == NULL) {
taosHashPut(pInfo->pSet, val, bytes, &dummy, sizeof(dummy)); taosHashPut(pInfo->pSet, val, keyLen, &dummy, sizeof(dummy));
char* start = pResultColInfoData->pData + bytes * pInfo->pRes->info.rows; char* start = pResultColInfoData->pData + bytes * pInfo->pRes->info.rows;
memcpy(start, val, bytes); memcpy(start, val, bytes);
pRes->info.rows += 1; pRes->info.rows += 1;
...@@ -6624,6 +6633,7 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat ...@@ -6624,6 +6633,7 @@ SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperat
pOperator->blockingOptr = false; pOperator->blockingOptr = false;
pOperator->status = OP_IN_EXECUTING; pOperator->status = OP_IN_EXECUTING;
pOperator->operatorType = OP_Distinct; pOperator->operatorType = OP_Distinct;
pOperator->pExpr = pExpr;
pOperator->numOfOutput = numOfOutput; pOperator->numOfOutput = numOfOutput;
pOperator->info = pInfo; pOperator->info = pInfo;
pOperator->pRuntimeEnv = pRuntimeEnv; pOperator->pRuntimeEnv = pRuntimeEnv;
......
...@@ -242,6 +242,7 @@ static void *taosAcceptTcpConnection(void *arg) { ...@@ -242,6 +242,7 @@ static void *taosAcceptTcpConnection(void *arg) {
pServerObj = (SServerObj *)arg; pServerObj = (SServerObj *)arg;
tDebug("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port); tDebug("%s TCP server is ready, ip:0x%x:%hu", pServerObj->label, pServerObj->ip, pServerObj->port);
setThreadName("acceptTcpConn");
while (1) { while (1) {
socklen_t addrlen = sizeof(caddr); socklen_t addrlen = sizeof(caddr);
...@@ -528,6 +529,11 @@ static void *taosProcessTcpData(void *param) { ...@@ -528,6 +529,11 @@ static void *taosProcessTcpData(void *param) {
SFdObj *pFdObj; SFdObj *pFdObj;
struct epoll_event events[maxEvents]; struct epoll_event events[maxEvents];
SRecvInfo recvInfo; SRecvInfo recvInfo;
char name[16];
memset(name, 0, sizeof(name));
snprintf(name, 16, "%s-tcpData", pThreadObj->label);
setThreadName(name);
while (1) { while (1) {
int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME); int fdNum = epoll_wait(pThreadObj->pollFd, events, maxEvents, TAOS_EPOLL_WAIT_TIME);
......
...@@ -195,6 +195,8 @@ static void *taosRecvUdpData(void *param) { ...@@ -195,6 +195,8 @@ static void *taosRecvUdpData(void *param) {
tDebug("%s UDP thread is created, index:%d", pConn->label, pConn->index); tDebug("%s UDP thread is created, index:%d", pConn->label, pConn->index);
char *msg = pConn->buffer; char *msg = pConn->buffer;
setThreadName("recvUdpData");
while (1) { while (1) {
dataLen = recvfrom(pConn->fd, pConn->buffer, RPC_MAX_UDP_SIZE, 0, (struct sockaddr *)&sourceAdd, &addLen); dataLen = recvfrom(pConn->fd, pConn->buffer, RPC_MAX_UDP_SIZE, 0, (struct sockaddr *)&sourceAdd, &addLen);
if (dataLen <= 0) { if (dataLen <= 0) {
......
...@@ -48,6 +48,8 @@ static void *sendRequest(void *param) { ...@@ -48,6 +48,8 @@ static void *sendRequest(void *param) {
SInfo *pInfo = (SInfo *)param; SInfo *pInfo = (SInfo *)param;
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
setThreadName("sendCliReq");
tDebug("thread:%d, start to send request", pInfo->index); tDebug("thread:%d, start to send request", pInfo->index);
while ( pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) { while ( pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) {
......
...@@ -41,6 +41,8 @@ static void *sendRequest(void *param) { ...@@ -41,6 +41,8 @@ static void *sendRequest(void *param) {
SInfo *pInfo = (SInfo *)param; SInfo *pInfo = (SInfo *)param;
SRpcMsg rpcMsg, rspMsg; SRpcMsg rpcMsg, rspMsg;
setThreadName("sendSrvReq");
tDebug("thread:%d, start to send request", pInfo->index); tDebug("thread:%d, start to send request", pInfo->index);
while ( pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) { while ( pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) {
......
...@@ -263,6 +263,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) { ...@@ -263,6 +263,7 @@ static int32_t syncRestoreDataStepByStep(SSyncPeer *pPeer) {
} }
void *syncRestoreData(void *param) { void *syncRestoreData(void *param) {
setThreadName("syncRestoreData");
int64_t rid = (int64_t)param; int64_t rid = (int64_t)param;
SSyncPeer *pPeer = syncAcquirePeer(rid); SSyncPeer *pPeer = syncAcquirePeer(rid);
if (pPeer == NULL) { if (pPeer == NULL) {
......
...@@ -415,6 +415,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) { ...@@ -415,6 +415,7 @@ static int32_t syncRetrieveDataStepByStep(SSyncPeer *pPeer) {
} }
void *syncRetrieveData(void *param) { void *syncRetrieveData(void *param) {
setThreadName("syncRetrievData");
int64_t rid = (int64_t)param; int64_t rid = (int64_t)param;
SSyncPeer *pPeer = syncAcquirePeer(rid); SSyncPeer *pPeer = syncAcquirePeer(rid);
if (pPeer == NULL) { if (pPeer == NULL) {
......
...@@ -195,6 +195,8 @@ static void *syncProcessTcpData(void *param) { ...@@ -195,6 +195,8 @@ static void *syncProcessTcpData(void *param) {
SConnObj * pConn = NULL; SConnObj * pConn = NULL;
struct epoll_event events[maxEvents]; struct epoll_event events[maxEvents];
setThreadName("syncTcpData");
void *buffer = malloc(pInfo->bufferSize); void *buffer = malloc(pInfo->bufferSize);
taosBlockSIGPIPE(); taosBlockSIGPIPE();
...@@ -257,6 +259,7 @@ static void *syncAcceptPeerTcpConnection(void *argv) { ...@@ -257,6 +259,7 @@ static void *syncAcceptPeerTcpConnection(void *argv) {
SPoolInfo *pInfo = &pPool->info; SPoolInfo *pInfo = &pPool->info;
taosBlockSIGPIPE(); taosBlockSIGPIPE();
setThreadName("acceptTcpConn");
while (1) { while (1) {
struct sockaddr_in clientAddr; struct sockaddr_in clientAddr;
......
...@@ -48,6 +48,8 @@ void *sendRequest(void *param) { ...@@ -48,6 +48,8 @@ void *sendRequest(void *param) {
SInfo * pInfo = (SInfo *)param; SInfo * pInfo = (SInfo *)param;
SRpcMsg rpcMsg = {0}; SRpcMsg rpcMsg = {0};
setThreadName("sendCliReq");
uDebug("thread:%d, start to send request", pInfo->index); uDebug("thread:%d, start to send request", pInfo->index);
while (pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) { while (pInfo->numOfReqs == 0 || pInfo->num < pInfo->numOfReqs) {
......
...@@ -178,6 +178,8 @@ void *processWriteQueue(void *param) { ...@@ -178,6 +178,8 @@ void *processWriteQueue(void *param) {
int type; int type;
void *item; void *item;
setThreadName("writeQ");
while (1) { while (1) {
int ret = taosReadQitem(qhandle, &type, &item); int ret = taosReadQitem(qhandle, &type, &item);
if (ret <= 0) { if (ret <= 0) {
......
...@@ -158,6 +158,8 @@ static void *tsdbLoopCommit(void *arg) { ...@@ -158,6 +158,8 @@ static void *tsdbLoopCommit(void *arg) {
STsdbRepo * pRepo = NULL; STsdbRepo * pRepo = NULL;
TSDB_REQ_T req; TSDB_REQ_T req;
setThreadName("tsdbCommit");
while (true) { while (true) {
pthread_mutex_lock(&(pQueue->lock)); pthread_mutex_lock(&(pQueue->lock));
......
...@@ -656,6 +656,8 @@ void* taosCacheTimedRefresh(void *handle) { ...@@ -656,6 +656,8 @@ void* taosCacheTimedRefresh(void *handle) {
return NULL; return NULL;
} }
setThreadName("cacheTimedRefre");
const int32_t SLEEP_DURATION = 500; //500 ms const int32_t SLEEP_DURATION = 500; //500 ms
int64_t totalTick = pCacheObj->refreshTime / SLEEP_DURATION; int64_t totalTick = pCacheObj->refreshTime / SLEEP_DURATION;
......
...@@ -178,6 +178,8 @@ static void *taosThreadToOpenNewFile(void *param) { ...@@ -178,6 +178,8 @@ static void *taosThreadToOpenNewFile(void *param) {
char keepName[LOG_FILE_NAME_LEN + 20]; char keepName[LOG_FILE_NAME_LEN + 20];
sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag); sprintf(keepName, "%s.%d", tsLogObj.logName, tsLogObj.flag);
setThreadName("openNewFile");
tsLogObj.flag ^= 1; tsLogObj.flag ^= 1;
tsLogObj.lines = 0; tsLogObj.lines = 0;
char name[LOG_FILE_NAME_LEN + 20]; char name[LOG_FILE_NAME_LEN + 20];
...@@ -688,6 +690,8 @@ static void taosWriteLog(SLogBuff *tLogBuff) { ...@@ -688,6 +690,8 @@ static void taosWriteLog(SLogBuff *tLogBuff) {
static void *taosAsyncOutputLog(void *param) { static void *taosAsyncOutputLog(void *param) {
SLogBuff *tLogBuff = (SLogBuff *)param; SLogBuff *tLogBuff = (SLogBuff *)param;
setThreadName("asyncOutputLog");
while (1) { while (1) {
//tsem_wait(&(tLogBuff->buffNotEmpty)); //tsem_wait(&(tLogBuff->buffNotEmpty));
......
...@@ -50,6 +50,8 @@ static void *taosNetBindUdpPort(void *sarg) { ...@@ -50,6 +50,8 @@ static void *taosNetBindUdpPort(void *sarg) {
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
struct sockaddr_in clientAddr; struct sockaddr_in clientAddr;
setThreadName("netBindUdpPort");
if ((serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { if ((serverSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
uError("failed to create UDP socket since %s", strerror(errno)); uError("failed to create UDP socket since %s", strerror(errno));
return NULL; return NULL;
...@@ -113,6 +115,8 @@ static void *taosNetBindTcpPort(void *sarg) { ...@@ -113,6 +115,8 @@ static void *taosNetBindTcpPort(void *sarg) {
SOCKET client; SOCKET client;
char buffer[BUFFER_SIZE]; char buffer[BUFFER_SIZE];
setThreadName("netBindTcpPort");
if ((serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { if ((serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
uError("failed to create TCP socket since %s", strerror(errno)); uError("failed to create TCP socket since %s", strerror(errno));
return NULL; return NULL;
......
...@@ -84,6 +84,8 @@ static void *taosThreadToOpenNewNote(void *param) { ...@@ -84,6 +84,8 @@ static void *taosThreadToOpenNewNote(void *param) {
char name[NOTE_FILE_NAME_LEN * 2]; char name[NOTE_FILE_NAME_LEN * 2];
SNoteObj *pNote = (SNoteObj *)param; SNoteObj *pNote = (SNoteObj *)param;
setThreadName("openNewNote");
pNote->flag ^= 1; pNote->flag ^= 1;
pNote->lines = 0; pNote->lines = 0;
sprintf(name, "%s.%d", pNote->name, pNote->flag); sprintf(name, "%s.%d", pNote->name, pNote->flag);
......
...@@ -122,6 +122,8 @@ void *taosProcessSchedQueue(void *scheduler) { ...@@ -122,6 +122,8 @@ void *taosProcessSchedQueue(void *scheduler) {
SSchedQueue *pSched = (SSchedQueue *)scheduler; SSchedQueue *pSched = (SSchedQueue *)scheduler;
int ret = 0; int ret = 0;
setThreadName("schedQ");
while (1) { while (1) {
if ((ret = tsem_wait(&pSched->fullSem)) != 0) { if ((ret = tsem_wait(&pSched->fullSem)) != 0) {
uFatal("wait %s fullSem failed(%s)", pSched->label, strerror(errno)); uFatal("wait %s fullSem failed(%s)", pSched->label, strerror(errno));
......
...@@ -35,6 +35,8 @@ void *addRef(void *param) { ...@@ -35,6 +35,8 @@ void *addRef(void *param) {
SRefSpace *pSpace = (SRefSpace *)param; SRefSpace *pSpace = (SRefSpace *)param;
int id; int id;
setThreadName("addRef");
for (int i=0; i < pSpace->steps; ++i) { for (int i=0; i < pSpace->steps; ++i) {
printf("a"); printf("a");
id = random() % pSpace->refNum; id = random() % pSpace->refNum;
...@@ -52,6 +54,8 @@ void *removeRef(void *param) { ...@@ -52,6 +54,8 @@ void *removeRef(void *param) {
SRefSpace *pSpace = (SRefSpace *)param; SRefSpace *pSpace = (SRefSpace *)param;
int id, code; int id, code;
setThreadName("removeRef");
for (int i=0; i < pSpace->steps; ++i) { for (int i=0; i < pSpace->steps; ++i) {
printf("d"); printf("d");
id = random() % pSpace->refNum; id = random() % pSpace->refNum;
...@@ -70,6 +74,8 @@ void *acquireRelease(void *param) { ...@@ -70,6 +74,8 @@ void *acquireRelease(void *param) {
SRefSpace *pSpace = (SRefSpace *)param; SRefSpace *pSpace = (SRefSpace *)param;
int id; int id;
setThreadName("acquireRelease");
for (int i=0; i < pSpace->steps; ++i) { for (int i=0; i < pSpace->steps; ++i) {
printf("a"); printf("a");
...@@ -91,6 +97,8 @@ void myfree(void *p) { ...@@ -91,6 +97,8 @@ void myfree(void *p) {
void *openRefSpace(void *param) { void *openRefSpace(void *param) {
SRefSpace *pSpace = (SRefSpace *)param; SRefSpace *pSpace = (SRefSpace *)param;
setThreadName("openRefSpace");
printf("c"); printf("c");
pSpace->rsetId = taosOpenRef(50, myfree); pSpace->rsetId = taosOpenRef(50, myfree);
......
...@@ -61,6 +61,8 @@ static void vnodeProcessBackupMsg(SVBackupMsg *pMsg) { ...@@ -61,6 +61,8 @@ static void vnodeProcessBackupMsg(SVBackupMsg *pMsg) {
} }
static void *vnodeBackupFunc(void *param) { static void *vnodeBackupFunc(void *param) {
setThreadName("vnodeBackup");
while (1) { while (1) {
SVBackupMsg *pMsg = NULL; SVBackupMsg *pMsg = NULL;
if (taosReadQitemFromQset(tsVBackupQset, NULL, (void **)&pMsg, NULL) == 0) { if (taosReadQitemFromQset(tsVBackupQset, NULL, (void **)&pMsg, NULL) == 0) {
......
...@@ -188,6 +188,8 @@ static void vnodeProcessMWorkerMsg(SVMWorkerMsg *pMsg) { ...@@ -188,6 +188,8 @@ static void vnodeProcessMWorkerMsg(SVMWorkerMsg *pMsg) {
} }
static void *vnodeMWorkerFunc(void *param) { static void *vnodeMWorkerFunc(void *param) {
setThreadName("vnodeMWorker");
while (1) { while (1) {
SVMWorkerMsg *pMsg = NULL; SVMWorkerMsg *pMsg = NULL;
if (taosReadQitemFromQset(tsVMWorkerQset, NULL, (void **)&pMsg, NULL) == 0) { if (taosReadQitemFromQset(tsVMWorkerQset, NULL, (void **)&pMsg, NULL) == 0) {
......
...@@ -192,6 +192,7 @@ static void walFsyncAll() { ...@@ -192,6 +192,7 @@ static void walFsyncAll() {
static void *walThreadFunc(void *param) { static void *walThreadFunc(void *param) {
int stop = 0; int stop = 0;
setThreadName("walThrd");
while (1) { while (1) {
walUpdateSeq(); walUpdateSeq();
walFsyncAll(); walFsyncAll();
......
...@@ -5,6 +5,8 @@ IF (TD_LINUX) ...@@ -5,6 +5,8 @@ IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(. SRC) AUX_SOURCE_DIRECTORY(. SRC)
ADD_EXECUTABLE(demo apitest.c) ADD_EXECUTABLE(demo apitest.c)
TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread ) TARGET_LINK_LIBRARIES(demo taos_static trpc tutil pthread )
ADD_EXECUTABLE(sml schemaless.c)
TARGET_LINK_LIBRARIES(sml taos_static trpc tutil pthread )
ADD_EXECUTABLE(subscribe subscribe.c) ADD_EXECUTABLE(subscribe subscribe.c)
TARGET_LINK_LIBRARIES(subscribe taos_static trpc tutil pthread ) TARGET_LINK_LIBRARIES(subscribe taos_static trpc tutil pthread )
ADD_EXECUTABLE(epoll epoll.c) ADD_EXECUTABLE(epoll epoll.c)
......
...@@ -964,21 +964,31 @@ int32_t verify_schema_less(TAOS* taos) { ...@@ -964,21 +964,31 @@ int32_t verify_schema_less(TAOS* taos) {
usleep(100000); usleep(100000);
char* lines[] = { char* lines[] = {
"st,t1=3i,t2=4,t3=\"t3\" c1=3i,c3=L\"passit\",c2=false,c4=4 1626006833639000000", "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"st,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5 1626006833640000000", "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns",
"ste,t2=5,t3=L\"ste\" c1=true,c2=4,c3=\"iam\" 1626056811823316532", "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532ns",
"st,t1=4i,t2=5,t3=\"t4\" c1=3i,c3=L\"passitagain\",c2=true,c4=5 1626006833642000000", "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns",
"ste,t2=5,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532", "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns",
"ste,t2=5,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32b,c6=64s,c7=32w,c8=88.88f 1626056812843316532", "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns",
"st,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5,c6=7u 1626006933640000000", "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns",
"stf,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin\",c2=true,c4=5,c5=5,c6=7u 1626006933640000000", "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns",
"stf,t1=4i,t3=\"t4\",t2=5,t4=5 c1=3i,c3=L\"passitagin_stf\",c2=false,c5=5,c6=7u 1626006933641a" "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns"
}; };
// int code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*)); int code = 0;
int code = taos_insert_lines(taos, &lines[0], 1); code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*));
code = taos_insert_lines(taos, &lines[1], 1); char* lines2[] = {
"stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"
};
code = taos_insert_lines(taos, &lines2[0], 1);
code = taos_insert_lines(taos, &lines2[1], 1);
char* lines3[] = {
"sth,t1=4i64,t2=5f64,t4=5f64,ID=\"childtable\" c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641ms",
"sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933654ms"
};
code = taos_insert_lines(taos, lines3, 2);
return code; return code;
} }
...@@ -1000,10 +1010,8 @@ int main(int argc, char *argv[]) { ...@@ -1000,10 +1010,8 @@ int main(int argc, char *argv[]) {
printf("client info: %s\n", info); printf("client info: %s\n", info);
printf("************ verify shemaless *************\n"); printf("************ verify shemaless *************\n");
int code = verify_schema_less(taos); verify_schema_less(taos);
if (code == 0) {
return code;
}
printf("************ verify query *************\n"); printf("************ verify query *************\n");
verify_query(taos); verify_query(taos);
......
#include "taos.h"
#include "taoserror.h"
#include "os.h"
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <unistd.h>
int numSuperTables = 8;
int numChildTables = 1024;
int numRowsPerChildTable = 128;
void shuffle(char**lines, size_t n)
{
if (n > 1)
{
size_t i;
for (i = 0; i < n - 1; i++)
{
size_t j = i + rand() / (RAND_MAX / (n - i) + 1);
char* t = lines[j];
lines[j] = lines[i];
lines[i] = t;
}
}
}
static int64_t getTimeInUs() {
struct timeval systemTime;
gettimeofday(&systemTime, NULL);
return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec;
}
int main(int argc, char* argv[]) {
TAOS_RES *result;
const char* host = "127.0.0.1";
const char* user = "root";
const char* passwd = "taosdata";
taos_options(TSDB_OPTION_TIMEZONE, "GMT-8");
TAOS* taos = taos_connect(host, user, passwd, "", 0);
if (taos == NULL) {
printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos));
exit(1);
}
char* info = taos_get_server_info(taos);
printf("server info: %s\n", info);
info = taos_get_client_info(taos);
printf("client info: %s\n", info);
result = taos_query(taos, "drop database if exists db;");
taos_free_result(result);
usleep(100000);
result = taos_query(taos, "create database db precision 'ms';");
taos_free_result(result);
usleep(100000);
(void)taos_select_db(taos, "db");
time_t ct = time(0);
int64_t ts = ct * 1000;
char* lineFormat = "sta%d,t0=true,t1=127i8,t2=32767i16,t3=%di32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" %lldms";
char** lines = calloc(numSuperTables * numChildTables * numRowsPerChildTable, sizeof(char*));
int l = 0;
for (int i = 0; i < numSuperTables; ++i) {
for (int j = 0; j < numChildTables; ++j) {
for (int k = 0; k < numRowsPerChildTable; ++k) {
char* line = calloc(512, 1);
snprintf(line, 512, lineFormat, i, j, ts + 10 * l);
lines[l] = line;
++l;
}
}
}
shuffle(lines, numSuperTables * numChildTables * numRowsPerChildTable);
printf("%s\n", "begin taos_insert_lines");
int64_t begin = getTimeInUs();
int32_t code = taos_insert_lines(taos, lines, numSuperTables * numChildTables * numRowsPerChildTable);
int64_t end = getTimeInUs();
printf("code: %d, %s. time used: %"PRId64"\n", code, tstrerror(code), end-begin);
char* lines_000_0[] = {
"sta1,id=sta1_1,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=255u8,t6=32770u16,t7=2147483699u32,t8=9223372036854775899u64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833639000us"
};
code = taos_insert_lines(taos, lines_000_0 , sizeof(lines_000_0)/sizeof(char*));
if (0 == code) {
printf("taos_insert_lines() lines_000_0 should return error\n");
return -1;
}
char* lines_000_1[] = {
"sta2,id=\"sta2_1\",t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=255u8,t6=32770u16,t7=2147483699u32,t8=9223372036854775899u64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833639001"
};
code = taos_insert_lines(taos, lines_000_1 , sizeof(lines_000_1)/sizeof(char*));
if (0 == code) {
printf("taos_insert_lines() lines_000_1 should return error\n");
return -1;
}
char* lines_000_2[] = {
"sta3,id=\"sta3_1\",t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=255u8,c6=32770u16,c7=2147483699u32,c8=9223372036854775899u64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" 0"
};
code = taos_insert_lines(taos, lines_000_2 , sizeof(lines_000_2)/sizeof(char*));
if (0 != code) {
printf("taos_insert_lines() lines_000_2 return code:%d (%s)\n", code, (char*)tstrerror(code));
return -1;
}
char* lines_001_0[] = {
"sta4,t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833639000us",
};
code = taos_insert_lines(taos, lines_001_0 , sizeof(lines_001_0)/sizeof(char*));
if (0 != code) {
printf("taos_insert_lines() lines_001_0 return code:%d (%s)\n", code, (char*)tstrerror(code));
return -1;
}
char* lines_001_1[] = {
"sta5,id=\"sta5_1\",t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833639001"
};
code = taos_insert_lines(taos, lines_001_1 , sizeof(lines_001_1)/sizeof(char*));
if (0 != code) {
printf("taos_insert_lines() lines_001_1 return code:%d (%s)\n", code, (char*)tstrerror(code));
return -1;
}
char* lines_001_2[] = {
"sta6,id=\"sta6_1\",t0=true,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t9=11.12345f32,t10=22.123456789f64,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c0=true,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c9=11.12345f32,c10=22.123456789f64,c11=\"binaryValue\",c12=L\"ncharValue\" 0"
};
code = taos_insert_lines(taos, lines_001_2 , sizeof(lines_001_2)/sizeof(char*));
if (0 != code) {
printf("taos_insert_lines() lines_001_2 return code:%d (%s)\n", code, (char*)tstrerror(code));
return -1;
}
char* lines_002[] = {
"stb,id=\"stb_1\",t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833639000000ns",
"stc,id=\"stc_1\",t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833639019us",
"stc,id=\"stc_1\",t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006833640ms",
"stc,id=\"stc_1\",t20=t,t21=T,t22=true,t23=True,t24=TRUE,t25=f,t26=F,t27=false,t28=False,t29=FALSE,t10=33.12345,t11=\"binaryTagValue\",t12=L\"ncharTagValue\" c20=t,c21=T,c22=true,c23=True,c24=TRUE,c25=f,c26=F,c27=false,c28=False,c29=FALSE,c10=33.12345,c11=\"binaryValue\",c12=L\"ncharValue\" 1626006834s"
};
code = taos_insert_lines(taos, lines_002 , sizeof(lines_002)/sizeof(char*));
if (0 != code) {
printf("taos_insert_lines() lines_002 return code:%d (%s)\n", code, (char*)tstrerror(code));
return -1;
}
return 0;
}
...@@ -27,6 +27,7 @@ python3 ./test.py -f insert/bug3654.py ...@@ -27,6 +27,7 @@ python3 ./test.py -f insert/bug3654.py
python3 ./test.py -f insert/insertDynamicColBeforeVal.py python3 ./test.py -f insert/insertDynamicColBeforeVal.py
python3 ./test.py -f insert/in_function.py python3 ./test.py -f insert/in_function.py
python3 ./test.py -f insert/modify_column.py python3 ./test.py -f insert/modify_column.py
python3 ./test.py -f insert/line_insert.py
#table #table
python3 ./test.py -f table/alter_wal0.py python3 ./test.py -f table/alter_wal0.py
...@@ -361,4 +362,6 @@ python3 test.py -f alter/alter_keep.py ...@@ -361,4 +362,6 @@ python3 test.py -f alter/alter_keep.py
python3 test.py -f alter/alter_cacheLastRow.py python3 test.py -f alter/alter_cacheLastRow.py
python3 ./test.py -f query/querySession.py python3 ./test.py -f query/querySession.py
python3 test.py -f alter/alter_create_exception.py python3 test.py -f alter/alter_create_exception.py
python3 ./test.py -f insert/flushwhiledrop.py
#======================p4-end=============== #======================p4-end===============
###################################################################
# 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 threading
from util.log import *
from util.cases import *
from util.sql import *
from time import sleep
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self.numberOfRecords = 15000
self.ts = 1601481600000
def run(self):
tdSql.execute('create database test cache 1 blocks 3')
tdSql.execute('use test')
tdSql.execute('create table tb(ts timestamp, c1 timestamp, c2 int, c3 bigint, c4 float, c5 double, c6 binary(8), c7 smallint, c8 tinyint, c9 bool, c10 nchar(8))')
threads = []
t1 = threading.Thread(target=self.insertAndFlush, args=())
threads.append(t1)
t2 = threading.Thread(target=self.drop, args=())
threads.append(t2)
for t in threads:
t.setDaemon(True)
t.start()
for t in threads:
t.join()
def insertAndFlush(self):
finish = 0
currts = self.ts
while(finish < self.numberOfRecords):
sql = "insert into tb values"
for i in range(finish, self.numberOfRecords):
sql += "(%d, 1019774612, 29931, 1442173978, 165092.468750, 1128.643179, 'MOCq1pTu', 18405, 82, 0, 'g0A6S0Fu')" % (currts + i)
finish = i + 1
if (1048576 - len(sql)) < 16384:
break
tdSql.execute(sql)
def drop(self):
sleep(30)
tdSql.execute('drop database test')
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
\ No newline at end of file
###################################################################
# Copyright (c) 2021 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
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self._conn = conn
def run(self):
print("running {}".format(__file__))
tdSql.execute("drop database if exists test")
tdSql.execute("create database if not exists test precision 'us'")
tdSql.execute('use test')
tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)')
lines = [ "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns",
"ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532ns",
"stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns",
"st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns",
"ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns",
"ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns",
"stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns"
]
code = self._conn.insertLines(lines)
print("insertLines result {}".format(code))
lines2 = [ "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
"stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"
]
code = self._conn.insertLines([ lines2[0] ])
print("insertLines result {}".format(code))
self._conn.insertLines([ lines2[1] ])
print("insertLines result {}".format(code))
tdSql.query("select * from st")
tdSql.checkRows(4)
tdSql.query("select * from ste")
tdSql.checkRows(3)
tdSql.query("select * from stf")
tdSql.checkRows(2)
tdSql.query("select * from stg")
tdSql.checkRows(2)
tdSql.query("show tables")
tdSql.checkRows(8)
tdSql.query("describe stf")
tdSql.checkData(2, 2, 14)
self._conn.insertLines([
"sth,t1=4i64,t2=5f64,t4=5f64,ID=\"childtable\" c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641ms",
"sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933654ms"
])
tdSql.query('select tbname, * from sth')
tdSql.checkRows(2)
tdSql.query('select tbname, * from childtable')
tdSql.checkRows(1)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
NAME=robust
CFLAGS = -O3 -g -Wall -Wno-deprecated -fPIC -Wno-unused-result -Wconversion -Wno-char-subscripts -D_REENTRANT -Wno-format -DLINUX -msse4.2 -Wno-unused-function -D_M_X64 -std=gnu99
all:
gcc $(CFLAGS) ./$(NAME).c -o $(NAME) -ltaos -lpthread
clean:
rm $(NAME)
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h>
#include <pthread.h>
#include <sys/time.h>
#include <unistd.h>
typedef struct {
char querySQL[256];
int client;
int stable;
int table;
unsigned interval;
int insert;
int create;
int query;
} ProArgs;
typedef struct {
pthread_t pid;
int threadId;
void* taos;
} ThreadObj;
static ProArgs arguments;
void parseArg(int argc, char *argv[]);
void create();
void createImp(void *param);
void start();
void insertImp(void *param);
void queryImp(void *param);
int64_t getTimeStampMs() {
struct timeval systemTime;
gettimeofday(&systemTime, NULL);
return (int64_t)systemTime.tv_sec * 1000L + (int64_t)systemTime.tv_usec / 1000;
}
void parseArg(int argc, char *argv[]) {
arguments.stable = 100000;
arguments.table = 50;
arguments.client = 16;
arguments.interval = 1;
sprintf(arguments.querySQL, "select count(*) from");
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-stable") == 0) {
if (i < argc - 1) {
arguments.stable = atoi(argv[++i]);
} else {
fprintf(stderr, "'-stable' requires a parameter, default:%d\n", arguments.stable);
}
} else if (strcmp(argv[i], "-table") == 0) {
if (i < argc - 1) {
arguments.table = atoi(argv[++i]);
} else {
fprintf(stderr, "'-table' requires a parameter, default:%d\n", arguments.table);
}
} else if (strcmp(argv[i], "-client") == 0) {
if (i < argc - 1) {
arguments.client = atoi(argv[++i]);
} else {
fprintf(stderr, "'-client' requires a parameter, default:%d\n", arguments.client);
}
} else if (strcmp(argv[i], "-sql") == 0) {
if (i < argc - 1) {
strcpy(arguments.querySQL,argv[++i]);
} else {
fprintf(stderr, "'-sql' requires a parameter, default:%d\n", arguments.querySQL);
}
} else if (strcmp(argv[i], "-insert") == 0) {
arguments.insert = 1;
} else if (strcmp(argv[i], "-create") == 0) {
arguments.create = 1;
} else if (strcmp(argv[i], "-query") == 0) {
arguments.query = 1;
}
}
}
void create() {
int64_t st = getTimeStampMs();
void *taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0);
if (taos == NULL) {
printf("TDengine error: failed to connect\n");
exit(EXIT_FAILURE);
}
TAOS_RES *result = taos_query(taos, "drop database if exists db");
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
exit(EXIT_FAILURE);
}
taos_free_result(result);
int64_t elapsed = getTimeStampMs() - st;
printf("--- spend %ld ms to drop database db\n", elapsed);
st = getTimeStampMs();
result = taos_query(taos, "create database if not exists db");
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
exit(EXIT_FAILURE);
}
taos_free_result(result);
elapsed = getTimeStampMs() - st;
printf("--- spend %ld ms to create database db\n", elapsed);
st = getTimeStampMs();
start();
printf("--- Spend %ld ms to create %d super tables and each %d tables\n", elapsed, arguments.stable, arguments.table);
}
void createImp(void *param) {
char command[256] = "\0";
int sqlLen = 0;
int count = 0;
char *sql = calloc(1, 1024*1024);
ThreadObj *pThread = (ThreadObj *)param;
printf("Thread %d start create super table s%d to s%d\n", pThread->threadId, (pThread->threadId - 1) * arguments.stable / arguments.client, pThread->threadId * arguments.stable / arguments.client - 1);
for (int i = (pThread->threadId - 1) * arguments.stable / arguments.client; i < pThread->threadId * arguments.stable / arguments.client; i++) {
sprintf(command, "create table if not exists db.s%d(ts timestamp, c1 int, c2 int, c3 int) TAGS (id int)", i);
TAOS_RES *result = taos_query(pThread->taos, command);
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql:%s, reason:%s\n", __LINE__, command, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
result = taos_query(pThread->taos, "use db");
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
sqlLen = sprintf(sql, "create table if not exists ");
count = 0;
for (int j = 0; j < arguments.table; j++) {
sqlLen += sprintf(sql + sqlLen, " s%d_%d USING s%d TAGS (%d)", i, j, i, j);
if ((j + 1) % arguments.table == 0) {
result = taos_query(pThread->taos, sql);
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
printf("Thread %d created table s%d_%d to s%d_%d\n", pThread->threadId, i, count, i, j);
count = j;
sqlLen = sprintf(sql, "create table if not exists ");
}
}
}
}
void start() {
ThreadObj *threads = calloc((size_t)arguments.client, sizeof(ThreadObj));
for (int i = 0; i < arguments.client; i++) {
ThreadObj *pthread = threads + i;
pthread_attr_t thattr;
pthread->threadId = i + 1;
pthread->taos = taos_connect("127.0.0.1", "root", "taosdata", NULL, 0);
pthread_attr_init(&thattr);
pthread_attr_setdetachstate(&thattr, PTHREAD_CREATE_JOINABLE);
if (arguments.create) {
pthread_create(&pthread->pid, &thattr, (void *(*)(void *))createImp, pthread);
} else if (arguments.insert) {
pthread_create(&pthread->pid, &thattr, (void *(*)(void *))insertImp, pthread);
} else if (arguments.query) {
pthread_create(&pthread->pid, &thattr, (void *(*)(void *))queryImp, pthread);
}
}
for (int i = 0; i < arguments.client; i++) {
pthread_join(threads[i].pid, NULL);
}
free(threads);
}
void insertImp(void *param) {
int count = 0;
ThreadObj *pThread = (ThreadObj *)param;
printf("Thread %d start insert data\n", pThread->threadId);
int sqlLen = 0;
char *sql = calloc(1, 1024*1024);
TAOS_RES *result = taos_query(pThread->taos, "use db");
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
int64_t time = getTimeStampMs();
while (true) {
sqlLen = sprintf(sql, "insert into");
for (int i = (pThread->threadId - 1) * arguments.stable / arguments.client; i < pThread->threadId * arguments.stable / arguments.client; i++) {
for (int j = 0; j < arguments.table; j++) {
sqlLen += sprintf(sql + sqlLen, " s%d_%d values (%ld, %d, %d, %d)", i, j, time, rand(), rand(), rand());
count++;
if ( (1048576 - sqlLen) < 49151 || i == (pThread->threadId * arguments.stable / arguments.client - 1)) {
result = taos_query(pThread->taos, sql);
printf("Thread %d already insert %d rows\n", pThread->threadId, count);
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
sqlLen = sprintf(sql, "insert into");
}
}
}
time += 1000*arguments.interval;
}
}
void queryImp(void *param) {
ThreadObj *pThread = (ThreadObj *)param;
printf("Thread %d start query\n", pThread->threadId);
int sqlLen = 0;
char *sql = calloc(1, 1024*1024);
TAOS_RES *result = taos_query(pThread->taos, "use db");
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql, reason:%s\n", __LINE__, taos_errstr(result));
taos_free_result(result);
return;
}
taos_free_result(result);
while (true) {
for (int i = (pThread->threadId - 1) * arguments.stable / arguments.client; i < pThread->threadId * arguments.stable / arguments.client; i++) {
sqlLen = sprintf(sql, arguments.querySQL);
sqlLen += sprintf(sql + sqlLen, " s%d", i);
result = taos_query(pThread->taos, sql);
if (result == NULL || taos_errno(result) != 0) {
printf("In line:%d, failed to execute sql: %s, reason:%s\n", __LINE__, sql, taos_errstr(result));
taos_free_result(result);
return;
}
int num_fields = taos_field_count(result);
TAOS_FIELD *fields = taos_fetch_fields(result);
TAOS_ROW row = NULL;
while ((row = taos_fetch_row(result))) {
char temp[16000] = {0};
int len = taos_print_row(temp, row, fields, num_fields);
len += sprintf(temp + len, "\n");
printf("Thread %d query result: %s\n", pThread->threadId, temp);
}
taos_free_result(result);
sleep(arguments.interval);
}
}
}
int main(int argc, char *argv[]) {
parseArg(argc, argv);
if (arguments.insert || arguments.query || arguments.create) {
start();
} else {
printf("choose one argument: \n1) -create\n2) -insert\n3) -query\n");
}
}
\ No newline at end of file
...@@ -105,6 +105,7 @@ run general/parser/import_commit2.sim ...@@ -105,6 +105,7 @@ run general/parser/import_commit2.sim
run general/parser/import_commit3.sim run general/parser/import_commit3.sim
run general/parser/insert_tb.sim run general/parser/insert_tb.sim
run general/parser/first_last.sim run general/parser/first_last.sim
run general/parser/line_insert.sim
#unsupport run general/parser/import_file.sim #unsupport run general/parser/import_file.sim
run general/parser/lastrow.sim run general/parser/lastrow.sim
run general/parser/nchar.sim run general/parser/nchar.sim
......
...@@ -16,11 +16,10 @@ sql create database $db precision 'us' ...@@ -16,11 +16,10 @@ sql create database $db precision 'us'
sql use $db sql use $db
sql create stable $mte (ts timestamp, f int) TAGS(t1 bigint) sql create stable $mte (ts timestamp, f int) TAGS(t1 bigint)
line_insert st,t1=3i,t2=4,t3="t3" c1=3i,c3=L"passit",c2=false,c4=4 1626006833639000000 line_insert st,t1=3i64,t2=4f64,t3="t3" c1=3i64,c3=L"passit",c2=false,c4=4f64 1626006833639000000ns
line_insert st,t1=4i,t3="t41",t2=5 c1=3i,c3=L"passiT",c2=true,c4=5 1626006833640000000 line_insert st,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin",c2=true,c4=5f64,c5=5f64 1626006833640000000ns
line_insert stf,t1=4i,t2=5,t3="t4" c1=3i,c3=L"passitagain",c2=true,c4=5 1626006833642000000 line_insert ste,t2=5f64,t3=L"ste" c1=true,c2=4i64,c3="iam" 1626056811823316532ns
line_insert ste,t2=5,t3=L"ste" c1=true,c2=4,c3="iam" 1626056811823316532 line_insert stf,t1=4i64,t3="t4",t2=5f64,t4=5f64 c1=3i64,c3=L"passitagin",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns
sql select * from st sql select * from st
if $rows != 2 then if $rows != 2 then
return -1 return -1
...@@ -30,7 +29,7 @@ if $data00 != @21-07-11 20:33:53.639000@ then ...@@ -30,7 +29,7 @@ if $data00 != @21-07-11 20:33:53.639000@ then
return -1 return -1
endi endi
if $data03 != @passit@ then if $data02 != @passit@ then
return -1 return -1
endi endi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册