Skip to content

feat: parameterize S2_CoveringCellIds (min_level, max_level, max_cells)#1023

Open
ajaypadwal73 wants to merge 2 commits into
apache:mainfrom
ajaypadwal73:issue-920-s2-coveringcellids-params
Open

feat: parameterize S2_CoveringCellIds (min_level, max_level, max_cells)#1023
ajaypadwal73 wants to merge 2 commits into
apache:mainfrom
ajaypadwal73:issue-920-s2-coveringcellids-params

Conversation

@ajaypadwal73

@ajaypadwal73 ajaypadwal73 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds optional min_level, max_level, max_cells positional args to S2_CoveringCellIds, matching BigQuery's S2 covering signature.
  • Adds NULL-argument overloads so S2_CoveringCellIds returns NULL (rather than failing to resolve) when any parameter is a literal NULL.
  • Documents the new parameters and defaults (min_level=0, max_level=30, max_cells=8, unchanged from prior hardcoded behavior).

Closes #920

Submodule status

The s2geography C++ change backing this lives in paleolimbot/s2geography#123. Until that merges, .gitmodules temporarily points the submodule at my fork (ajaypadwal73/s2geography) so CI can resolve the pinned commit. Once #123 merges upstream, this PR needs a follow-up commit reverting .gitmodules to paleolimbot/s2geography and re-pinning the submodule to the merged commit.

Test plan

CI can't fetch commit 45a0ecf from paleolimbot/s2geography since it only exists on a fork branch. Temporarily point at the fork (paleolimbot/s2geography#123) until it merges upstream.
@ajaypadwal73

Copy link
Copy Markdown
Contributor Author

Hey @paleolimbot, can you please take a look at this?

Comment on lines +38 to +44
Optional positional arguments can control the covering:

| Argument | Description | Default |
| --- | --- | --- |
| `min_level` | Minimum S2 cell level to return. Must be between 0 and 30. | 0 |
| `max_level` | Maximum S2 cell level to return. Must be between 0 and 30. | 30 |
| `max_cells` | Maximum number of cells to return. Must be greater than 0. | 8 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of as a table, can you give these labels and descriptions in the yaml itself? You can see the documentation for st_buffer which does this.

Comment on lines +97 to +105
@pytest.mark.parametrize("eng", [SedonaDB])
def test_s2_coveringcellids_parameters(eng):
eng = eng.create_or_skip()
result = eng.execute_and_collect(
"SELECT S2_CoveringCellIds("
"ST_GeogFromText('LINESTRING (0 0, 100 50)'), 0, 30, 2)"
)
df = eng.result_to_pandas(result)
assert len(df.iloc[0, 0]) <= 2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add tests for all of the overloads that are exposed here? (min level and min + max level overloads are missing here). They can all be in the same Python test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cells_level, max_cells/min_cells are not parameterized in S2_COVERINGCELLIDS

2 participants