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

Add generate_series function #59390

Merged
merged 36 commits into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f91feb0
Initial working commit
divanik Jan 30, 2024
3f0cfbd
Kek
divanik Feb 3, 2024
623b425
Add feature with the right author name
Feb 6, 2024
145e425
Added Documentation
Feb 7, 2024
03aaeda
Fix bug
Feb 9, 2024
1b2f232
Change documentation
Feb 9, 2024
79f9100
To pull
Feb 9, 2024
c8af01c
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Feb 9, 2024
f7dbcdd
Made refactoring
Feb 9, 2024
696609e
Kek
Feb 10, 2024
3ec9f3c
Check foormattign
Feb 10, 2024
d045698
It seems to work
Feb 10, 2024
789d3c6
Remove bug for mt
Feb 10, 2024
0f84f68
Simplified code
Feb 13, 2024
97aec71
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Feb 14, 2024
8f44201
Preliminary commit
Mar 12, 2024
3c2514b
Correct small issues
Mar 12, 2024
cf639ba
Fix attach bug
Mar 13, 2024
8301910
Correct fast test ande fix perfomance issue
Mar 13, 2024
f63e1b4
Temporarily increase build limit with sanitizers
Mar 14, 2024
9c77aa9
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Mar 14, 2024
27a9309
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Mar 14, 2024
bb5e8f5
Kek
Mar 14, 2024
e57446b
Resolved conflicts
Mar 15, 2024
7d38789
Make generate_series test smaller
Mar 15, 2024
c5d35bb
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Mar 18, 2024
265d917
Remove log debug
Mar 18, 2024
d0ed47e
Return right cmake settings
Mar 18, 2024
3fd5c69
Add docs
Mar 18, 2024
2061fb2
Add alias to doc
Mar 18, 2024
90c4b0a
Add word to aspell-dictg
Mar 18, 2024
24a5954
ASdd documentation
Mar 19, 2024
87e2c09
Correct typo
Mar 19, 2024
8ec2dd3
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Mar 20, 2024
52b2220
Resolved issues
Mar 20, 2024
cc7a418
Merge branch 'master' of github.com:ClickHouse/ClickHouse into divani…
Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/en/sql-reference/table-functions/generate_series.md
@@ -0,0 +1,25 @@
---
slug: /en/sql-reference/table-functions/generate_series
sidebar_position: 146
sidebar_label: generate_series
---

# generate_series
divanik marked this conversation as resolved.
Show resolved Hide resolved

`generate_series(START, STOP)` - Returns a table with the single ‘generate_series’ column (UInt64) that contains integers from start to stop inclusively.

`generate_series(START, STOP, STEP)` - Returns a table with the single ‘generate_series’ column (UInt64) that contains integers from start to stop inclusively with spacing between values given by STEP.

The following queries return tables with the same content but different column names:

``` sql
SELECT * FROM numbers(10, 5);
SELECT * FROM generate_series(10, 14);
```

And the following queries return tables with the same content but different column names (but the second option is more efficient):
divanik marked this conversation as resolved.
Show resolved Hide resolved

``` sql
SELECT * FROM numbers(10, 11) WHERE number % 3 == (10 % 3);
SELECT * FROM generate_series(10, 20, 3) ;
```
29 changes: 29 additions & 0 deletions src/Common/iota.cpp
Expand Up @@ -27,10 +27,39 @@ void iota(T * begin, size_t count, T first_value)
return iotaImpl(begin, count, first_value);
}

MULTITARGET_FUNCTION_AVX2_SSE42(
MULTITARGET_FUNCTION_HEADER(template <iota_supported_types T> void NO_INLINE),
iotaWithStepImpl, MULTITARGET_FUNCTION_BODY((T * begin, size_t count, T first_value, T step) /// NOLINT
{
for (size_t i = 0; i < count; i++)
*(begin + i) = static_cast<T>(first_value + i * step);
})
)

template <iota_supported_types T>
void iota_with_step(T * begin, size_t count, T first_value, T step)
{
#if USE_MULTITARGET_CODE
if (isArchSupported(TargetArch::AVX2))
return iotaWithStepImplAVX2(begin, count, first_value, step);

if (isArchSupported(TargetArch::SSE42))
return iotaWithStepImplSSE42(begin, count, first_value, step);
#endif
return iotaWithStepImpl(begin, count, first_value, step);
}

template void iota(UInt8 * begin, size_t count, UInt8 first_value);
template void iota(UInt32 * begin, size_t count, UInt32 first_value);
template void iota(UInt64 * begin, size_t count, UInt64 first_value);
#if defined(OS_DARWIN)
template void iota(size_t * begin, size_t count, size_t first_value);
#endif

template void iota_with_step(UInt8 * begin, size_t count, UInt8 first_value, UInt8 step);
template void iota_with_step(UInt32 * begin, size_t count, UInt32 first_value, UInt32 step);
template void iota_with_step(UInt64 * begin, size_t count, UInt64 first_value, UInt64 step);
#if defined(OS_DARWIN)
template void iota_with_step(size_t * begin, size_t count, size_t first_value, size_t step);
#endif
}
9 changes: 9 additions & 0 deletions src/Common/iota.h
Expand Up @@ -31,4 +31,13 @@ extern template void iota(UInt64 * begin, size_t count, UInt64 first_value);
#if defined(OS_DARWIN)
extern template void iota(size_t * begin, size_t count, size_t first_value);
#endif

template <iota_supported_types T> void iota_with_step(T * begin, size_t count, T first_value, T step);
divanik marked this conversation as resolved.
Show resolved Hide resolved

extern template void iota_with_step(UInt8 * begin, size_t count, UInt8 first_value, UInt8 step);
extern template void iota_with_step(UInt32 * begin, size_t count, UInt32 first_value, UInt32 step);
extern template void iota_with_step(UInt64 * begin, size_t count, UInt64 first_value, UInt64 step);
#if defined(OS_DARWIN)
extern template void iota_with_step(size_t * begin, size_t count, size_t first_value, size_t step);
#endif
}