Skip to content

Commit

Permalink
HHH-18053 alternative fix for Cockroach duration arithmetic
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin King <gavin@hibernate.org>
  • Loading branch information
gavinking authored and beikov committed May 7, 2024
1 parent 0ee170d commit 046bec5
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.query.sqm.TemporalUnit.DAY;
import static org.hibernate.query.sqm.TemporalUnit.EPOCH;
import static org.hibernate.query.sqm.TemporalUnit.NATIVE;
import static org.hibernate.type.SqlTypes.ARRAY;
import static org.hibernate.type.SqlTypes.BINARY;
import static org.hibernate.type.SqlTypes.BLOB;
Expand Down Expand Up @@ -787,11 +786,15 @@ public String translateExtractField(TemporalUnit unit) {

/**
* {@code microsecond} is the smallest unit for an {@code interval},
* and the highest precision for a {@code timestamp}.
* and the highest precision for a {@code timestamp}, so we could
* use it as the "native" precision, but it's more convenient to use
* whole seconds (with the fractional part), since we want to use
* {@code extract(epoch from ...)} in our emulation of
* {@code timestampdiff()}.
*/
@Override
public long getFractionalSecondPrecisionInNanos() {
return 1_000; //microseconds
return 1_000_000_000; //seconds
}

@Override
Expand Down Expand Up @@ -865,13 +868,6 @@ public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalT
}
}

@Override
public String translateDurationField(TemporalUnit unit) {
return unit==NATIVE
? "microsecond"
: super.translateDurationField(unit);
}

@Override
public void appendDatetimeFormat(SqlAppender appender, String format) {
appender.appendSql( SpannerDialect.datetimeFormat( format ).result() );
Expand Down

0 comments on commit 046bec5

Please sign in to comment.