Skip to content

functions: add char function #7486

Merged
alexey-milovidov merged 6 commits intoClickHouse:masterfrom
sundy-li:char_function
Nov 4, 2019
Merged

functions: add char function #7486
alexey-milovidov merged 6 commits intoClickHouse:masterfrom
sundy-li:char_function

Conversation

@sundy-li
Copy link
Contributor

@sundy-li sundy-li commented Oct 25, 2019

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

For changelog. Remove if this is non-significant change.

Category (leave one):

  • New Feature

Short description (up to few sentences):

char function like mysql. But Behavior is not exactly the same.

Our users who used MySQL a lot said to me they really need it in ClickHouse, so I create this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Unneeded.

Copy link
Member

@alexey-milovidov alexey-milovidov Oct 25, 2019

Choose a reason for hiding this comment

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

It isn't an "IP coding function".
Let's move to another test file.

Copy link
Member

Choose a reason for hiding this comment

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

Does it really have the same behaviour? What about numbers out of ASCII range?

Copy link
Contributor Author

@sundy-li sundy-li Oct 26, 2019

Choose a reason for hiding this comment

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

I gave up implementing the same Behavior as mysql when number out of ASCII range.
It could return multiply characters, I think it's unnecessary and I don't know the internal implementation.

mysql> select char(2221111111111);
+---------------------+
| char(2221111111111) |
+---------------------+
| $���                   |
+---------------------+
1 row in set (0.00 sec)

So I just took the first byte. It's easy to make it done by Column and easy to know the results.

Copy link
Member

Choose a reason for hiding this comment

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

Virtual call in a loop.

Copy link
Member

@alexey-milovidov alexey-milovidov Oct 25, 2019

Choose a reason for hiding this comment

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

  • size()

Copy link
Member

Choose a reason for hiding this comment

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

Style: ++row instead of row ++.

Copy link
Member

Choose a reason for hiding this comment

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

Double whitespace.

Copy link
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

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

.

@zhang2014
Copy link
Contributor

#7498 (comment)

Undo cn documents(Need rebase, because we need clear the commit record), or keep them synchronized.

@sundy-li sundy-li changed the title functions: add char function as mysql behavior functions: add char function Oct 28, 2019
# Encoding functions

## char
Accepts multiple arguments of `Number` types. Returns a string, each char of the results corresponds to the ascii character of the input numbers. It'll cast the first byte from the number, if the byte overflows the range of ascii(which is 127), it returns an unrecognized character(�).
Copy link
Member

Choose a reason for hiding this comment

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

We can construct UTF-8 string with this function. It's not limited for ASCII. I will test...


for (size_t row = 0; row < rows; ++row)
{
out_vec[row * size_per_row + column_idx] = static_cast<char>(src_data_concrete->getInt(row));
Copy link
Member

Choose a reason for hiding this comment

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

Ok. BTW, it's in question what variant of loop is faster - this one or permuted.

@alexey-milovidov alexey-milovidov merged commit 7d2a16e into ClickHouse:master Nov 4, 2019
@CurtizJ CurtizJ added the pr-feature Pull request with new product feature label Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants