Skip to content

test: Add E2E tests for geo functions#26969

Open
jkhaliqi wants to merge 1 commit intoprestodb:masterfrom
jkhaliqi:e2e_geo
Open

test: Add E2E tests for geo functions#26969
jkhaliqi wants to merge 1 commit intoprestodb:masterfrom
jkhaliqi:e2e_geo

Conversation

@jkhaliqi
Copy link
Copy Markdown
Contributor

@jkhaliqi jkhaliqi commented Jan 14, 2026

Description

Add E2E tests for bing_tile_at, bing_tile_polygon, bing_tiles_around, and great_circle_distance.
Some testing data came from https://github.com/prestodb/presto/blob/master/presto-main-base/src/test/java/com/facebook/presto/geospatial/TestBingTileFunctions.java

Motivation and Context

closes #26935

Impact

Test Plan

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.
  • If adding new dependencies, verified they have an OpenSSF Scorecard score of 5.0 or higher (or obtained explicit TSC approval for lower scores).

Release Notes

Please follow release notes guidelines and fill in the release notes below.

== NO RELEASE NOTE ==

Summary by Sourcery

Add native geospatial E2E coverage for Bing tile and great-circle distance functions using a shared coordinates table utility.

Enhancements:

  • Extend TestingPrestoClient value conversion to support BING_TILE type results in tests.

Tests:

  • Add native tests validating bing_tile_at, bing_tile_polygon, bing_tiles_around, and great_circle_distance behavior and error handling.
  • Introduce a reusable GeoSpatialTestUtils helper to create coordinate test data and random temporary tables for geospatial queries.

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Jan 14, 2026
@prestodb-ci prestodb-ci requested review from a team, namya28 and sh-shamsan and removed request for a team January 14, 2026 21:55
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 14, 2026

Reviewer's Guide

Adds native E2E geospatial tests for Bing tile and great-circle distance functions by creating shared coordinate test data, temporary table helpers, and enabling BING_TILE handling in the test client.

File-Level Changes

Change Details Files
Introduce reusable geospatial test utilities for coordinate data and temporary table creation in native tests.
  • Add GeoSpatialTestUtils helper with generateRandomTableName to safely create and pre-drop temporary tables
  • Add createCoordinates helper that recreates a coordinates table and populates it with valid and invalid lat/lon/zoom combinations and great-circle test pairs
presto-native-tests/src/test/java/com/facebook/presto/nativetests/GeoSpatialTestUtils.java
Extend native geospatial E2E test suite to cover Bing tile and great-circle distance functions using shared test data.
  • Override createTables in TestPrestoNativeGeospatial to create and seed the coordinates table via GeoSpatialTestUtils
  • Add testBingTileAt to validate successful evaluations and error handling for out-of-range latitude, longitude, and zoom values
  • Add testBingTilePolygon that builds a temporary tile table, exercises bing_tile_polygon on valid tiles, and checks error behavior for invalid X coordinate
  • Add testBingTilesAround to validate cardinality computation on valid coordinates and error handling for invalid coordinates and zoom
  • Add testGreatCircleDistance to validate normal execution and error messages for invalid latitude/longitude inputs
presto-native-tests/src/test/java/com/facebook/presto/nativetests/TestPrestoNativeGeospatial.java
Teach TestingPrestoClient to pass through BING_TILE values for comparison in tests.
  • Extend TestingPrestoClient.convertToRowValue to handle BING_TILE type by returning the raw value
presto-tests/src/main/java/com/facebook/presto/tests/TestingPrestoClient.java

Assessment against linked issues

Issue Objective Addressed Explanation
#26935 Add end-to-end tests for the geospatial function bing_tile_at.
#26935 Add end-to-end tests for the geospatial function bing_tile_polygon.
#26935 Add end-to-end tests for the geospatial functions bing_tiles_around and great_circle_distance.

Possibly linked issues


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

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 left some high level feedback:

  • For the positive cases in testBingTileAt, testBingTilesAround, and testGreatCircleDistance, consider asserting against concrete expected values (e.g., specific tile IDs, polygon WKT, or distances) rather than just assertQuery/SELECT cardinality(...) so the tests verify correctness and not just successful execution.
  • In testBingTilesAround, you can strengthen the tests by checking that cardinality(bing_tiles_around(...)) equals an expected constant (e.g., SELECT 9), which will catch regressions in the number of tiles returned for a given zoom.
  • Now that BING_TILE is handled in TestingPrestoClient.convertToRowValue, it may be worth adding at least one query in the tests that returns a BING_TILE directly in a result set (not just using it as an argument) to exercise that conversion path.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- For the positive cases in `testBingTileAt`, `testBingTilesAround`, and `testGreatCircleDistance`, consider asserting against concrete expected values (e.g., specific tile IDs, polygon WKT, or distances) rather than just `assertQuery`/`SELECT cardinality(...)` so the tests verify correctness and not just successful execution.
- In `testBingTilesAround`, you can strengthen the tests by checking that `cardinality(bing_tiles_around(...))` equals an expected constant (e.g., `SELECT 9`), which will catch regressions in the number of tiles returned for a given zoom.
- Now that `BING_TILE` is handled in `TestingPrestoClient.convertToRowValue`, it may be worth adding at least one query in the tests that returns a `BING_TILE` directly in a result set (not just using it as an argument) to exercise that conversion path.

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.

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @jkhaliqi for the tests.

@Test
public void testBingTileAt()
{
assertQuery("SELECT bing_tile_at(0.0, 0.0, 0)");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jkhaliqi : A lot of these tests are using constants which are typically constant folded in the co-ordinator. Please write tests that involve using a column of data from a table as those run on workers.

@jkhaliqi jkhaliqi force-pushed the e2e_geo branch 2 times, most recently from b9b0f0a to 55ef8c1 Compare January 15, 2026 19:34
@jkhaliqi jkhaliqi force-pushed the e2e_geo branch 2 times, most recently from 9c9fe3d to de07ad0 Compare February 4, 2026 21:25
@jkhaliqi jkhaliqi requested a review from czentgr February 5, 2026 16:33
Copy link
Copy Markdown
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thanks, for the description - release notes we don't need it.
Remember release notes are what goes into the changelog. That we added tests is great but not necessarily relevant like a fix/feature etc.

Should we look at the presto-native-tests as well and see what the support for testing the bing tile is?
I assume that these tests originally came from the Java E2E test. Maybe we can refer to it in the description.

@steveburnett
Copy link
Copy Markdown
Contributor

Thanks, for the description - release notes we don't need it. Remember release notes are what goes into the changelog. That we added tests is great but not necessarily relevant like a fix/feature etc.

Thanks, good point. Just update the release note entry to

== NO RELEASE NOTE ==

czentgr
czentgr previously approved these changes Feb 19, 2026
Copy link
Copy Markdown
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @jkhaliqi

}
}

public static void createCoordinates(QueryRunner queryRunner)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jkhaliqi : Is this table used by any other tests ? Can we move this function to TestPrestoNativeGeospatial or to another specific file for GeoSpatial utility functions ?

Copy link
Copy Markdown
Contributor Author

@jkhaliqi jkhaliqi Feb 27, 2026

Choose a reason for hiding this comment

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

@aditi-pandit Thank you, it's only used and will be used for Geo testing, so created GeoSpatialTestUtility class.

czentgr
czentgr previously approved these changes Mar 18, 2026
Copy link
Copy Markdown
Contributor

@czentgr czentgr left a comment

Choose a reason for hiding this comment

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

Thanks. @aditi-pandit Please also take another look.

Copy link
Copy Markdown
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

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

Thanks @jkhaliqi for these tests.

String tmpTableName = generateRandomTableName(getQueryRunner());
getQueryRunner().execute(format("CREATE TABLE %s " +
"(x integer, y integer, z integer, isvalid boolean)", tmpTableName));
getQueryRunner().execute(format("INSERT INTO %s VALUES " +
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add some cases here where either of (or 2 of) x, y, z are NULL ?

@aditi-pandit
Copy link
Copy Markdown
Contributor

@sourcery-ai review

@aditi-pandit aditi-pandit requested a review from Copilot March 19, 2026 18:06
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 found 1 issue, and left some high level feedback:

  • The coordinates table is created as a shared, non-temporary table in createTables() and reused across tests, which can lead to cross-test coupling and flakiness; consider using per-test temporary tables or a helper like TestTable that creates and drops isolated tables.
  • generateRandomTableName creates persistent tables (e.g., in testBingTilePolygon) but the tests never drop them, so the test suite will leave behind state; it would be better to wrap such tables in a utility that ensures DROP TABLE in a try/finally or equivalent.
  • The assertQueryFails patterns are tightly coupled to full error messages like specific phrasing and capitalization (e.g., Latitude.*outside of valid range), which can be brittle; consider relaxing the regexes to match only the most stable parts of the message or using error codes if available.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `coordinates` table is created as a shared, non-temporary table in `createTables()` and reused across tests, which can lead to cross-test coupling and flakiness; consider using per-test temporary tables or a helper like `TestTable` that creates and drops isolated tables.
- `generateRandomTableName` creates persistent tables (e.g., in `testBingTilePolygon`) but the tests never drop them, so the test suite will leave behind state; it would be better to wrap such tables in a utility that ensures `DROP TABLE` in a `try/finally` or equivalent.
- The `assertQueryFails` patterns are tightly coupled to full error messages like specific phrasing and capitalization (e.g., `Latitude.*outside of valid range`), which can be brittle; consider relaxing the regexes to match only the most stable parts of the message or using error codes if available.

## Individual Comments

### Comment 1
<location path="presto-native-tests/src/test/java/com/facebook/presto/nativetests/TestPrestoNativeGeospatial.java" line_range="73-82" />
<code_context>
+    @Test
</code_context>
<issue_to_address>
**suggestion (testing):** Drop the temporary table created in testBingTilePolygon to avoid leaving artifacts between test runs.

`testBingTilePolygon` creates a temporary table with a random name but never drops it, so it persists after the test and can clutter shared environments or repeated runs. Please ensure the table is dropped, e.g., by wrapping `CREATE`/`INSERT`/`SELECT` in a try/finally with a `DROP TABLE` in the finally block, or by using a helper that manages temporary test table lifecycle.

Suggested implementation:

```java
    @Test
    public void testBingTilePolygon()
    {
        String tableName = "tmp_bing_tile_polygon_" + randomNameSuffix();

        try {
            assertUpdate(format("CREATE TABLE %s AS SELECT ...", tableName),  /* expectedRows */  ...);
            assertQuery(format("SELECT ... FROM %s", tableName), "SELECT ...");
        }
        finally {
            // Best-effort cleanup to avoid leaving artifacts between test runs
            assertUpdate(format("DROP TABLE IF EXISTS %s", tableName));
        }
    }

```

I only saw a small portion of the file, so please adjust the SEARCH block to match the actual implementation of `testBingTilePolygon`:

1. Keep the existing `tableName` initialization expression exactly as it is (if it already uses a random name, retain that).
2. Move all existing `CREATE` / `INSERT` / `SELECT` calls inside the `try` block.
3. Ensure `assertUpdate(format("DROP TABLE IF EXISTS %s", tableName));` in the `finally` block matches your existing assertion utilities and imports (e.g., `format` from `java.lang.String` or `com.facebook.presto.util.MoreStrings` as currently used in the file).
4. If the test currently uses a different variable name than `tableName`, update the `DROP TABLE` statement accordingly.
</issue_to_address>

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds end-to-end coverage for Presto Native geospatial functions (Bing tile utilities + great circle distance) and extends test result handling to support BING_TILE values.

Changes:

  • Extend TestingPrestoClient row-value conversion to handle BING_TILE results in test assertions.
  • Add native E2E tests for bing_tile_at, bing_tile_polygon, bing_tiles_around, and great_circle_distance (including failure cases).
  • Introduce GeoSpatialTestUtils to provision shared coordinate test data and generate temp table names.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
presto-tests/src/main/java/com/facebook/presto/tests/TestingPrestoClient.java Adds BING_TILE handling in test value conversion to support new assertions.
presto-native-tests/src/test/java/com/facebook/presto/nativetests/TestPrestoNativeGeospatial.java Adds E2E geospatial tests and table setup for shared coordinate data.
presto-native-tests/src/test/java/com/facebook/presto/nativetests/GeoSpatialTestUtils.java New utility to create coordinate test table and generate random temp table names.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@allenshen13
Copy link
Copy Markdown
Member

image Should you add tests with the 4 parameter version that has radius?

@allenshen13
Copy link
Copy Markdown
Member

Should we have NULL array inputs (CAST(NULL AS ...))? Is that worth adding as a test?

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.

Add end to end tests for Geospatial functions

7 participants