From 94d056e67fa2dd0e8fc033abf02996916d6183ae Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 13 Jun 2023 18:00:52 +0800 Subject: [PATCH 1/3] fix:uniform output csv format with shell output --- tools/shell/inc/shellInt.h | 2 ++ tools/shell/src/shellEngine.c | 31 +++++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/shell/inc/shellInt.h b/tools/shell/inc/shellInt.h index 6345647e2f..57415f8335 100644 --- a/tools/shell/inc/shellInt.h +++ b/tools/shell/inc/shellInt.h @@ -45,6 +45,8 @@ #define SHELL_MAX_PKG_NUM 1 * 1024 * 1024 #define SHELL_MIN_PKG_NUM 1 #define SHELL_DEF_PKG_NUM 100 +#define SHELL_FLOAT_WIDTH 20 +#define SHELL_DOUBLE_WIDTH 25 typedef struct { char* hist[SHELL_MAX_HISTORY_SIZE]; diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 7b30052659..0967557a80 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -358,22 +358,29 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i taosFprintfFile(pFile, "%" PRIu64, *((uint64_t *)val)); break; case TSDB_DATA_TYPE_FLOAT: + int32_t width = SHELL_FLOAT_WIDTH; if (tsEnableScience) { - taosFprintfFile(pFile, "%e", GET_FLOAT_VAL(val)); + printf("%*e", width, GET_FLOAT_VAL(val)); } else { - taosFprintfFile(pFile, "%.5f", GET_FLOAT_VAL(val)); + n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.5f", width, GET_FLOAT_VAL(val)); + if (n > SHELL_FLOAT_WIDTH) { + printf("%*e", width, GET_FLOAT_VAL(val)); + } else { + printf("%s", buf); + } } break; case TSDB_DATA_TYPE_DOUBLE: + int32_t width = SHELL_DOUBLE_WIDTH; if (tsEnableScience) { - snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9e", 23, GET_DOUBLE_VAL(val)); - taosFprintfFile(pFile, "%s", buf); + snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%.9e", GET_DOUBLE_VAL(val)); + taosFprintfFile(pFile, "%*s", width, buf); } else { - n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", length, GET_DOUBLE_VAL(val)); - if (n > TMAX(25, length)) { - taosFprintfFile(pFile, "%*.15e", length, GET_DOUBLE_VAL(val)); + n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", width, GET_DOUBLE_VAL(val)); + if (n > SHELL_DOUBLE_WIDTH) { + taosFprintfFile(pFile, "%*.15e", width, GET_DOUBLE_VAL(val)); } else { - taosFprintfFile(pFile, "%s", buf); + taosFprintfFile(pFile, "%s", buf); } } break; @@ -607,7 +614,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t printf("%*e", width, GET_FLOAT_VAL(val)); } else { n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.5f", width, GET_FLOAT_VAL(val)); - if (n > TMAX(20, width)) { + if (n > SHELL_FLOAT_WIDTH) { printf("%*e", width, GET_FLOAT_VAL(val)); } else { printf("%s", buf); @@ -620,7 +627,7 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t printf("%*s", width, buf); } else { n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", width, GET_DOUBLE_VAL(val)); - if (n > TMAX(25, width)) { + if (n > SHELL_DOUBLE_WIDTH) { printf("%*.15e", width, GET_DOUBLE_VAL(val)); } else { printf("%s", buf); @@ -757,10 +764,10 @@ int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision) { return TMAX(21, width); // '-9223372036854775807' case TSDB_DATA_TYPE_FLOAT: - return TMAX(20, width); + return TMAX(SHELL_FLOAT_WIDTH, width); case TSDB_DATA_TYPE_DOUBLE: - return TMAX(25, width); + return TMAX(SHELL_DOUBLE_WIDTH, width); case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_GEOMETRY: From e30cdd03de3d08813e1e824f708c9eae2263f656 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 13 Jun 2023 18:03:26 +0800 Subject: [PATCH 2/3] fix:uniform output csv format with shell output1 --- tools/shell/src/shellEngine.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 0967557a80..38d0cca773 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -360,13 +360,13 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i case TSDB_DATA_TYPE_FLOAT: int32_t width = SHELL_FLOAT_WIDTH; if (tsEnableScience) { - printf("%*e", width, GET_FLOAT_VAL(val)); + taosFprintfFile(pFile, "%*e", width, GET_FLOAT_VAL(val)); } else { n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.5f", width, GET_FLOAT_VAL(val)); if (n > SHELL_FLOAT_WIDTH) { - printf("%*e", width, GET_FLOAT_VAL(val)); + taosFprintfFile(pFile, "%*e", width, GET_FLOAT_VAL(val)); } else { - printf("%s", buf); + taosFprintfFile(pFile, "%s", buf); } } break; @@ -378,9 +378,9 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i } else { n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", width, GET_DOUBLE_VAL(val)); if (n > SHELL_DOUBLE_WIDTH) { - taosFprintfFile(pFile, "%*.15e", width, GET_DOUBLE_VAL(val)); + taosFprintfFile(pFile, "%*.15e", width, GET_DOUBLE_VAL(val)); } else { - taosFprintfFile(pFile, "%s", buf); + taosFprintfFile(pFile, "%s", buf); } } break; From 4d3d48d3b77de38957b5a8eee56516101617bb4b Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 13 Jun 2023 18:06:27 +0800 Subject: [PATCH 3/3] fix:uniform output csv format with shell output --- tools/shell/src/shellEngine.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 38d0cca773..865d4680a3 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -326,6 +326,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i char quotationStr[2]; quotationStr[0] = '\"'; quotationStr[1] = 0; + int32_t width; int n; char buf[TSDB_MAX_BYTES_PER_ROW]; @@ -358,7 +359,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i taosFprintfFile(pFile, "%" PRIu64, *((uint64_t *)val)); break; case TSDB_DATA_TYPE_FLOAT: - int32_t width = SHELL_FLOAT_WIDTH; + width = SHELL_FLOAT_WIDTH; if (tsEnableScience) { taosFprintfFile(pFile, "%*e", width, GET_FLOAT_VAL(val)); } else { @@ -371,7 +372,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i } break; case TSDB_DATA_TYPE_DOUBLE: - int32_t width = SHELL_DOUBLE_WIDTH; + width = SHELL_DOUBLE_WIDTH; if (tsEnableScience) { snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%.9e", GET_DOUBLE_VAL(val)); taosFprintfFile(pFile, "%*s", width, buf);