Skip to content

Commit

Permalink
fix: add geometry and varbinary
Browse files Browse the repository at this point in the history
  • Loading branch information
DuanKuanJun committed Jun 13, 2024
1 parent d5dd5e6 commit 2f2aa16
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 2 deletions.
1 change: 1 addition & 0 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -1180,5 +1180,6 @@ uint64_t tmpUint64Impl(Field *field, int32_t angle, int64_t k);
float tmpFloatImpl(Field *field, int i, int32_t angle, int32_t k);
double tmpDoubleImpl(Field *field, int32_t angle, int32_t k);
int tmpStr(char *tmp, int iface, Field *field, int64_t k);
int tmpGeometry(char *tmp, int iface, Field *field, int64_t k);

#endif // INC_BENCH_H_
119 changes: 117 additions & 2 deletions src/benchData.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ uint32_t accumulateRowLen(BArray *fields, int iface) {
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY:
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_GEOMETRY:
len += field->length + 3;
break;
case TSDB_DATA_TYPE_INT:
Expand Down Expand Up @@ -483,6 +482,41 @@ int tmpStr(char *tmp, int iface, Field *field, int64_t k) {
return 0;
}

int tmpGeometry(char *tmp, int iface, Field *field, int64_t k) {
// values
if (field->values) {
int arraySize = tools_cJSON_GetArraySize(field->values);
if (arraySize) {
tools_cJSON *buf = tools_cJSON_GetArrayItem(
field->values,
taosRandom() % arraySize);
snprintf(tmp, field->length,
"%s", buf->valuestring);
} else {
errorPrint("%s() cannot read correct value "
"from json file. array size: %d\n",
__func__, arraySize);
return -1;
}
return 0;
}

// gen point count
int32_t cnt = field->length / 24;
if(cnt == 0) {
snprintf(tmp, field->length, "POINT(%d %d)", tmpUint16(field), tmpUint16(field));
return 0;
}

int32_t pos = snprintf(tmp, field->length, "LINESTRING(");
for(int32_t i = 0; i < cnt; i++) {
pos = snprintf(tmp + pos, field->length - pos, "%d %d", tmpUint16(field), tmpUint16(field));
}
strcat(tmp, ")");

return 0;
}

bool tmpBool(Field *field) {
bool boolTmp;
if (field->min == field->max) {
Expand Down Expand Up @@ -1001,6 +1035,28 @@ static int fillStmt(
tmfree(tmp);
break;
}
case TSDB_DATA_TYPE_GEOMETRY: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpGeometry(tmp, stbInfo->iface, field, k)) {
tmfree(tmp);
return -1;
}
if (childCol) {
snprintf((char *)childCol->stmtData.data
+ k * field->length,
field->length,
"%s", tmp);
} else {
snprintf((char *)field->stmtData.data
+ k * field->length,
field->length,
"%s", tmp);
}
n = snprintf(sampleDataBuf + pos, bufLen - pos,
"'%s',", tmp);
tmfree(tmp);
break;
}
case TSDB_DATA_TYPE_JSON: {
pos += tmpJson(sampleDataBuf, bufLen, pos,
fieldsSize, field);
Expand Down Expand Up @@ -1231,7 +1287,7 @@ static int generateRandDataSmlTelnet(SSuperTable *stbInfo, char *sampleDataBuf,
case TSDB_DATA_TYPE_NCHAR: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
free(tmp);
tmfree(tmp);
return -1;
}
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY) {
Expand Down Expand Up @@ -1272,6 +1328,31 @@ static int generateRandDataSmlTelnet(SSuperTable *stbInfo, char *sampleDataBuf,
tmfree(tmp);
break;
}
case TSDB_DATA_TYPE_GEOMETRY: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpGeometry(tmp, stbInfo->iface, field, k)) {
tmfree(tmp);
return -1;
}
if (tag) {
n = snprintf(sampleDataBuf + pos, bufLen - pos,
"%s=L\"%s\" ",
field->name, tmp);
} else {
n = snprintf(sampleDataBuf + pos, bufLen - pos,
"\"%s\" ", tmp);
}
if (n < 0 || n >= bufLen - pos) {
errorPrint("%s() LN%d snprintf overflow\n",
__func__, __LINE__);
tmfree(tmp);
return -1;
} else {
pos += n;
}
tmfree(tmp);
break;
}
case TSDB_DATA_TYPE_JSON: {
pos += tmpJson(sampleDataBuf, bufLen, pos,
fieldsSize, field);
Expand Down Expand Up @@ -1534,6 +1615,18 @@ static int generateRandDataSmlLine(SSuperTable *stbInfo, char *sampleDataBuf,
tmfree(tmp);
break;
}
case TSDB_DATA_TYPE_GEOMETRY: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpGeometry(tmp, stbInfo->iface, field, k)) {
tmfree(tmp);
return -1;
}
n = snprintf(sampleDataBuf + pos, bufLen - pos,
"%s=\"%s\",",
field->name, tmp);
tmfree(tmp);
break;
}
case TSDB_DATA_TYPE_JSON: {
n = tmpJson(sampleDataBuf, bufLen, pos,
fieldsSize, field);
Expand Down Expand Up @@ -2075,6 +2168,15 @@ void generateSmlJsonValues(
tmfree(buf);
break;
}
case TSDB_DATA_TYPE_GEOMETRY: {
char *buf = (char *)benchCalloc(col->length + 1, 1, false);
tmpGeometry(buf, stbInfo->iface, col, 0);
value_buf = benchCalloc(len_key + col->length + 3, 1, true);
snprintf(value_buf, len_key + col->length + 3,
"\"value\":\"%s\",", buf);
tmfree(buf);
break;
}
default: {
value_buf = benchCalloc(len_key + 20, 1, true);
double doubleTmp = tmpDouble(col);
Expand Down Expand Up @@ -2120,6 +2222,13 @@ void generateSmlJsonCols(tools_cJSON *array, tools_cJSON *tag,
tmfree(buf);
break;
}
case TSDB_DATA_TYPE_GEOMETRY: {
char *buf = (char *)benchCalloc(col->length + 1, 1, false);
tmpGeometry(buf, stbInfo->iface, col, 0);
tools_cJSON_AddStringToObject(record, "value", buf);
tmfree(buf);
break;
}
default: {
double doubleTmp = tmpDouble(col);
tools_cJSON_AddNumberToObject(record, "value", doubleTmp);
Expand Down Expand Up @@ -2180,6 +2289,12 @@ void generateSmlTaosJsonCols(tools_cJSON *array, tools_cJSON *tag,
tmfree(buf);
break;
}
case TSDB_DATA_TYPE_GEOMETRY:
char *buf = (char *)benchCalloc(col->length + 1, 1, false);
tmpGeometry(buf, stbInfo->iface, col, 0);
tools_cJSON_AddStringToObject(value, "value", buf);
tools_cJSON_AddStringToObject(value, "type", "geometry");
tmfree(buf);
default: {
double dblTmp = (double)col->min;
if (col->max != col->min) {
Expand Down
3 changes: 3 additions & 0 deletions src/benchDataMix.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ uint32_t dataGenByField(Field* fd, char* pstr, uint32_t len, char* prefix, int64
format = ",\'%s\'";
tmpStr(val, 0, fd, *k);
break;
case TSDB_DATA_TYPE_GEOMETRY:
tmpGeometry(val, 0, fd, 0);
break;
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ static int createSuperTable(SDataBase* database, SSuperTable* stbInfo) {
int n;
if (col->type == TSDB_DATA_TYPE_BINARY ||
col->type == TSDB_DATA_TYPE_NCHAR ||
col->type == TSDB_DATA_TYPE_VARBINARY ||
col->type == TSDB_DATA_TYPE_GEOMETRY) {
n = snprintf(colsBuf + len, col_buffer_len - len,
",%s %s(%d)", col->name,
Expand Down Expand Up @@ -318,6 +319,7 @@ static int createSuperTable(SDataBase* database, SSuperTable* stbInfo) {
Field *tag = benchArrayGet(stbInfo->tags, tagIndex);
if (tag->type == TSDB_DATA_TYPE_BINARY ||
tag->type == TSDB_DATA_TYPE_NCHAR ||
tag->type == TSDB_DATA_TYPE_VARBINARY ||
tag->type == TSDB_DATA_TYPE_GEOMETRY) {
n = snprintf(tagsBuf + len, tag_buffer_len - len,
"%s %s(%d),", tag->name,
Expand Down Expand Up @@ -2834,6 +2836,8 @@ static int initStmtDataValue(SSuperTable *stbInfo, SChildTable *childTbl) {
break;
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY:
{
size_t tmpLen = strlen(tmpStr);
debugPrint("%s() LN%d, index: %d, "
Expand Down Expand Up @@ -2926,6 +2930,7 @@ static void initStmtData(char dataType, void **data, uint32_t length) {

case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_GEOMETRY:
tmpP = calloc(1, g_arguments->prepared_rand * length);
assert(tmpP);
tmfree(*data);
Expand Down
2 changes: 2 additions & 0 deletions src/benchJsonOpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ static int getColumnAndTagTypeFromInsertJsonFile(
} else {
if (type == TSDB_DATA_TYPE_BINARY
|| type == TSDB_DATA_TYPE_JSON
|| type == TSDB_DATA_TYPE_VARBINARY
|| type == TSDB_DATA_TYPE_GEOMETRY
|| type == TSDB_DATA_TYPE_NCHAR) {
length = g_arguments->binwidth;
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/benchUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,8 @@ int convertStringToDatatype(char *type, int length) {
return TSDB_DATA_TYPE_BINARY;
} else if (0 == strcasecmp(type, "varbinary")) {
return TSDB_DATA_TYPE_VARBINARY;
} else if (0 == strcasecmp(type, "geometry")) {
return TSDB_DATA_TYPE_GEOMETRY;
} else {
errorPrint("unknown data type: %s\n", type);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -1045,6 +1047,8 @@ int convertStringToDatatype(char *type, int length) {
return TSDB_DATA_TYPE_BINARY;
} else if (0 == strncasecmp(type, "varbinary", length)) {
return TSDB_DATA_TYPE_VARBINARY;
} else if (0 == strncasecmp(type, "geometry", length)) {
return TSDB_DATA_TYPE_GEOMETRY;
} else {
errorPrint("unknown data type: %s\n", type);
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 2f2aa16

Please sign in to comment.