This is an automated email from the ASF dual-hosted git repository. zhaoc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new ccc3412 Fix bug: Error of exporting double type data to hdfs (#2924) (#2925) ccc3412 is described below commit ccc3412f13a05ad945d37fd2ac6645c1e2161a98 Author: wutiangan <wutian...@gmail.com> AuthorDate: Thu Feb 20 21:06:50 2020 +0800 Fix bug: Error of exporting double type data to hdfs (#2924) (#2925) --- be/src/runtime/export_sink.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/be/src/runtime/export_sink.cpp b/be/src/runtime/export_sink.cpp index aaf288f..cf5c4ff 100644 --- a/be/src/runtime/export_sink.cpp +++ b/be/src/runtime/export_sink.cpp @@ -141,12 +141,29 @@ Status ExportSink::gen_row_buffer(TupleRow* row, std::stringstream* ss) { case TYPE_LARGEINT: (*ss) << reinterpret_cast<PackedInt128*>(item)->value; break; - case TYPE_FLOAT: - (*ss) << *static_cast<float*>(item); + case TYPE_FLOAT: { + char buffer[MAX_FLOAT_STR_LENGTH + 2]; + float float_value = *static_cast<float*>(item); + buffer[0] = '\0'; + int length = FloatToBuffer(float_value, MAX_FLOAT_STR_LENGTH, buffer); + DCHECK(length >= 0) << "gcvt float failed, float value=" << float_value; + (*ss) << buffer; break; - case TYPE_DOUBLE: - (*ss) << *static_cast<double*>(item); + } + case TYPE_DOUBLE: { + // To prevent loss of precision on float and double types, + // they are converted to strings before output. + // For example: For a double value 27361919854.929001, + // the direct output of using std::stringstream is 2.73619e+10, + // and after conversion to a string, it outputs 27361919854.929001 + char buffer[MAX_DOUBLE_STR_LENGTH + 2]; + double double_value = *static_cast<double*>(item); + buffer[0] = '\0'; + int length = DoubleToBuffer(double_value, MAX_DOUBLE_STR_LENGTH, buffer); + DCHECK(length >= 0) << "gcvt double failed, double value=" << double_value; + (*ss) << buffer; break; + } case TYPE_DATE: case TYPE_DATETIME: { char buf[64]; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org