Skip to content

Add FORMAT_BYTES and FORMAT_NANO_TIME functions #20872

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dveeden
Copy link
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

@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 the missing-translation-status This PR does not have translation status info. label Apr 28, 2025
Copy link

ti-chi-bot bot commented Apr 28, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign qiancai for approval. For more information see the Code Review Process.

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

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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 28, 2025
@dveeden dveeden requested review from hfxsd and Oreoxmt April 28, 2025 17:17
Copy link

@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.


### `FORMAT_BYTES()`

The `FORMAT_BYTES()` function formats a number of bytes as human readable number.

Choose a reason for hiding this comment

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

low

According to the style guide 1, use second person ("you") when addressing users. Consider rephrasing to something like "The FORMAT_BYTES() function formats the number of bytes into a human-readable format for you."

Style Guide References

Suggested change
The `FORMAT_BYTES()` function formats a number of bytes as human readable number.
The `FORMAT_BYTES()` function formats a number of bytes into a human-readable format for you.

Footnotes

  1. Write in second person ("you") when addressing users. (link)

Comment on lines +15 to +17
```sql
SELECT FORMAT_BYTES(10*1024*1024);
```

Choose a reason for hiding this comment

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

low

According to the style guide 1, code snippets should be in backticks (`).

Style Guide References

Suggested change
```sql
SELECT FORMAT_BYTES(10*1024*1024);
```
SELECT FORMAT_BYTES(10*1024*1024);

Footnotes

  1. Code snippets, command names, options, and paths should be in backticks (`). (link)

Comment on lines +19 to +25
```
+----------------------------+
| FORMAT_BYTES(10*1024*1024) |
+----------------------------+
| 10.00 MiB |
+----------------------------+
1 row in set (0.001 sec)

Choose a reason for hiding this comment

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

low

According to the style guide 1, code snippets should be in backticks (`).

Style Guide References

Suggested change
```
+----------------------------+
| FORMAT_BYTES(10*1024*1024) |
+----------------------------+
| 10.00 MiB |
+----------------------------+
1 row in set (0.001 sec)
+----------------------------+
| FORMAT_BYTES(10*1024*1024) |
+----------------------------+
| 10.00 MiB |
+----------------------------+
1 row in set (0.001 sec)

Footnotes

  1. Code snippets, command names, options, and paths should be in backticks (`). (link)


### `FORMAT_NANO_TIME()`

The `FORMAT_NANO_TIME()` function formats a number of nanoseconds as a human readable number.

Choose a reason for hiding this comment

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

low

According to the style guide 1, use second person ("you") when addressing users. Consider rephrasing to something like "The FORMAT_NANO_TIME() function formats the number of nanoseconds into a human-readable format for you."

Style Guide References

Suggested change
The `FORMAT_NANO_TIME()` function formats a number of nanoseconds as a human readable number.
The `FORMAT_NANO_TIME()` function formats a number of nanoseconds into a human-readable format for you.

Footnotes

  1. Write in second person ("you") when addressing users. (link)

Comment on lines +32 to +34
```sql
SELECT FORMAT_NANO_TIME(1000000);
```

Choose a reason for hiding this comment

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

low

According to the style guide 1, code snippets should be in backticks (`).

Style Guide References

Suggested change
```sql
SELECT FORMAT_NANO_TIME(1000000);
```
SELECT FORMAT_NANO_TIME(1000000);

Footnotes

  1. Code snippets, command names, options, and paths should be in backticks (`). (link)

Comment on lines +36 to +42
```
+---------------------------+
| FORMAT_NANO_TIME(1000000) |
+---------------------------+
| 1.00 ms |
+---------------------------+
1 row in set (0.001 sec)

Choose a reason for hiding this comment

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

low

According to the style guide 1, code snippets should be in backticks (`).

Style Guide References

Suggested change
```
+---------------------------+
| FORMAT_NANO_TIME(1000000) |
+---------------------------+
| 1.00 ms |
+---------------------------+
1 row in set (0.001 sec)
+---------------------------+
| FORMAT_NANO_TIME(1000000) |
+---------------------------+
| 1.00 ms |
+---------------------------+
1 row in set (0.001 sec)

Footnotes

  1. Code snippets, command names, options, and paths should be in backticks (`). (link)

@dveeden
Copy link
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
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
Contributor Author

dveeden commented Apr 29, 2025

Also related: pingcap/tidb#60928

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
missing-translation-status This PR does not have translation status info. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant