Skip to content

test: Enable native e2e test for array_split_into_chunks null literal#27559

Draft
allenshen13 wants to merge 1 commit intomasterfrom
fix-array-split-into-chunks-empty-array
Draft

test: Enable native e2e test for array_split_into_chunks null literal#27559
allenshen13 wants to merge 1 commit intomasterfrom
fix-array-split-into-chunks-empty-array

Conversation

@allenshen13
Copy link
Copy Markdown
Member

@allenshen13 allenshen13 commented Apr 10, 2026

Summary

Match Velox's behavior for array_split_into_chunks(array[], n) so the inherited
native e2e test (TestSqlInvokedFunctions#testArraySplitIntoChunks) can run
unmodified:

  • Add an explicit empty-array check to the SQL definition that throws
    "Cannot split an empty array." — byte-identical to Velox's
    VELOX_USER_CHECK_GT(inputSize, 0, "Cannot split an empty array.") in
    velox/functions/prestosql/ArrayFunctions.h.
  • Remove the // TODO override in presto-native-tests/.../TestSqlInvokedFunctions.java
    that was suppressing the entire native run of testArraySplitIntoChunks.
  • Extend AbstractTestSqlInvokedFunctions.testArraySplitIntoChunks with empty-array,
    exact-fit, and boolean-element cases. These run against H2 (Java) directly and
    against the native engine via the inherited TestSqlInvokedFunctions.
  • Add TestArraySqlFunctions.testArraySplitIntoChunksEmptyArray covering empty
    arrays of bigint / varchar / integer / double.

Tracks #27429.

Behavior change

array_split_into_chunks(array[], n) with n > 0 failed with
the sequence builtin's error: "sequence stop value should be greater than or equal to start value if step is greater than zero...". After this PR it
throws "Cannot split an empty array.", identical to what Velox throws,
so the same call fails the same way on both engines and the inherited native
e2e test can assert one regex against both. The original sequence failure throw is
ambiguous and should be changed.

Test plan

  • TestArraySqlFunctions#testArraySplitIntoChunksEmptyArray passes
  • AbstractTestSqlInvokedFunctions#testArraySplitIntoChunks passes (Java/H2)
  • TestSqlInvokedFunctions#testArraySplitIntoChunks passes against the native engine

Merge order

This PR must wait for facebookincubator/velox#16923 to land and for the
Velox SHA pinned by Presto to advance past it. That PR fixes the null-literal
overload-resolution half of #27429; until it's in, the inherited test's
array_split_into_chunks(null, 2) assertion will still fail on native.

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Apr 10, 2026
@prestodb-ci prestodb-ci requested review from a team, jp-sivaprasad and xin-zhang2 and removed request for a team April 10, 2026 17:49
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the SQL-implemented array_split_into_chunks function to return an empty array of arrays when given an empty input array, and adds corresponding unit and e2e tests while re-enabling the native engine test override.

File-Level Changes

Change Details Files
Handle empty input arrays in array_split_into_chunks SQL implementation instead of throwing on invalid sequence() bounds.
  • Wrap existing logic in an IF that checks cardinality(input) = 0 and directly returns an empty array when true
  • Keep existing validation that sz > 0 and the limit on the maximum number of chunks before calling sequence() and slice()
presto-sql-helpers/presto-sql-invoked-functions-plugin/src/main/java/com/facebook/presto/scalar/sql/ArraySqlFunctions.java
Add unit tests covering empty array inputs for array_split_into_chunks in scalar array SQL function tests.
  • Introduce testArraySplitIntoChunksEmptyArray with multiple element types (bigint, varchar, integer, double)
  • Assert that array_split_into_chunks returns an empty list of arrays for empty input arrays regardless of chunk size
presto-main-base/src/test/java/com/facebook/presto/operator/scalar/sql/TestArraySqlFunctions.java
Extend SQL-invoked function e2e tests to assert behavior for empty arrays and re-enable native test override.
  • Add an assertion in AbstractTestSqlInvokedFunctions.testArraySplitIntoChunks that an empty bigint array input returns an empty array-of-arrays
  • Remove the testArraySplitIntoChunks override in TestSqlInvokedFunctions so that it inherits and runs the base test against the native engine
presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestSqlInvokedFunctions.java
presto-native-tests/src/test/java/com/facebook/presto/nativetests/TestSqlInvokedFunctions.java

Assessment against linked issues

Issue Objective Addressed Explanation
#27429 Ensure array_split_into_chunks correctly handles a NULL literal array argument (e.g., select array_split_into_chunks(null, 2)) by resolving to array(unknown) and not failing operator resolution. The PR only changes the SQL function implementation to special-case empty input arrays and adds corresponding tests. It does not modify type resolution or null-literal handling, and no new tests cover array_split_into_chunks(null, 2), so the original NULL literal failure is not addressed.
#27429 On the Velox side, simplify and correct array_split_into_chunks registration (use a generic registration instead of many concrete types, remove unsupported int128_t, and add a decimal unit test). This PR is in the Presto repository and only changes Presto SQL function code and tests. It does not touch Velox registrations or Velox tests; those are deferred to a separate Velox PR referenced in the description.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@allenshen13 allenshen13 changed the title Fix array_split_into_chunks to handle empty arrays fix: Array_split_into_chunks to handle empty arrays Apr 10, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 10, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@allenshen13 allenshen13 force-pushed the fix-array-split-into-chunks-empty-array branch 3 times, most recently from 4db6aa3 to 2df5f81 Compare April 10, 2026 22:47
@kaikalur kaikalur requested a review from abhinavmuk04 April 10, 2026 22:54
@allenshen13 allenshen13 force-pushed the fix-array-split-into-chunks-empty-array branch from 2df5f81 to e7e282c Compare April 16, 2026 20:44
@allenshen13 allenshen13 changed the title fix: Array_split_into_chunks to handle empty arrays test: Enable native e2e test for array_split_into_chunks null literal Apr 27, 2026
@allenshen13 allenshen13 force-pushed the fix-array-split-into-chunks-empty-array branch from 65773cf to 280ba5b Compare April 28, 2026 00:20
The SQL expression used sequence(1, cardinality(input), sz) which threw
"sequence stop value should be greater than or equal to start value if step
is greater than zero" for empty input arrays. Add an explicit empty-array
guard in the SQL function that throws "Cannot split an empty array.",
matching the message Velox already throws.

This lets cross-engine tests assert the same error regex against both the
Java and native engines, and unblocks enabling the parent test in the
native test suite.

Changes:
- ArraySqlFunctions: add IF(cardinality(input) = 0, fail(...), ...) guard.
- TestArraySqlFunctions: add unit test for the empty-array error.
- AbstractTestSqlInvokedFunctions: add e2e coverage for empty-array,
  exact-fit boundary, boolean elements, and the cardinality-limit error.
- TestSqlInvokedFunctions (native): remove the TODO override so the
  parent test runs against the native engine.

Fixes: #27429
@allenshen13 allenshen13 force-pushed the fix-array-split-into-chunks-empty-array branch from 280ba5b to e29701d Compare April 28, 2026 21:16
@allenshen13 allenshen13 marked this pull request as draft April 29, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

from:IBM PR from IBM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants