Skip to content

Explore infrastructure for Dialect-specific Criteria #2076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft

Conversation

mp911de
Copy link
Member

@mp911de mp911de commented Jun 26, 2025

This pull request explores the necessary infrastructure so that a Dialect-specific extension can be provided to render Database-specific operators and functions for usage in Criteria (and later on Select Items and Order By).

To verify assumptions, we've provided a Postgres-specific dialect extension with:

  • Support for Array, JSON, and Vector Search functions and operators
  • Expressions to reference columns (property paths)
  • Initial support for Query Mapping using the R2DBC Query Mapper

Criteria Infrastructure requires details about typing and property to column (including joins) mapping to consider quotation, column names and target type conversion.

TODO:

  • Discuss QueryExpress with its nested interfaces and methods
  • Decide on PgSql API style
  • Determine whether we really need the BindMarkers copy (org.springframework.data.relational.core.binding package)

Syntax Variants

Functional Transformation (left-hand-side)

PgSql.where("embedding", it -> it.distanceTo(Vector.of(1, 2, 3), Distances::cosine)).lessThan("0.8")
     .and("some_json", it -> it.json().field("country")).is("Some Country");

Functional Transformation (right-hand-side)

PgSql.where("tags").json(it -> it.containsAll("electronics", "gaming"))

Fluent API per Entrypoint

PgSql.where(PgSql.vectorSearch().distanceOf("embedding", Vector.of(1, 2, 3)).cosine()).lessThan(0.8);

Fluent API (right-hand-side)

PgSql.where("tags").arrays().overlaps("country");

Each style contributes some useful details and we have to discuss for the Postgres-specific part, how we want to expose the API. We want to generally avoid a style that would e.g. make use of many braces (e.g. asBoolean(field(json("some_json"), "country"))) as counting closing-braces and inner braces is detrimental to code readability.

@mp911de mp911de marked this pull request as draft June 26, 2025 14:46
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 26, 2025
@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants