Skip to content
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

Format function added #5330

Merged
merged 10 commits into from
May 19, 2019
Merged

Format function added #5330

merged 10 commits into from
May 19, 2019

Conversation

danlark1
Copy link
Contributor

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):
format function added

Detailed description (optional):

Formatting constant pattern with the string listed in the arguments. pattern is a simplified Python format pattern. Format string contains "replacement fields" surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}. Field names can be numbers (starting from zero) or empty (then they are treated as consequence numbers).

SELECT format('{1} {0} {1}', 'World', 'Hello')

┌─format('{1} {0} {1}', 'World', 'Hello')─┐
│ Hello World Hello                       │
└─────────────────────────────────────────┘

SELECT format('{} {}', 'Hello', 'World')

┌─format('{} {}', 'Hello', 'World')─┐
│ Hello World                       │
└───────────────────────────────────┘

It turned out to be faster than concat function


SELECT count(format('Hello {} World {}', URL, URL))
FROM hits_100m_single 
SETTINGS max_threads = 1

┌─count(format('Hello {} World {}', URL, URL))─┐
│                                    100000000 │
└──────────────────────────────────────────────┘

1 rows in set. Elapsed: 6.684 sec. Processed 100.00 million rows, 9.38 GB (14.96 million rows/s., 1.40 GB/s.) 

vla2-5812-1.qyp-seek-6.vla.yp-c.yandex.net :) select count(concat('Hello ', URL, ' World ', URL)) from hits_100m_single settings max_threads=1;

SELECT count(concat('Hello ', URL, ' World ', URL))
FROM hits_100m_single 
SETTINGS max_threads = 1

┌─count(concat('Hello ', URL, ' World ', URL))─┐
│                                    100000000 │
└──────────────────────────────────────────────┘

1 rows in set. Elapsed: 10.607 sec. Processed 100.00 million rows, 9.38 GB (9.43 million rows/s., 883.98 MB/s.)

SELECT sum(concat('Hello ', URL, ' World ', URL) = format('Hello {} World {}', URL, URL))
FROM hits_100m_single 
SETTINGS max_threads = 1

┌─sum(equals(concat('Hello ', URL, ' World ', URL), format('Hello {} World {}', URL, URL)))─┐
│                                                                                 100000000 │
└───────────────────────────────────────────────────────────────────────────────────────────┘ 

@danlark1 danlark1 added can be tested pr-feature Pull request with new product feature labels May 18, 2019
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.

(after adding support for const strings)

@danlark1 danlark1 merged commit 295a4a8 into master May 19, 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.

None yet

2 participants