shrirangmhalgi opened a new pull request, #57089:
URL: https://github.com/apache/spark/pull/57089
### What changes were proposed in this pull request?
Implement the ANSI SQL `OVERLAPS` predicate that determines whether two
chronological periods share at least one point in time.
#### Syntax:
```
(start1, end1) OVERLAPS (start2, end2)
(start1, interval1) OVERLAPS (start2, interval2)
```
#### Changes:
- **Grammar**: add `#overlaps` alternative to `booleanExpression` in
`SqlBaseParser.g4`, wired to the existing `OVERLAPS` keyword
- **AstBuilder**: `visitOverlaps` produces `Overlaps` expression
- **`Overlaps` expression**: implements ANSI overlap semantics - endpoint
normalization, point-period degenerate case, NULL three-valued logic
- **`ResolveOverlaps` analyzer rule**: rewrites (start, interval) form to
(start, start + interval)
- `OVERLAPS` TreePattern for analyzer pruning
- Supports `TIME`, `DATE`, `TIMESTAMP`, and `TIMESTAMP_NTZ` endpoints
### Why are the changes needed?
ANSI SQL defines `OVERLAPS` as a standard predicate (ISO/IEC 9075-2) but
Spark currently does not implement it despite reserving the keyword. The
primary motivation is the TIME data type - testing whether time-of-day ranges
intersect (shifts, business hours, bookings) is a common use case, e.g.
`(t_start, t_end) OVERLAPS (TIME'09:00', TIME'17:00')`.
### Does this PR introduce _any_ user-facing change?
Yes. `(start, end) OVERLAPS (start, end)` is now a valid boolean predicate
in SQL. Examples:
- `(TIME'09:00', TIME'12:00') OVERLAPS (TIME'11:00', TIME'13:00')` returns
`true`
- `(TIME'09:00', TIME'12:00') OVERLAPS (TIME'12:00', TIME'13:00')` returns
`false` (touching, not overlapping)
- `(TIME'09:00', INTERVAL '3' HOUR) OVERLAPS (TIME'11:00', TIME'13:00')`
returns `true` (interval form)
### How was this patch tested?
- Parser unit test in `ExpressionParserSuite` ("overlaps predicate")
- Golden SQL test file (`overlaps.sql`) covering: TIME
overlapping/non-overlapping periods, touching endpoints, endpoint
normalization, zero-length (point) periods, microsecond precision, interval
form, NULL endpoints (three-valued logic), DATE, TIMESTAMP, and TIMESTAMP_NTZ
support
- All existing tests pass (`catalyst/compile, sql/compile,
SQLQueryTestSuite`)
### Was this patch authored or co-authored using generative AI tooling?
CoAuthored using Claude Opus 4.6
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]