Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native] Refactor Duration::toString and DataSize::toString to use fmt::format #24241

Merged
merged 1 commit into from
Dec 31, 2024

Conversation

anandamideShakyan
Copy link
Contributor

Description

Refactored the Duration::toString and DataSize::toString methods to replace the use of snprintf with fmt::format. This change modernizes the codebase, eliminates the need for manual buffer management, and ensures safer and more readable formatting operations.

Motivation and Context

Refactored to align with modern C++ practices, improving safety, readability, and maintainability. fmt::format eliminates manual buffer management and the risks of buffer overflows inherent in snprintf.

Impact

Simplifies the code, reduces error-prone logic, and aligns with modern C++ standards. The output remains consistent with the original implementation, with minimal performance impact and improved maintainability.

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

@anandamideShakyan anandamideShakyan requested a review from a team as a code owner December 11, 2024 09:52
@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Dec 11, 2024
@prestodb-ci prestodb-ci requested review from a team, czentgr and psnv03 and removed request for a team December 11, 2024 09:52
@anandamideShakyan anandamideShakyan self-assigned this Dec 11, 2024
@aditi-pandit aditi-pandit changed the title Refactor: Review and fix Detect and handle input/output errors [native]: Refactor Duration::toString and DataSize::toString to use fmt::format Dec 11, 2024
Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

sizeof(buffer),
"%.2f%s",
return fmt::format(
"{:-f}{}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Use .2 in the formating here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

sizeof(buffer),
"%f%s",
return fmt::format(
"{:-f}{}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "-" needed ? Think its the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@czentgr suggested me to use {:-f} citing : https://fmt.dev/10.2.0/syntax.html

Copy link
Contributor

Choose a reason for hiding this comment

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

@anandamideShakyan : Agree with the use of {:-f} syntax. As per the examples in https://fmt.dev/10.2.0/syntax.html#format-examples, the leading "-" is not needed. It is the default. So I was suggesting that we can skip that sign.

sizeof(buffer),
"%.2f%s",
return fmt::format(
"{:-f}{}",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "-" needed here ? It is the default.

@aditi-pandit aditi-pandit changed the title [native]: Refactor Duration::toString and DataSize::toString to use fmt::format [native] Refactor Duration::toString and DataSize::toString to use fmt::format Dec 11, 2024
@aditi-pandit
Copy link
Contributor

@anandamideShakyan : Please merge your commits and use the same commit message as the PR title. https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards

@anandamideShakyan anandamideShakyan force-pushed the dev2 branch 2 times, most recently from 2cb3281 to 0377f99 Compare December 20, 2024 13:52
@aditi-pandit
Copy link
Contributor

@anandamideShakyan : Your code has format-check errors https://app.circleci.com/pipelines/github/prestodb/presto/23646/workflows/08edfa15-4ce4-44cb-8cca-003495536fd6/jobs/98777.

Please run make format-fix on the command line in the presto-cpp folder and commit the changes it suggests.

Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

@aditi-pandit aditi-pandit merged commit 65d252c into prestodb:master Dec 31, 2024
67 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from:IBM PR from IBM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants