yy782 opened a new pull request, #71159: URL: https://github.com/apache/doris/pull/71159
### Background `array_pushback` and `array_pushfront` append an element to the tail or head of an array. They were implemented as two separate `IFunction` classes with nearly identical bodies: unpack constant columns, extract the source `ColumnArray`, allocate a nullable array result, then copy the source elements and insert the new value before or after them. The only real difference was the insertion order, but each function carried its own copy of argument handling, null propagation and result construction. ### What problem does this PR solve? Issue Number: None Related PR: None PR Type: Refactor Problem Summary: The two functions duplicated roughly 100 lines of `IFunction` implementation each, and their constant-column handling had drifted apart: `pushback` used `unpack_if_const` with per-row `index_check_const`, while `pushfront` materialized both arguments with `convert_to_full_column_if_const`. Extract the shared implementation into a CRTP template `FunctionArrayPush<PushType>`; each concrete function now only supplies its name and an `is_front` flag, and a compile-time branch selects the insertion order. Both functions therefore share one path for constants, nulls and error handling, and new tests pin that path down. ### Details - **Change map:** production code is one new header (`function_array_push.h`, 122 lines) plus two `.cpp` files reduced from ~190 lines to declarations (6 lines); tests are one new unit test file (385 lines) and one regression suite with its `.out` (147 lines). No docs or generated files. - **Moves vs. logic changes:** the whole body of `create`, `get_name`, `get_return_type_impl` and `execute_impl` moved into the template base. Logic changes are limited to: both arguments now go through `unpack_if_const` + `index_check_const` instead of `pushfront` expanding constants into full columns; array extraction uses `extract_column_array_info`, which returns a `RuntimeError` for unsupported types instead of failing an `assert_cast`; the outer null map is indexed by the resolved source index. The head/tail element order itself is unchanged. - **Behavior change:** No for supported inputs — both functions still return `Nullable(Array(...))` with the same element order and null propagation. Unsupported source array types now raise a runtime error instead of hitting a failed cast. - **Compatibility:** function names, signatures and registration are unchanged, so existing queries are unaffected. - **Performance impact:** `array_pushfront` no longer materializes constant arguments into full columns, so constant inputs allocate less memory. Non-constant inputs follow the same work as before. - **Rollback:** revert the commit; no configuration or data changes are involved. ### Testing Build: BE compiled successfully. Unit test — `be/test/exprs/function/function_array_push_test.cpp` (passed). It instantiates the template directly through two trait structs (front and back) and checks the produced `Block` column element by element: - head vs. tail insertion order on the same array; - a constant array source reused across 4 rows with a varying right column; - a 16-row constant `NULL` array source, where every row must stay null; - a constant right value against arrays of different lengths, including empty arrays; - null elements inside the array with the inner null map preserved; - a null outer array propagating to the result; - outer array and elements both nullable; - empty source arrays and offset advancement; - return type deduction for plain, outer-nullable and nested-nullable arrays. Regression suite — `test_array_push_pop_backfront.groovy` with its `.out` (passed). It adds a table with int, boolean, nested-array, decimal, datetime and varchar array columns, including null arrays, null elements and empty arrays, plus 8 query groups: constant-null pushfront over 16 rows, head/tail push on ordered rows, mixed constant-array and constant-value cases, nested arrays as elements, boolean arrays, pushing `NULL` into four element types, empty/singleton arrays, and the `array_append` alias. ### Release note None. ### Check List (For Author) - Behavior changed: No - Does this need documentation: No - Pre-submission status: Ready ### AI Disclosure - Tool: DeepSeek V4 Pro - Generated: the refactor, the unit tests, the regression suite and this description - Human review: approved the approach and reviewed the generated code, tests and description before submission -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
