Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
2c0a7e3
Init
anlowee Aug 8, 2025
91b499c
Fix the bug of negative small standard decimal; formalize the unit test
anlowee Aug 8, 2025
41eee1a
Add a new NodeType FormattedFloat, and a new config option retain-flo…
anlowee Aug 8, 2025
1a3ef60
Add unit test for FormattedFloat search
anlowee Aug 8, 2025
e4bca46
Add the unit test for rounded cases
anlowee Aug 8, 2025
1c2d47e
Fix a bug that when mantissa greater than 9 or is 0 when it is a non-…
anlowee Aug 8, 2025
32a5375
WIP
anlowee Aug 8, 2025
f6f58be
Finish the doc
anlowee Aug 8, 2025
6bc94cc
Add doc strings
anlowee Aug 8, 2025
8724e11
Fix a bug that significant digits can be negative after refactoring; …
anlowee Aug 8, 2025
1f33f98
Merge branch 'main' into v0.4.0-dev-retain-float-format
kirkrodrigues Aug 11, 2025
15e4346
clp-json: Change clp-s compression task to retain float format.
kirkrodrigues Aug 11, 2025
e5717ef
Wrap some inline comments to 100 chars
anlowee Aug 11, 2025
a4cbd89
Merge branch 'v0.4.0-dev-retain-float-format' of github.com:y-scope/c…
anlowee Aug 11, 2025
30c9b08
Merge branch 'main' into xwei/formatted-double
anlowee Aug 12, 2025
c56275e
Address coderabbitai comments
anlowee Aug 13, 2025
0090052
Merge branch 'xwei/formatted-double' of github.com:anlowee/clp into x…
anlowee Aug 13, 2025
38d5ae4
Address coderaddbitai comments
anlowee Aug 13, 2025
87a131f
Merge branch 'main' into xwei/formatted-double
anlowee Aug 13, 2025
287b43e
Move FormattedFloat before Unknown
anlowee Aug 13, 2025
283ce61
Address coderabbitai comments
anlowee Aug 13, 2025
b0d083d
Address coderabbitai comments
anlowee Aug 13, 2025
3e18f00
Address coderabbitai comments
anlowee Aug 13, 2025
bee4fca
Merge branch 'main' into xwei/formatted-double
anlowee Aug 13, 2025
71f2fb6
Adderss coderabbitai comments
anlowee Aug 13, 2025
e6ac492
Merge branch 'main' into xwei/formatted-double
anlowee Aug 13, 2025
42347c1
Merge branch 'main' into xwei/formatted-double
anlowee Aug 13, 2025
284027c
Merge branch 'main' into xwei/formatted-double
anlowee Aug 14, 2025
3870058
Merge branch 'main' into xwei/formatted-double
anlowee Aug 19, 2025
eff80ce
Merge branch 'main' into xwei/formatted-double
anlowee Aug 20, 2025
03506bc
Merge branch 'main' into xwei/formatted-double
anlowee Aug 22, 2025
4da57f3
Address part of comments
anlowee Aug 22, 2025
e8db268
Merge branch 'main' into xwei/formatted-double
anlowee Aug 22, 2025
5a385c6
Fix bug
anlowee Aug 29, 2025
c43884d
Move whitespace trimming into JsonParser to simplify extracting float…
gibber9809 Sep 2, 2025
b6b364a
Merge remote-tracking branch 'upstream/main' into xwei/formatted-double
gibber9809 Sep 2, 2025
e72ea13
Fix format
gibber9809 Sep 2, 2025
c0982e7
Move float format encoding logic into dedicated function
gibber9809 Sep 2, 2025
464f3b6
Remove remaining asserts in get_float_encoding
gibber9809 Sep 3, 2025
5425f84
Move float format restoration into FloatFormatEncoding
gibber9809 Sep 4, 2025
cfc3740
Explicitly set locale when marshalling floats per rabbit suggestion
gibber9809 Sep 5, 2025
98e0390
Clean up some bithacks; Fix bug introduced when moving floating point…
gibber9809 Sep 5, 2025
b5c1987
More cleanup in float formatting
gibber9809 Sep 5, 2025
091a3fc
Clean up more bithacks
gibber9809 Sep 5, 2025
731bf83
Add support for retaining up to 17 decimal digits; Update tests by in…
gibber9809 Sep 5, 2025
1d3fd9f
Get rid of remaining assert statements and instead return error codes
gibber9809 Sep 5, 2025
bf9cfb0
Add the beginnings of fuzzing tests for floating point formatting and…
gibber9809 Sep 8, 2025
18e5aaf
Extend fuzzing tests to cover a wide variety of cases.
gibber9809 Sep 9, 2025
af19cc6
Remove unnecessary generate statement in float search tests.
gibber9809 Sep 9, 2025
ab38a34
Define float_format_t type
gibber9809 Sep 9, 2025
73da7f3
Remove dedicated namespace for float formatting
gibber9809 Sep 9, 2025
fcea117
Move float format parsing from column writer to json parser
gibber9809 Sep 9, 2025
7ed2c91
Add support for dictionary encoding floating point numbers.
gibber9809 Sep 9, 2025
bf9b6cb
Fix cmake scripts
gibber9809 Sep 9, 2025
0197735
Return protocol_not_supported for more unsupported cases in get_float…
gibber9809 Sep 9, 2025
c1bf459
Check for even more unsupported cases in get_float_format
gibber9809 Sep 9, 2025
eb9a711
Properly handle zeroes and add explicit tests for zeroes.
gibber9809 Sep 9, 2025
ef79776
Merge remote-tracking branch 'upstream/main' into xwei/formatted-double
gibber9809 Sep 9, 2025
05fd52c
Add missing header
gibber9809 Sep 9, 2025
1c2a209
Remove now-unused test results file.
gibber9809 Sep 10, 2025
d4ef78b
Remove unnecessary newlines in test log files.
gibber9809 Sep 10, 2025
86ed676
Explicilty check that round trips for formatted floats will be succes…
gibber9809 Sep 10, 2025
c1b2960
Remove integer test cases from floating point test.
gibber9809 Sep 10, 2025
c38d22a
Fix edge case where scientific zeros with one digit 0e0 weren't encod…
gibber9809 Sep 10, 2025
0d4b607
Verify that floats are encoded as the expected type in end to end tests
gibber9809 Sep 10, 2025
0e15df7
Add tests for non-754 floats
gibber9809 Sep 10, 2025
6813e1e
Merge remote-tracking branch 'upstream/main' into xwei/formatted-double
gibber9809 Sep 10, 2025
200a320
Update design-retain-float-format.md doc
gibber9809 Sep 10, 2025
dafb471
Remove limitations in user-docs.
gibber9809 Sep 10, 2025
f9725db
Update description of retain-float-format command line argument
gibber9809 Sep 10, 2025
7c0d698
Revert docs changes since they have been split off into PR #1298
gibber9809 Sep 10, 2025
a2a31b0
Address rabbit comment
gibber9809 Sep 10, 2025
b997d17
Remove unused constant
gibber9809 Sep 10, 2025
b8e2d50
Apply another rabbit suggestion.
gibber9809 Sep 10, 2025
2f70218
Fix build issue
gibber9809 Sep 11, 2025
3894a4d
Add test cases for max and min subnormal float roundtrip
gibber9809 Sep 11, 2025
b37df69
Rename test_rounded_formatted_float.jsonl to test_invalid_formatted_f…
gibber9809 Sep 11, 2025
89e9a1f
Address review comments
gibber9809 Sep 11, 2025
903e6c2
Apply suggestions from code review
gibber9809 Sep 11, 2025
46983ae
Explicitly check that exponent digits are zero for zero valued numbers
gibber9809 Sep 11, 2025
0aca1e2
Add suggested test cases
gibber9809 Sep 11, 2025
7da0c1d
Update components/core/tests/test_log_files/test_invalid_formatted_fl…
gibber9809 Sep 11, 2025
5fbdd07
Update components/core/src/clp_s/ColumnWriter.cpp
gibber9809 Sep 11, 2025
cda2121
Merge branch 'main' into xwei/formatted-double
gibber9809 Sep 11, 2025
f6e1024
Merge branch 'main' into xwei/formatted-double
anlowee Sep 12, 2025
2f25beb
Bump patch version
gibber9809 Sep 15, 2025
66a7e8e
Merge remote-tracking branch 'upstream/main' into xwei/formatted-double
gibber9809 Sep 15, 2025
1504898
Merge branch 'main' into xwei/formatted-double
anlowee Sep 16, 2025
c0b7e84
Merge remote-tracking branch 'upstream/main' into xwei/formatted-double
gibber9809 Sep 18, 2025
c0d6f4c
Merge branch 'main' into xwei/formatted-double
anlowee Sep 19, 2025
29fcbf2
Merge branch 'main' into xwei/formatted-double
anlowee Sep 22, 2025
777f126
Fix build issues after merge
gibber9809 Sep 22, 2025
bb46862
Merge branch 'main' into xwei/formatted-double
gibber9809 Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/core/src/clp_s/ArchiveReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ BaseColumnReader* ArchiveReader::append_reader_column(SchemaReader& reader, int3
case NodeType::Float:
column_reader = new FloatColumnReader(column_id);
break;
case NodeType::FormattedFloat:
column_reader = new FormattedFloatColumnReader(column_id);
break;
case NodeType::ClpString:
column_reader = new ClpStringColumnReader(column_id, m_var_dict, m_log_dict);
break;
Expand Down Expand Up @@ -247,6 +250,9 @@ void ArchiveReader::append_unordered_reader_columns(
case NodeType::Float:
column_reader = new FloatColumnReader(column_id);
break;
case NodeType::FormattedFloat:
column_reader = new FormattedFloatColumnReader(column_id);
break;
case NodeType::ClpString:
Comment thread
gibber9809 marked this conversation as resolved.
Resolved
column_reader = new ClpStringColumnReader(column_id, m_var_dict, m_log_dict);
break;
Expand Down
3 changes: 3 additions & 0 deletions components/core/src/clp_s/ArchiveWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ void ArchiveWriter::initialize_schema_writer(SchemaWriter* writer, Schema const&
case NodeType::Float:
writer->append_column(new FloatColumnWriter(id));
break;
case NodeType::FormattedFloat:
writer->append_column(new FormattedFloatColumnWriter(id));
break;
Comment thread
anlowee marked this conversation as resolved.
Resolved
case NodeType::ClpString:
writer->append_column(new ClpStringColumnWriter(id, m_var_dict, m_log_dict));
break;
Expand Down
159 changes: 159 additions & 0 deletions components/core/src/clp_s/ColumnReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ void FloatColumnReader::load(BufferViewReader& reader, uint64_t num_messages) {
m_values = reader.read_unaligned_span<double>(num_messages);
}

void FormattedFloatColumnReader::load(BufferViewReader& reader, uint64_t num_messages) {
m_values = reader.read_unaligned_span<double>(num_messages);
m_format = reader.read_unaligned_span<uint16_t>(num_messages);
}
Comment thread
anlowee marked this conversation as resolved.
Resolved

void
Int64ColumnReader::extract_string_value_into_buffer(uint64_t cur_message, std::string& buffer) {
buffer.append(std::to_string(m_values[cur_message]));
Expand All @@ -68,6 +73,12 @@ std::variant<int64_t, double, std::string, uint8_t> FloatColumnReader::extract_v
return m_values[cur_message];
}

std::variant<int64_t, double, std::string, uint8_t> FormattedFloatColumnReader::extract_value(
uint64_t cur_message
) {
return m_values[cur_message];
}

void BooleanColumnReader::load(BufferViewReader& reader, uint64_t num_messages) {
m_values = reader.read_unaligned_span<uint8_t>(num_messages);
}
Expand All @@ -77,6 +88,154 @@ FloatColumnReader::extract_string_value_into_buffer(uint64_t cur_message, std::s
buffer.append(std::to_string(m_values[cur_message]));
}

void FormattedFloatColumnReader::extract_string_value_into_buffer(
uint64_t cur_message,
std::string& buffer
) {
buffer.append(restore_format(cur_message));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Optional: avoid intermediate allocation in string extraction

buffer.append(restore_format(...)) creates a temporary. Consider an overload that formats directly into buffer to shave an extra allocation/copy on hot paths.

🤖 Prompt for AI Agents
In components/core/src/clp_s/ColumnReader.cpp around lines 91 to 96, the call
buffer.append(restore_format(cur_message)) creates a temporary string; change
the API/use an overload so formatting writes directly into the provided buffer
to avoid the extra allocation/copy — either add a restore_format(uint64_t,
std::string&) (or restore_format_to_buffer) that appends formatted text into
buffer and call that here, or refactor restore_format to accept an output string
reference and update its implementations accordingly; keep semantics identical
and ensure thread-safety and unit tests are updated if needed.


std::string FormattedFloatColumnReader::restore_format(uint64_t cur_message) {
std::ostringstream oss;
uint16_t const significant_digits
= (m_format[cur_message] >> float_format_encoding::cSignificantDigitsPos & 0x0F) + 1;
oss << std::scientific << std::setprecision(significant_digits - 1);
if (m_format[cur_message] & (1 << float_format_encoding::cScientificExponentNotePos)) {
if (m_format[cur_message] & (1 << (float_format_encoding::cScientificExponentNotePos + 1)))
{
oss << std::uppercase;
}
oss << m_values[cur_message];
auto formatted_double_str = oss.str();
auto const exp_pos = formatted_double_str.find_first_of("Ee");
char const maybe_sign = formatted_double_str[exp_pos + 1];
uint16_t const exp_digits
= (m_format[cur_message] >> float_format_encoding::cScientificExponentDigitsPos
& 0x03)
+ 1;
if (0b00 << float_format_encoding::cScientificExponentSignPos
== (m_format[cur_message] & 0b11 << float_format_encoding::cScientificExponentSignPos))
{
if ('+' == maybe_sign || '-' == maybe_sign) {
formatted_double_str.erase(exp_pos + 1, 1);
}
if (exp_digits < (formatted_double_str.length() - exp_pos - 1)) {
formatted_double_str = trim_leading_zeros(
formatted_double_str,
exp_pos + 1,
formatted_double_str.length() - exp_pos - 1 - exp_digits
);
} else {
formatted_double_str.insert(
exp_pos + 1,
exp_digits - (formatted_double_str.length() - exp_pos - 1),
'0'
);
}
} else {
if (exp_digits < (formatted_double_str.length() - exp_pos - 2)) {
formatted_double_str = trim_leading_zeros(
formatted_double_str,
exp_pos + 2,
formatted_double_str.length() - exp_pos - 2 - exp_digits
);
} else {
formatted_double_str.insert(
exp_pos + 2,
exp_digits - (formatted_double_str.length() - exp_pos - 2),
'0'
);
}
if (0b01 << float_format_encoding::cScientificExponentSignPos
== (m_format[cur_message]
& 0b11 << float_format_encoding::cScientificExponentSignPos))
{
if (std::isdigit(maybe_sign)) {
formatted_double_str.insert(exp_pos + 1, "+");
} else {
formatted_double_str[exp_pos + 1] = '+';
}
} else if (0b10 << float_format_encoding::cScientificExponentSignPos
== (m_format[cur_message]
& 0b11 << float_format_encoding::cScientificExponentSignPos))
{
if (std::isdigit(maybe_sign)) {
formatted_double_str.insert(exp_pos + 1, "-");
} else {
formatted_double_str[exp_pos + 1] = '-';
}
}
}

return formatted_double_str;
}

// Convert the scientific notation to the standard decimal
oss << m_values[cur_message];
return scientific_to_decimal(oss.str());
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

std::string FormattedFloatColumnReader::trim_leading_zeros(
std::string_view scientific_notation,
size_t start,
size_t number_of_zeros_to_trim
) {
auto sci_str = std::string(scientific_notation);
size_t actual_number_of_zeros_to_trim{0};
for (size_t i{start}; i < start + number_of_zeros_to_trim; ++i) {
if ('0' == sci_str[i]) {
actual_number_of_zeros_to_trim++;
} else {
break;
}
}
sci_str.erase(start, actual_number_of_zeros_to_trim);
return sci_str;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

std::string FormattedFloatColumnReader::scientific_to_decimal(
std::string_view scientific_notation
) {
auto sci_str = std::string(scientific_notation);
bool isNegative = false;
if (false == std::isdigit(sci_str[0])) {
isNegative = true;
sci_str.erase(0, 1);
}
size_t const exp_pos = sci_str.find_first_of("e");
assert(std::string::npos != exp_pos);

// Split into mantissa and exponent parts
std::string mantissa_str = sci_str.substr(0, exp_pos);
int const exponent = std::stoi(sci_str.substr(exp_pos + 1));

// Remove the decimal point from the mantissa
size_t const dot_pos = mantissa_str.find('.');
std::string digits;
if (dot_pos != std::string::npos) {
digits = mantissa_str.substr(0, dot_pos) + mantissa_str.substr(dot_pos + 1);
} else {
digits = mantissa_str;
}

// Adjust position of decimal point based on exponent
int const decimal_pos = static_cast<int>(dot_pos) + exponent;

std::string result{""};
if (isNegative) {
result = "-";
}
if (decimal_pos <= 0) {
result += "0." + std::string(-decimal_pos, '0') + digits;
} else if (decimal_pos < static_cast<int>(digits.size())) {
result += digits.substr(0, decimal_pos) + "." + digits.substr(decimal_pos);
} else {
result += digits + std::string(decimal_pos - digits.size(), '0');
}

return result;
}
Comment thread
anlowee marked this conversation as resolved.
Resolved
Comment thread
anlowee marked this conversation as resolved.
Resolved

std::variant<int64_t, double, std::string, uint8_t> BooleanColumnReader::extract_value(
uint64_t cur_message
) {
Expand Down
60 changes: 60 additions & 0 deletions components/core/src/clp_s/ColumnReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,66 @@ class FloatColumnReader : public BaseColumnReader {
UnalignedMemSpan<double> m_values;
};

class FormattedFloatColumnReader : public BaseColumnReader {
public:
// Constructor
explicit FormattedFloatColumnReader(int32_t id) : BaseColumnReader(id) {}

// Destructor
~FormattedFloatColumnReader() override = default;

// Methods inherited from BaseColumnReader
void load(BufferViewReader& reader, uint64_t num_messages) override;

NodeType get_type() override { return NodeType::FormattedFloat; }

std::variant<int64_t, double, std::string, uint8_t> extract_value(
uint64_t cur_message
) override;

void extract_string_value_into_buffer(uint64_t cur_message, std::string& buffer) override;

/**
* Decodes the format information and generates the string of the stored double value with the
* decoded format.
*
* @param cur_message
* @return The double value string formatted by the format information.
*/
std::string restore_format(uint64_t cur_message);

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
private:
UnalignedMemSpan<double> m_values;
UnalignedMemSpan<uint16_t> m_format;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UnalignedMemSpan<uint16_t> m_format;
UnalignedMemSpan<uint16_t> m_formats;


Comment thread
anlowee marked this conversation as resolved.
Resolved
/**
* Trims the leading zeros until the number of exponent digits match the value stored in the
* format. However, if it encounters non-zero digit when trimming, the trim will be aborted to
* avoid incorrect double value string.
*
* @param scientific_notation The scientific notation string generated by std::scientific.
* @param start The start position of trimming. It could be either right after the exponent
* note (E or e), or the second char after the exponent note if the exponent has a sign.
* @param number_of_zeros_to_trim The difference between current number of exponent digits and
* the target value stored in the format.
* @return The scientific notation string with the exponent being trimmed leading zeros.
*/
static std::string trim_leading_zeros(
std::string_view scientific_notation,
size_t start,
size_t number_of_zeros_to_trim
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

/**
* Convert the scientific notation string to a double value string formatted by the encoded
* format information.
*
* @param scientific_notation The scientific notation string generated by std::scientific.
* @return The double value string formatted by the format information.
*/
static std::string scientific_to_decimal(std::string_view scientific_notation);
};
Comment thread
anlowee marked this conversation as resolved.
Resolved

class BooleanColumnReader : public BaseColumnReader {
public:
// Constructor
Expand Down
88 changes: 88 additions & 0 deletions components/core/src/clp_s/ColumnWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,94 @@ void FloatColumnWriter::store(ZstdCompressor& compressor) {
compressor.write(reinterpret_cast<char const*>(m_values.data()), size);
}

size_t FormattedFloatColumnWriter::add_value(ParsedMessage::variable_t& value) {
Comment thread
anlowee marked this conversation as resolved.
Resolved
auto float_str = std::get<std::string>(value);

// Trim the raw string
float_str.erase(
Comment thread
anlowee marked this conversation as resolved.
Resolved
std::remove_if(
float_str.begin(),
float_str.end(),
[](char c) {
return !std::isdigit(static_cast<unsigned char>(c)) && '.' != c && '+' != c
&& '-' != c && 'E' != c && 'e' != c;
}
),
float_str.end()
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// If the raw JSON token is an illegal double number then here will throw exception
m_values.push_back(std::stod(float_str));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine as defensive programming, but just to confirm this shouldn't ever throw given the way we're currently parsing number values right? I would think that if simdjson claims something is a double it is guaranteed to be valid, but maybe that's not right.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true


Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
auto const dot_pos = float_str.find('.');
uint16_t format{0};

// Check whether it is the scientific; if so, if the exponent is E or e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Check whether it is the scientific; if so, if the exponent is E or e
// Check whether it is scientific; if so, whether the exponent is E or e

size_t exp_pos = float_str.find_first_of("Ee");
if (std::string::npos != exp_pos) {
format |= 1 << float_format_encoding::cScientificExponentNotePos;
format |= ('E' == float_str[exp_pos])
<< (float_format_encoding::cScientificExponentNotePos + 1);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

// Check whether there is a sign for the exponent
if ('+' == float_str[exp_pos + 1]) {
format |= 1 << float_format_encoding::cScientificExponentSignPos;
} else if ('-' == float_str[exp_pos + 1]) {
format |= 1 << (float_format_encoding::cScientificExponentSignPos + 1);
}

// Set the number of exponent digits
int exp_digits = float_str.length() - exp_pos - 1;
if (false == std::isdigit(float_str[exp_pos + 1])) {
exp_digits--;
}
format |= (static_cast<uint16_t>(std::min(exp_digits - 1, 3)) & 0x03)
<< float_format_encoding::cScientificExponentDigitsPos;
Comment thread
anlowee marked this conversation as resolved.
Resolved
} else {
exp_pos = float_str.length();
}

// According to the JSON grammar, there is no leading zeros for the integer part of a number,
// so we can check whether the first or the second (if the there is a sign) digit is 0 to know
// if the first non-zero number is in integer part.
size_t first_non_zero_frac_digit_pos = std::isdigit(float_str[0]) ? 0 : 1;
if (std::isdigit(float_str[0]) && '0' != float_str[0]) {
first_non_zero_frac_digit_pos = 0;
} else if (std::isdigit(float_str[1]) && '0' != float_str[1]) {
first_non_zero_frac_digit_pos = 1;
} else if (std::string::npos != dot_pos) {
for (size_t i = dot_pos + 1; i < float_str.length(); ++i) {
if (false == std::isdigit(float_str[i])) {
break;
} else if ('0' != float_str[i]) {
first_non_zero_frac_digit_pos = i;
break;
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

int significant_digits = exp_pos - first_non_zero_frac_digit_pos;
if (std::string::npos != dot_pos && first_non_zero_frac_digit_pos < dot_pos) {
significant_digits--;
}
assert(significant_digits > 0);
uint16_t const compressed_significant_digits
= static_cast<uint16_t>(std::min(significant_digits - 1, 15)) & 0x0F;

format |= compressed_significant_digits << float_format_encoding::cSignificantDigitsPos;

m_format.push_back(format);
return sizeof(double) + sizeof(uint16_t);
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
anlowee marked this conversation as resolved.
Resolved

void FormattedFloatColumnWriter::store(ZstdCompressor& compressor) {
assert(m_format.size() == m_values.size());
auto const values_size = m_values.size() * sizeof(double);
auto const format_size = m_format.size() * sizeof(uint16_t);
compressor.write(reinterpret_cast<char const*>(m_values.data()), values_size);
compressor.write(reinterpret_cast<char const*>(m_format.data()), format_size);
}

size_t BooleanColumnWriter::add_value(ParsedMessage::variable_t& value) {
m_values.push_back(std::get<bool>(value) ? 1 : 0);
return sizeof(uint8_t);
Expand Down
Loading