Skip to content

Implement FunctionVariantAdaptor to support variant type in functions - #90900

Merged
bharatnc merged 27 commits into
masterfrom
ncb/support-geometry-for-flipcoordinates
Jan 10, 2026
Merged

bharatnc merged 27 commits into
masterfrom
ncb/support-geometry-for-flipcoordinates

Conversation

@bharatnc

@bharatnc bharatnc commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

Implement variant function adaptor. This is a permanent fix for #79634 to support Geometry type for flipCoordinates function. An temporary patch for it #93303 was already merged and backported. After this PR is merged, the patch can be removed.

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Implement FunctionVariantAdaptor to support variant type in functions

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@clickhouse-gh

clickhouse-gh Bot commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3485a2e]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_binary, ParallelReplicas, s3 storage, parallel) failure
03776_text_index_compact_tokens FAIL cidb, issue ISSUE EXISTS
Integration tests (amd_tsan, 3/6) failure
test_backup_restore_on_cluster/test_disallow_concurrency.py::test_concurrent_backups_on_different_nodes FAIL cidb, issue ISSUE EXISTS
test_backup_restore_on_cluster/test_disallow_concurrency.py::test_concurrent_restores_on_same_node FAIL cidb, issue ISSUE EXISTS
test_backup_restore_on_cluster/test_disallow_concurrency.py::test_concurrent_restores_on_different_node FAIL cidb, issue ISSUE EXISTS
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL cidb, issue ISSUE EXISTS
Integration tests (amd_asan, targeted) error IGNORED

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Nov 26, 2025
@bharatnc
bharatnc force-pushed the ncb/support-geometry-for-flipcoordinates branch from 8c72faa to 2b33a29 Compare November 26, 2025 15:59
@bharatnc
bharatnc requested a review from Copilot November 26, 2025 15:59

Copilot AI left a comment

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.

Pull request overview

This PR extends the flipCoordinates function to support the Geometry variant type in addition to the existing tuple-based geometric types (Point, Ring, Polygon, MultiPolygon). The implementation processes geometry data stored as variants by converting each geometry subtype, flipping its coordinates, and reconstructing the variant column.

Key changes:

  • Added support for Geometry type (represented as a variant) in the flipCoordinates function
  • Implemented coordinate flipping for all geometry subtypes through the variant type system
  • Added comprehensive test coverage for the new Geometry type support

Reviewed changes

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

File Description
src/Functions/flipCoordinates.cpp Implements Geometry variant type support by adding variant column handling, geometry type conversion helpers, and a new executeForGeometry method that processes each geometry subtype
tests/queries/0_stateless/03444_flip_coordinates.sql Adds test cases covering Geometry type with various subtypes (Point, LineString, Polygon, etc.) and verifies correct type preservation
tests/queries/0_stateless/03444_flip_coordinates.reference Contains expected outputs for the new Geometry type test cases

Comment thread src/Functions/flipCoordinates.cpp Resolved
Comment thread src/Functions/flipCoordinates.cpp Resolved
Comment thread src/Functions/flipCoordinates.cpp Resolved

@alexey-milovidov alexey-milovidov left a comment

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.

The implementation with a temporary Field is suboptimal.
Change to something like "default implementation for variant".
You can ask @Avogar about it.

Moreover, I want all the implementation to be greatly simplified. Let it accept any dimensional array of points of any type and variants of them.

@alexey-milovidov alexey-milovidov self-assigned this Nov 26, 2025
@Avogar

Avogar commented Nov 26, 2025

Copy link
Copy Markdown
Member

Change to something like "default implementation for variant".
You can ask @Avogar about it.

Just to clarify, "default implementation for variant" means "execute function on each underlying variant subcolumn separately and then combine the results into a single result according to discriminators".

There are 2 different things we can do:

  1. Implement general default implementation for Variant for most functions similar to default implementation for Dynamic we already have
  2. If 1) is too much, we can implement it only for this function.

@alexey-milovidov

Copy link
Copy Markdown
Member

I was under the impression that it exists. If it's not, ok to just look into each subcolumn and pass it for processing here.

@Avogar

Avogar commented Nov 26, 2025

Copy link
Copy Markdown
Member

I was under the impression that it exists.

It exists for Dynamic data type only. It has its own specifics, so for Variant we need separate default implementation (but it will be similar). Probably it's a good feature request.

@bharatnc

Copy link
Copy Markdown
Contributor Author

I was under the impression that it exists. If it's not, ok to just look into each subcolumn and pass it for processing here.

It sounds like the current implementation should work for now though sub optimal. Let me know if otherwise.

If 1) is too much, we can implement it only for this function.

As per @Avogar 's suggestion, if it's going to be slightly more optimal, I can try default implementation for this function - I will follow up with Pavel with any questions.

Variant we need separate default implementation

How much of work would this be?

@alexey-milovidov

alexey-milovidov commented Nov 29, 2025 •

Copy link
Copy Markdown
Member

I'd rather withdraw the flipCoordinates function from the release than accept this implementation.

@alexey-milovidov

Copy link
Copy Markdown
Member

How much of work would this be?

Not much.

@alexey-milovidov

Copy link
Copy Markdown
Member

It sounds like the current implementation should work for now though sub optimal.

It's not good for me.

@bharatnc

bharatnc commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

It sounds like the current implementation should work for now though sub optimal.

It's not good for me.

Ok, I misunderstood your initial point. I'll avoid using the temporary field.

I'll work on simplifying it and work on a more efficient implementation.

@bharatnc
bharatnc force-pushed the ncb/support-geometry-for-flipcoordinates branch from ccafe22 to 35faf18 Compare December 1, 2025 15:21
@Avogar Avogar self-assigned this Dec 1, 2025
@bharatnc
bharatnc requested a review from Avogar January 2, 2026 03:20
@bharatnc
bharatnc force-pushed the ncb/support-geometry-for-flipcoordinates branch from f73b113 to 5ae927a Compare January 2, 2026 04:22

@Avogar Avogar left a comment

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.

Looks really great! Amazing work! Some small adjustments are remaining

@bharatnc
bharatnc requested a review from Avogar January 8, 2026 03:00

@Avogar Avogar left a comment

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.

Just a few minor comments and we can merge it

Comment thread src/Functions/IFunction.cpp Resolved
@bharatnc
bharatnc requested a review from Avogar January 9, 2026 12:24
Comment thread src/Functions/IFunction.cpp Resolved
@bharatnc
bharatnc requested a review from Avogar January 9, 2026 14:22
@bharatnc

Copy link
Copy Markdown
Contributor Author

test failures not related:

@bharatnc
bharatnc added this pull request to the merge queue Jan 10, 2026
Merged via the queue into master with commit e9d0862 Jan 10, 2026
124 of 128 checks passed
@bharatnc
bharatnc deleted the ncb/support-geometry-for-flipcoordinates branch January 10, 2026 02:50
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 10, 2026
alexey-milovidov added a commit that referenced this pull request Feb 3, 2026
…unctions"

This reverts commit e9d0862 (PR #90900).

The `FunctionVariantAdaptor` feature caused a logical error exception in
`arrayRemove` when comparing incompatible Variant types. The `equals`
function would return `Nullable(Nothing)` for such comparisons, but
`arrayRemove` assumed the result would be `UInt8`, leading to type
mismatch in the `if` function's `executeGeneric` method.

Fixes #95839

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants