Skip to content

Add conv function #83058

Merged
bharatnc merged 18 commits intoClickHouse:masterfrom
hp77-creator:feature_CH-4633
Oct 12, 2025
Merged

Add conv function #83058
bharatnc merged 18 commits intoClickHouse:masterfrom
hp77-creator:feature_CH-4633

Conversation

@hp77-creator
Copy link
Copy Markdown
Contributor

Add new 'conv' function which provides support of converting numbers between '2-36' into each other,

sample usage include:

SELECT conv('10', 10, 2); -- 1010
SELECT conv('255', 10, 16); -- FF

Many of the decisions like invalid character handling, whitespace handling are inspired from MySQL implementation
and it closes #4633

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

New conv function for converting numbers between bases, currently supports bases from 2-36

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

conv

Converts numbers between different number bases. The function takes a number in one base and converts it to another base, supporting bases from 2 to 36. This function is compatible with MySQL's CONV() function and handles partial invalid inputs by processing valid digits until the first invalid character.

Syntax

conv(number, from_base, to_base)

Arguments

  • number — The number to convert. Can be a string or numeric type. Leading and trailing whitespace is automatically trimmed. String or Number
  • from_base — The source base (2-36). Must be an integer. Integer
  • to_base — The target base (2-36). Must be an integer. Integer

Implementation Details

  • For bases higher than 10, letters A-Z (case insensitive) represent digits 10-35
  • Negative numbers are handled using two's complement representation
  • Invalid characters stop processing at the first invalid digit (left-to-right processing)
  • Leading and trailing whitespace is automatically trimmed
  • Returns empty string for invalid base ranges or completely invalid input

Returned value

  • Returns the string representation of the number in the target base. String

Examples

Query:

SELECT conv('10', 10, 2);

Response:

┌─conv('10', 10, 2)─┐
│ 1010              │
└───────────────────┘

Query:

SELECT conv('FF', 16, 10);

Response:

┌─conv('FF', 16, 10)─┐
│ 255                │
└────────────────────┘

Query:

SELECT conv('123XYZ', 10, 16);

Response:

   ┌─conv('123XYZ', 10, 16)─┐
1. │ 7B                     │
   └────────────────────────┘

Query:

SELECT conv('-1', 10, 16);

Response:

┌─conv('-1', 10, 16)─┐
│ FFFFFFFFFFFFFFFF   │
└────────────────────┘

@bharatnc bharatnc added the can be tested Allows running workflows for external contributors label Jul 2, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Jul 2, 2025

Workflow [PR], commit [0b1e311]

Summary:

job_name test_name status info comment
Stateless tests (amd_tsan, parallel, 2/2) failure
00156_max_execution_speed_sample_merge FAIL
Stress test (amd_tsan) failure
Server died FAIL
Hung check failed, possible deadlock found (see hung_check.log) FAIL
Killed by signal (in clickhouse-server.log) FAIL
Fatal message in clickhouse-server.log (see fatal_messages.txt) FAIL
Killed by signal (output files) FAIL
Found signal in gdb.log FAIL

@clickhouse-gh clickhouse-gh bot added the pr-feature Pull request with new product feature label Jul 2, 2025
@bharatnc bharatnc self-assigned this Jul 2, 2025
@hp77-creator hp77-creator requested a review from bharatnc August 20, 2025 04:32
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 20, 2025
@bharatnc
Copy link
Copy Markdown
Contributor

bharatnc commented Sep 2, 2025

I'll do one final round of review to ensure that everything looks ok and then we can merge.

@hp77-creator
Copy link
Copy Markdown
Contributor Author

sure @bharatnc lmk if there's any changes needed.

@hp77-creator hp77-creator force-pushed the feature_CH-4633 branch 2 times, most recently from 102a2df to 3187f1c Compare September 11, 2025 03:14
@hp77-creator
Copy link
Copy Markdown
Contributor Author

@bharatnc

03096_text_log_format_string_args_not_empty |

is failing now, I didn't do any change related to this? what should I do?

@bharatnc
Copy link
Copy Markdown
Contributor

is failing now, I didn't do any change related to this? what should I do?

Yes, I'm not sure why it fails - I will check.

@Felixoid Felixoid removed the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 26, 2025
@hp77-creator
Copy link
Copy Markdown
Contributor Author

currently these tests fail:
https://github.com/ClickHouse/ClickHouse/actions/runs/18041406470/job/51345778134?pr=83058

https://github.com/ClickHouse/ClickHouse/actions/runs/18041406470/job/51345778282?pr=83058

i will re-trigger the pipeline to see if these fail again, if they do, i will analyze the cause, from the first inference of the logs, it appears like one test failed because it was unable to load AWS credential, other failed on cleanup

so re-triggering these should work

@bharatnc
Copy link
Copy Markdown
Contributor

The test failures not related, no need to re-trigger. Some small fixes suggested, otherwise looks good.

Copy link
Copy Markdown
Contributor

@bharatnc bharatnc left a comment

Choose a reason for hiding this comment

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

Mostly looks good, one comment needs addressing.

Copy link
Copy Markdown
Contributor

@bharatnc bharatnc left a comment

Choose a reason for hiding this comment

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

LGTM, can merge once builds finish.

@hp77-creator
Copy link
Copy Markdown
Contributor Author

@bharatnc
No autogenerated function categories found in src/Functions/conv.cpp
No changes in docs for new feature and no autogenerated function categories found

I added in the comments, do I need to add somewhere else as well to get PR job pass?

@bharatnc
Copy link
Copy Markdown
Contributor

bharatnc commented Oct 6, 2025

I added in the comments, do I need to add somewhere else as well to get PR job pass?

I think it's happening because the String category is currently not autogenerated - only allowed ones are these.

Looks like you might need to add the docs for the new function here in the markdown for string-functions.

@bharatnc
Copy link
Copy Markdown
Contributor

bharatnc commented Oct 7, 2025

Btw, in future, please avoid rebase + force pushes to PR if you want to bring it up to date with master. Instead, do git fetch origin and git merge <origin/master> (adjust origin of master branch accordingly). Otherwise, we are unnecessarily rewriting entire commit history.

@hp77-creator
Copy link
Copy Markdown
Contributor Author

I thought doing a merge would increase a commit, so I did rebase, I will use merge from now on

@hp77-creator
Copy link
Copy Markdown
Contributor Author

@bharatnc since last two commits fast test is failing, it was passing before, I checked in some other PRs, it was failing in that as well:
https://github.com/ClickHouse/ClickHouse/actions/runs/18309278158/job/52134031576
https://github.com/ClickHouse/ClickHouse/actions/runs/18286111233/job/52132792584

one thing to note is that in all the PRs changes are related to some function code, do we need to increase some limit here?

@bharatnc
Copy link
Copy Markdown
Contributor

bharatnc commented Oct 9, 2025

@bharatnc since last two commits fast test is failing, it was passing before, I checked in some other PRs, it was failing in that as well:

02003_memory_limit_in_client doesn't look related, but I'll check.

@bharatnc
Copy link
Copy Markdown
Contributor

Test failures not related. But just in case, let's wait for a fresh set of builds before merging.

@bharatnc
Copy link
Copy Markdown
Contributor

Test failure not related:

@bharatnc bharatnc added this pull request to the merge queue Oct 12, 2025
Merged via the queue into ClickHouse:master with commit 22fded9 Oct 12, 2025
121 of 123 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2025
@hp77-creator
Copy link
Copy Markdown
Contributor Author

Thanks a lot @bharatnc !!

@alexey-milovidov
Copy link
Copy Markdown
Member

alexey-milovidov commented Nov 15, 2025

@bharatnc, please revert or fix: #90115

alexey-milovidov added a commit that referenced this pull request Nov 15, 2025
alexey-milovidov added a commit that referenced this pull request Nov 16, 2025
@alexey-milovidov
Copy link
Copy Markdown
Member

Oh, looks like it's not yours...

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

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

function request CONV(N,from_base,to_base)

6 participants