Skip to content

Commit

Permalink
fix the bug that tiflash wrongly add padding for non-binary chars (#2088
Browse files Browse the repository at this point in the history
)
  • Loading branch information
windtalker committed Jun 4, 2021
1 parent 0ed0a07 commit 890c955
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ struct TiDBConvertToString
col_null_map_to = ColumnUInt8::create(size, 0);
vec_null_map_to = &col_null_map_to->getData();
}
bool need_padding = tp.tp() == TiDB::TypeString && tp.flen() > 0 && tp.collate() == TiDB::ITiDBCollator::BINARY;

String padding_string;
if (tp.tp() == TiDB::TypeString && tp.flen() > 0)
if (need_padding)
padding_string.resize(tp.flen(), 0);

const auto & col_with_type_and_name = block.getByPosition(arguments[0]);
Expand Down Expand Up @@ -132,7 +134,7 @@ struct TiDBConvertToString
if (byte_length < org_length)
context.getDAGContext()->handleTruncateError("Data Too Long");
write_buffer.write(reinterpret_cast<const char *>(&(*data_from)[current_offset]), byte_length);
if (tp.tp() == TiDB::TypeString && tp.flen() > 0 && byte_length < static_cast<size_t>(tp.flen()))
if (need_padding && byte_length < static_cast<size_t>(tp.flen()))
write_buffer.write(padding_string.data(), tp.flen() - byte_length);
writeChar(0, write_buffer);
offsets_to[i] = write_buffer.count();
Expand Down Expand Up @@ -162,7 +164,7 @@ struct TiDBConvertToString
if (byte_length < element_write_buffer.count())
context.getDAGContext()->handleTruncateError("Data Too Long");
write_buffer.write(reinterpret_cast<char *>(container_per_element.data()), byte_length);
if (tp.tp() == TiDB::TypeString && tp.flen() > 0 && byte_length < static_cast<size_t>(tp.flen()))
if (need_padding && byte_length < static_cast<size_t>(tp.flen()))
write_buffer.write(padding_string.data(), tp.flen() - byte_length);
writeChar(0, write_buffer);
offsets_to[i] = write_buffer.count();
Expand Down Expand Up @@ -205,7 +207,7 @@ struct TiDBConvertToString
if (byte_length < element_write_buffer.count())
context.getDAGContext()->handleTruncateError("Data Too Long");
write_buffer.write(reinterpret_cast<char *>(container_per_element.data()), byte_length);
if (tp.tp() == TiDB::TypeString && tp.flen() > 0 && byte_length < static_cast<size_t>(tp.flen()))
if (need_padding && byte_length < static_cast<size_t>(tp.flen()))
write_buffer.write(padding_string.data(), tp.flen() - byte_length);
writeChar(0, write_buffer);
offsets_to[i] = write_buffer.count();
Expand Down

0 comments on commit 890c955

Please sign in to comment.