未验证 提交 aec59f0e 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #10048 from taosdata/feature/TS-822-D

[TS-822]<feature>: optimized print style of data with double type
...@@ -392,14 +392,14 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -392,14 +392,14 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
FILETIME b; // unit is 100ns FILETIME b; // unit is 100ns
ULARGE_INTEGER c; ULARGE_INTEGER c;
SystemTimeToFileTime(&a,&b); SystemTimeToFileTime(&a,&b);
c.LowPart = b.dwLowDateTime; c.LowPart = b.dwLowDateTime;
c.HighPart = b.dwHighDateTime; c.HighPart = b.dwHighDateTime;
c.QuadPart+=tt*10000000; c.QuadPart+=tt*10000000;
b.dwLowDateTime=c.LowPart; b.dwLowDateTime=c.LowPart;
b.dwHighDateTime=c.HighPart; b.dwHighDateTime=c.HighPart;
FileTimeToLocalFileTime(&b,&b); FileTimeToLocalFileTime(&b,&b);
FileTimeToSystemTime(&b,&a); FileTimeToSystemTime(&b,&a);
int pos = sprintf(buf,"%02d-%02d-%02d %02d:%02d:%02d", a.wYear, a.wMonth,a.wDay, a.wHour, a.wMinute, a.wSecond); int pos = sprintf(buf,"%02d-%02d-%02d %02d:%02d:%02d", a.wYear, a.wMonth,a.wDay, a.wHour, a.wMinute, a.wSecond);
if (precision == TSDB_TIME_PRECISION_NANO) { if (precision == TSDB_TIME_PRECISION_NANO) {
sprintf(buf + pos, ".%09d", ms); sprintf(buf + pos, ".%09d", ms);
} else if (precision == TSDB_TIME_PRECISION_MICRO) { } else if (precision == TSDB_TIME_PRECISION_MICRO) {
...@@ -442,6 +442,7 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_ ...@@ -442,6 +442,7 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_
return; return;
} }
int n;
char buf[TSDB_MAX_BYTES_PER_ROW]; char buf[TSDB_MAX_BYTES_PER_ROW];
switch (field->type) { switch (field->type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
...@@ -475,7 +476,12 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_ ...@@ -475,7 +476,12 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_
fprintf(fp, "%.5f", GET_FLOAT_VAL(val)); fprintf(fp, "%.5f", GET_FLOAT_VAL(val));
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
fprintf(fp, "%.9f", GET_DOUBLE_VAL(val)); n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", length, GET_DOUBLE_VAL(val));
if (n > MAX(25, length)) {
fprintf(fp, "%*.15e", length, GET_DOUBLE_VAL(val));
} else {
fprintf(fp, "%s", buf);
}
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
...@@ -631,6 +637,7 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le ...@@ -631,6 +637,7 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
return; return;
} }
int n;
char buf[TSDB_MAX_BYTES_PER_ROW]; char buf[TSDB_MAX_BYTES_PER_ROW];
switch (field->type) { switch (field->type) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
...@@ -664,7 +671,12 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le ...@@ -664,7 +671,12 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
printf("%*.5f", width, GET_FLOAT_VAL(val)); printf("%*.5f", width, GET_FLOAT_VAL(val));
break; break;
case TSDB_DATA_TYPE_DOUBLE: case TSDB_DATA_TYPE_DOUBLE:
printf("%*.9f", width, GET_DOUBLE_VAL(val)); n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.9f", width, GET_DOUBLE_VAL(val));
if (n > MAX(25, width)) {
printf("%*.15e", width, GET_DOUBLE_VAL(val));
} else {
printf("%s", buf);
}
break; break;
case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册