ClickHouse icon indicating copy to clipboard operation
ClickHouse copied to clipboard

Add `arrayUnion` function

Open rschu1ze opened this issue 11 months ago • 4 comments

Basically arrayDistinct(arrayConcat(arr1, arr2, arr3, ...))

Related function: arrayIntersect

rschu1ze avatar Mar 18 '24 19:03 rschu1ze

Hey @rschu1ze, I'd like to try fixing this issue. Can you assign it to me?

tinfoil-knight avatar Mar 19 '24 11:03 tinfoil-knight

Cool, please go ahead, thanks.

rschu1ze avatar Mar 19 '24 11:03 rschu1ze

@rschu1ze Just wanted to confirm this before I start working to not miss anything.

Initial Plan:

  • Add an arrayUnion.cpp file under src/Functions/array & implement the required function
  • Use the tests/queries/0_stateless/add-test script to generate a .sql & .reference file
  • Add tests in the generated .sql file & then update the reference file with: clickhouse-client --multiquery < 0xxxx_arrayUnion.sql > 0xxxx_arrayUnion.reference
  • Update docs/en/sql-reference/functions/array-functions.md
  • Update utils/check-style/aspell-ignore/en/aspell-dict.txt

tinfoil-knight avatar Mar 23 '24 13:03 tinfoil-knight

@tinfoil-knight The new function arrayUnion is conceptually similar to the existing function arrayIntersect. We should avoid to re-implement logic. Therefore, I'd suggest as first step to check src/Functions/array/arrayIntersect.cpp (possibly step through it using a debugger) which has a well-optimized implementation. As far as I see, most of the existing code also applies to arrayUnion and we only need to templatize FunctionArrayIntersect::execute (e.g. add a new template parameter bool intersect to distinguish intersect and union cases) and add a path under an if constexpr to it.

The other steps look good!

rschu1ze avatar Mar 26 '24 10:03 rschu1ze

@rschu1ze I'll work on this one

Blargian avatar May 15 '24 19:05 Blargian

@Blargian That's nice, I assigned you. Please ping me if you like me to have a look.

rschu1ze avatar May 17 '24 09:05 rschu1ze

@Blargian Are you still working on this? If not, I'd like to give it a shot.

petern48 avatar Aug 21 '24 02:08 petern48

@petern48 please go ahead! I got distracted with another project.

Blargian avatar Aug 21 '24 07:08 Blargian