Skip to content

feat: support the to_binary with format #18525

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 5 commits into
base: main
Choose a base branch
from

Conversation

KKould
Copy link
Member

@KKould KKould commented Aug 13, 2025

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • support function to_bianry with format
    • 'hex'
    • 'base64'
    • 'utf-8'
  • add alias for encode/decode function
    • 'hex_encode' -> to_hex
    • 'hex_decode_binary' -> 'from_hex'
    • 'try_hex_decode_binary' -> 'try_from_hex'
    • 'hex_decode_string' -> 'from_hex' + cast to string
    • 'try_hex_decode_string' -> 'try_from_hex' + cast to string
    • 'base64_encode' -> 'to_base64'
    • 'base64_decode_binary' -> 'from_base64'
    • 'try_base64_decode_binary' -> 'try_from_base64'
    • 'base64_decode_string' -> 'from_base64' + cast to string
    • 'try_base64_decode_string' -> 'try_from_base64' + cast to string

ref: Snowflake Encoding/decoding functions

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

This change is Reviewable

@KKould KKould requested a review from sundy-li August 13, 2025 08:37
@KKould KKould self-assigned this Aug 13, 2025
@github-actions github-actions bot added the pr-feature this PR introduces a new feature to the codebase label Aug 13, 2025
"try_to_binary",
|_, _, _| FunctionDomain::Full,
|val, format, ctx| {
let Some(format) = format.as_scalar() else {
Copy link
Member

Choose a reason for hiding this comment

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

I think the format could be injected via ctx from settings.

Copy link
Member Author

@KKould KKould Aug 14, 2025

Choose a reason for hiding this comment

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

In Snowflake, to_binary can enter the second parameter to dynamically select the format

https://docs.snowflake.com/en/sql-reference/functions/to_binary

@KKould KKould marked this pull request as ready for review August 14, 2025 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants