Skip to content

Commit

Permalink
feat: add newtype varbinary
Browse files Browse the repository at this point in the history
  • Loading branch information
DuanKuanJun committed May 25, 2024
1 parent 166b32a commit 50a1074
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/benchData.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ uint32_t accumulateRowLen(BArray *fields, int iface) {
Field *field = benchArrayGet(fields, i);
switch (field->type) {
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_GEOMETRY:
case TSDB_DATA_TYPE_NCHAR:
len += field->length + 3;
break;
Expand Down Expand Up @@ -780,6 +782,7 @@ static int generateRandDataSQL(SSuperTable *stbInfo, char *sampleDataBuf,
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
Expand Down Expand Up @@ -959,6 +962,7 @@ static int fillStmt(
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
Expand Down Expand Up @@ -1207,13 +1211,14 @@ static int generateRandDataSmlTelnet(SSuperTable *stbInfo, char *sampleDataBuf,
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
free(tmp);
return -1;
}
if (field->type == TSDB_DATA_TYPE_BINARY) {
if (field->type == TSDB_DATA_TYPE_BINARY || field->type == TSDB_DATA_TYPE_VARBINARY) {
if (tag) {
n = snprintf(sampleDataBuf + pos, bufLen - pos,
"%s=L\"%s\" ",
Expand Down Expand Up @@ -1359,6 +1364,7 @@ static int generateRandDataSmlJson(SSuperTable *stbInfo, char *sampleDataBuf,
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
Expand Down Expand Up @@ -1493,6 +1499,7 @@ static int generateRandDataSmlLine(SSuperTable *stbInfo, char *sampleDataBuf,
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *tmp = benchCalloc(1, field->length + 1, false);
if (0 != tmpStr(tmp, stbInfo->iface, field, k)) {
Expand Down Expand Up @@ -1915,10 +1922,11 @@ void generateSmlJsonTags(tools_cJSON *tagsList,
}

case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *buf = (char *)benchCalloc(tag->length + 1, 1, false);
rand_string(buf, tag->length, g_arguments->chinese);
if (tag->type == TSDB_DATA_TYPE_BINARY) {
if (tag->type == TSDB_DATA_TYPE_BINARY || tag->type == TSDB_DATA_TYPE_VARBINARY) {
tools_cJSON_AddStringToObject(tags, tagName, buf);
} else {
tools_cJSON_AddStringToObject(tags, tagName, buf);
Expand Down Expand Up @@ -1981,10 +1989,11 @@ void generateSmlTaosJsonTags(tools_cJSON *tagsList, SSuperTable *stbInfo,
}

case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *buf = (char *)benchCalloc(tag->length + 1, 1, false);
rand_string(buf, tag->length, g_arguments->chinese);
if (tag->type == TSDB_DATA_TYPE_BINARY) {
if (tag->type == TSDB_DATA_TYPE_BINARY || tag->type == TSDB_DATA_TYPE_VARBINARY) {
tools_cJSON_AddStringToObject(tagObj, "value", buf);
tools_cJSON_AddStringToObject(tagObj, "type", "binary");
} else {
Expand Down Expand Up @@ -2040,6 +2049,7 @@ void generateSmlJsonValues(
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *buf = (char *)benchCalloc(col->length + 1, 1, false);
rand_string(buf, col->length, g_arguments->chinese);
Expand Down Expand Up @@ -2082,6 +2092,7 @@ void generateSmlJsonCols(tools_cJSON *array, tools_cJSON *tag,
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *buf = (char *)benchCalloc(col->length + 1, 1, false);
rand_string(buf, col->length, g_arguments->chinese);
Expand Down Expand Up @@ -2139,10 +2150,11 @@ void generateSmlTaosJsonCols(tools_cJSON *array, tools_cJSON *tag,
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR: {
char *buf = (char *)benchCalloc(col->length + 1, 1, false);
rand_string(buf, col->length, g_arguments->chinese);
if (col->type == TSDB_DATA_TYPE_BINARY) {
if (col->type == TSDB_DATA_TYPE_BINARY || col->type == TSDB_DATA_TYPE_VARBINARY) {
tools_cJSON_AddStringToObject(value, "value", buf);
tools_cJSON_AddStringToObject(value, "type", "binary");
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/benchDataMix.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ uint32_t dataGenByField(Field* fd, char* pstr, uint32_t len, char* prefix, int64
// binary nchar
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
format = ",\'%s\'";
tmpStr(val, 0, fd, *k);
break;
Expand Down Expand Up @@ -203,6 +204,7 @@ uint32_t dataGenByCalcTs(Field* fd, char* pstr, uint32_t len, int64_t ts) {
break;
// binary nchar
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_VARBINARY:
case TSDB_DATA_TYPE_NCHAR:
sprintf(val, "%" PRId64, ts);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/benchUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,8 @@ int convertStringToDatatype(char *type, int length) {
return TSDB_DATA_TYPE_JSON;
} else if (0 == strcasecmp(type, "varchar")) {
return TSDB_DATA_TYPE_BINARY;
} else if (0 == strcasecmp(type, "varbinary")) {
return TSDB_DATA_TYPE_VARBINARY;
} else {
errorPrint("unknown data type: %s\n", type);
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -1039,6 +1041,8 @@ int convertStringToDatatype(char *type, int length) {
return TSDB_DATA_TYPE_JSON;
} else if (0 == strncasecmp(type, "varchar", length)) {
return TSDB_DATA_TYPE_BINARY;
} else if (0 == strcnasecmp(type, "varbinary"), length) {
return TSDB_DATA_TYPE_VARBINARY;
} else {
errorPrint("unknown data type: %s\n", type);
exit(EXIT_FAILURE);
Expand Down

0 comments on commit 50a1074

Please sign in to comment.