Visitar URL original
[feature](be) Add printf string formatting by HappenLee · Pull Request #68772 · apache/doris · GitHub
Skip to content

[feature](be) Add printf string formatting - #68772

Open
HappenLee wants to merge 1 commit into
apache:masterfrom
HappenLee:feature/printf-master
Open

HappenLee wants to merge 1 commit into
apache:masterfrom
HappenLee:feature/printf-master

Conversation

@HappenLee

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Related PR: #49210, #49048

Problem Summary:

printf is not registered on master. Its original implementation was merged into branch-c108335-hive-sql in #49210; the corresponding master PR #49048 was closed without merging.

Restore the implementation from commit fcab5d6bf213fca1ddd3e690d94e9ce4b7fa445a and adapt it to the current BE function layout and primitive types. For example, SELECT printf('%d-%s-%.2f', 100, 'test', 3.14) now returns 100-test-3.14.

The function accepts a format string followed by mixed string and numeric arguments. It uses fmt::vsprintf, handles constant and ordinary columns, accepts CHAR/VARCHAR/STRING, propagates NULL, and retains the original Decimal-to-Double coercion. Invalid format strings and unsupported argument types produce an error.

Add BE tests for formatting, constant column combinations and errors, FE tests for binding and type coercion, and regression coverage.

Release note

Add PRINTF(format_string[, args...]) for printf-style string formatting.

Check List (For Author)

  • Test:
    • Regression test: test_printf, generated output with -forceGenOut and then reran comparison; both passed.
    • Unit Test: 7 BE function_string_test.function_printf* tests and 3 FE PrintfTest tests passed.
    • Manual test: ASAN BE/FE build, Checkstyle, clang-tidy, C++ formatting and BE build hygiene checks passed.

Validation used ENABLE_PCH=OFF because the current toolchain reports an incomplete wide::integer instantiation in the existing PCH build. No build environment changes are included in this PR.

  • Behavior changed:

    • Yes. Register the PRINTF scalar function.
  • Does this need documentation?

    • No. PRINTF already has a function reference in the Doris documentation.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#49210, apache#49048

Problem Summary: PRINTF is missing from master. Restore the implementation
merged into the Hive SQL branch and adapt it to the current BE layout,
primitive types and Nereids function parameters. Support mixed string and
numeric arguments, constant columns, CHAR/VARCHAR/STRING and NULL propagation.
Retain Decimal-to-Double coercion and report invalid formats or unsupported
argument types. Add BE, FE and SQL regression tests.

### Release note

Add PRINTF(format_string[, args...]) for printf-style string formatting.

### Check List (For Author)

- Test: Regression test test_printf (output generation and comparison),
  7 BE unit tests, 3 FE unit tests, ASAN BE/FE build, Checkstyle,
  clang-tidy, C++ formatting and build hygiene checks
- Behavior changed: Yes. Register the PRINTF scalar function
- Does this need documentation: No. PRINTF has an existing function reference

(cherry picked from commit fcab5d6)
Co-authored-by: happenlee <happenlee@selectdb.com>
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

HappenLee added a commit to apache/doris-website that referenced this pull request Oct 8, 2026
The website currently documents `PRINTF` for dev, 4.x, and 3.x and
claims support since 3.0.6, while the master implementation is being
introduced in apache/doris#68772. Remove all six English and Chinese
function reference pages and their sidebar, migration-slug, and
last-update entries.

## Validation

- Changed-link gate: passed with no errors; the six page-deletion
notices were reviewed.
- English/Chinese sync gate: passed with no findings.
- Reference and JSON checks: passed; no remaining SQL `PRINTF`
references, document paths, or sidebar entries.
- `git diff --check`: passed.
- Docusaurus content and route loading: passed for dev, 4.x, and 3.x in
both English and Chinese; each locale has 4,582 routes and no `PRINTF`
route. Neighboring function pages and all three sidebars load
successfully.
- Docusaurus English production build: passed for dev, 4.x, and 3.x
(unaffected blog, community, releases, and course plugins excluded).
- Full production build across changed versions and languages: pending
in the PR's Build Check CI.

## Self-review

- Goal: all `PRINTF` SQL function documentation is removed.
- Scope: 13 files, with only the relevant deletions.
- Information architecture: dev, 4.x, and 3.x are updated in both
languages; older versions have no `PRINTF` reference pages.
- Links and navigation: no remaining inbound links or redirect entries
point to the removed pages; removed routes are intentionally retired
without a replacement page.
- Validation: the checks above cover document removal, mirrored
versions/languages, and sidebar integrity.
- Other correctness and usability issues: none found in the changed
content.

## Versions

- [x] dev
- [x] 4.x
- [x] 3.x
- [ ] 2.1 or older (not covered by version/language sync gate)

## Languages

- [x] Chinese
- [x] English

## Docs Checklist

- [x] Checked by AI
- [ ] Test Cases Built (documentation removal; no new SQL examples)
- [x] Updated required version and language counterparts, or explained
why not
- [x] If only one language changed, confirmed whether source/translation
counterparts need sync (both languages updated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants