Skip to content

Add FORMAT_BYTES and FORMAT_NANO_TIME functions#20872

Merged
ti-chi-bot[bot] merged 10 commits intopingcap:masterfrom
dveeden:format_funcs
Jun 17, 2025
Merged

Add FORMAT_BYTES and FORMAT_NANO_TIME functions#20872
ti-chi-bot[bot] merged 10 commits intopingcap:masterfrom
dveeden:format_funcs

Conversation

@dveeden
Copy link
Copy Markdown
Contributor

@dveeden dveeden commented Apr 28, 2025

What is changed, added or deleted? (Required)

Which TiDB version(s) do your changes apply to? (Required)

Tips for choosing the affected version(s):

By default, CHOOSE MASTER ONLY so your changes will be applied to the next TiDB major or minor releases. If your PR involves a product feature behavior change or a compatibility change, CHOOSE THE AFFECTED RELEASE BRANCH(ES) AND MASTER.

For details, see tips for choosing the affected versions.

  • master (the latest development version)
  • v9.0 (TiDB 9.0 versions)
  • v8.5 (TiDB 8.5 versions)
  • v8.4 (TiDB 8.4 versions)
  • v8.3 (TiDB 8.3 versions)
  • v8.1 (TiDB 8.1 versions)
  • v7.5 (TiDB 7.5 versions)
  • v7.1 (TiDB 7.1 versions)
  • v6.5 (TiDB 6.5 versions)
  • v6.1 (TiDB 6.1 versions)
  • v5.4 (TiDB 5.4 versions)

What is the related PR or file link(s)?

  • This PR is translated from:
  • Other reference link(s):

Do your changes match any of the following descriptions?

  • Delete files
  • Change aliases
  • Need modification after applied to another branch
  • Might cause conflicts after applied to another branch

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @dveeden, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request adds two new utility functions to TiDB: FORMAT_BYTES() and FORMAT_NANO_TIME(). These functions format a number of bytes and nanoseconds, respectively, into human-readable strings. The changes include adding the new functions to the functions-and-operators/utility-functions.md documentation file, as well as updating the table of contents in TOC.md and TOC-tidb-cloud.md to include a link to the new utility functions documentation.

Highlights

  • New Functions: Introduces FORMAT_BYTES() to format byte sizes into human-readable strings (e.g., '10.00 MiB').
  • New Functions: Introduces FORMAT_NANO_TIME() to format nanosecond values into human-readable strings (e.g., '1.00 ms').
  • Documentation: Adds a new utility-functions.md file under functions-and-operators/ to document the new functions.
  • Table of Contents: Updates TOC.md and TOC-tidb-cloud.md to include a link to the new Utility Functions documentation.

Changelog

  • TOC-tidb-cloud.md
    • Added 'Utility Functions' to the table of contents, linking to the new documentation page.
  • TOC.md
    • Added 'Utility Functions' to the table of contents, linking to the new documentation page.
  • functions-and-operators/utility-functions.md
    • Created a new documentation page for 'Utility Functions'.
    • Documented the FORMAT_BYTES() function with a description and example.
    • Documented the FORMAT_NANO_TIME() function with a description and example.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ti-chi-bot ti-chi-bot bot added missing-translation-status This PR does not have translation status info. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 28, 2025
@dveeden dveeden requested review from Oreoxmt and hfxsd April 28, 2025 17:17
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds two new utility functions, FORMAT_BYTES and FORMAT_NANO_TIME, to TiDB's documentation. The changes include adding the function documentation and updating the table of contents. Overall, the changes are well-structured and clear.

Merge Readiness

The pull request is well-structured and clear, and the changes seem straightforward. I recommend merging it after addressing the minor suggestions in the review comments. I am unable to approve this pull request, and that users should have others review and approve this code before merging.

@dveeden
Copy link
Copy Markdown
Contributor Author

dveeden commented Apr 28, 2025

Checking the docs against TiDB v8.5.1:

dvaneeden@dve-carbon:~/dev/pingcap/docs/functions-and-operators$ for bi in $(mysql --host 127.0.0.1 --port 4000 -u root -BNe 'show builtins'); do n=$(git grep -li $bi | wc -l); [ $n == 0 ] && echo $bi; done
bitand
bitneg
bitor
bitxor
char_func
default_func
des_decrypt
des_encrypt
format_bytes
format_nano_time
getparam
insert_func
intdiv
isfalse
istrue
json_memberof
leftshift
master_pos_wait
nulleq
old_password
password_func
rightshift
setvar
unaryminus
vec_as_text
vec_cosine_distance
vec_dims
vec_from_text
vec_l1_distance
vec_l2_distance
vec_l2_norm
vec_negative_inner_product
  1. Vector search related things are in ../vector-search/vector-search-functions-and-operators.md. Those are false positives.
  2. Things like bitand are names for operators. Those are also false positives.
  3. password_func should not be in the output, that's an issue, but not on the docs side.
  4. DES functions are deprecated/removed
  5. OLD_PASSWORD() is deprected/removed
  6. MASTER_POS_WAIT() is not implemented, It always returns an error.

So this is a list of things to check:

char_func               - Not intended as function?
default_func            - Not a real function?
format_bytes            - Should be in the docs, This PR
format_nano_time        - Should be in the docs, This PR
getparam                - Prepared statements related?
insert_func             - Not intended as real function?
isfalse                 - Not intended as real function?
istrue                  - Not intended as real function?
json_memberof           - Should be documented?
setvar                  - Unknown

@dveeden
Copy link
Copy Markdown
Contributor Author

dveeden commented Apr 28, 2025

Related: pingcap/tidb#60906

Looks like JSON_MEMBEROF might be related to MEMBER OF (e.g. SELECT 2 MEMBER OF (JSON_ARRAY(1,2,3)) )

@dveeden
Copy link
Copy Markdown
Contributor Author

dveeden commented Apr 29, 2025

Also related: pingcap/tidb#60928

@dveeden dveeden requested review from YangKeao and mjonss June 10, 2025 06:29
Copy link
Copy Markdown
Contributor

@mjonss mjonss left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Jun 10, 2025

@mjonss: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@hfxsd hfxsd self-assigned this Jun 16, 2025
hfxsd and others added 3 commits June 16, 2025 16:33
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jun 16, 2025
@hfxsd hfxsd added translation/doing This PR's assignee is translating this PR. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. and removed missing-translation-status This PR does not have translation status info. labels Jun 16, 2025
@hfxsd hfxsd added translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR. and removed translation/doing This PR's assignee is translating this PR. labels Jun 16, 2025
@hfxsd hfxsd requested review from qiancai and removed request for Oreoxmt June 16, 2025 09:00
Copy link
Copy Markdown
Collaborator

@qiancai qiancai left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 16, 2025
@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Jun 16, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-16 08:35:39.480354497 +0000 UTC m=+87992.203533480: ☑️ agreed by hfxsd.
  • 2025-06-16 09:18:09.853771251 +0000 UTC m=+90542.576950228: ☑️ agreed by qiancai.

Co-authored-by: Grace Cai <qqzczy@126.com>
Co-authored-by: Grace Cai <qqzczy@126.com>
@hfxsd
Copy link
Copy Markdown
Collaborator

hfxsd commented Jun 17, 2025

/approve

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot bot commented Jun 17, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hfxsd

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Jun 17, 2025
@ti-chi-bot ti-chi-bot bot merged commit a14a1c0 into pingcap:master Jun 17, 2025
9 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/docs that referenced this pull request Jun 17, 2025
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Copy Markdown
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #21191.
But this PR has conflicts, please resolve them!

@ti-chi-bot
Copy link
Copy Markdown
Member

In response to a cherrypick label: new pull request created to branch release-8.5: #21192.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-8.5 Should cherry pick this PR to release-8.5 branch. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. translation/done This PR has been translated from English into Chinese and updated to pingcap/docs-cn in a PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants