Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,6 @@ public String extractPattern(TemporalUnit unit) {
case DAY_OF_WEEK -> "(weekday(?2)+1)";
case DAY_OF_MONTH -> "day(?2)";
case EPOCH -> "(to_number(cast(cast(sum(?2-datetime(1970-1-1) year to day) as interval day(9) to day) as varchar(12)))*86400+to_number(cast(cast(sum(cast(?2 as datetime hour to second)-datetime(00:00:00) hour to second) as interval second(6) to second) as varchar(9))))";
case NATIVE -> "((to_number(cast(cast(sum(?2) as interval day(9) to day) as varchar(12)))*86400+mod(to_number(cast(cast(sum(?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?2) as interval fraction to fraction) as varchar(6))))*1e3)";
default -> "?1(?2)";
};
}
Expand Down Expand Up @@ -695,33 +694,51 @@ public String getCurrentTimestampSelectString() {

@Override @SuppressWarnings("deprecation")
public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {
return intervalType != null ? "(?2 + ?3)" : "(?3 + " + intervalPattern( unit ) + ")";
return intervalType != null ? "(?2 + ?3)" : "(?3 + " + intervalPattern( unit, temporalType ) + ")";
}

private static String intervalPattern(TemporalUnit unit) {
@SuppressWarnings("deprecation")
private static String intervalPattern(TemporalUnit unit, TemporalType temporalType) {
return switch (unit) {
case NANOSECOND -> "?2/1e9 * interval (1) second to fraction";
case NATIVE, SECOND -> "?2 * interval (1) second to fraction";
case QUARTER -> "?2 * interval (3) month to month";
case WEEK -> "?2 * interval (7) day to day";
default -> "?2 * interval (1) " + unit + " to " + unit;
case NANOSECOND -> "?2/1e9 * interval (1) second(9) to fraction";
case SECOND, NATIVE ->
temporalType == TemporalType.TIME
? "?2 * 1 units second" // times don't usually come equipped with fractional seconds
: "?2 * interval (1) second(9) to fraction"; // datetimes do have fractional seconds
case QUARTER -> "?2 * 3 units month";
case WEEK -> "?2 * 7 units day";
default -> "?2 * 1 units " + unit;
};
}

@Override
public long getFractionalSecondPrecisionInNanos() {
// Informix actually supports up to 10 microseconds
// but defaults to milliseconds (so use that)
return 1_000_000;
// since we do computations with intervals,
// may as well just use seconds as the NATIVE
// precision, do minimize conversion factors
return 1_000_000_000;
// // Informix actually supports up to 10 microseconds
// // but defaults to milliseconds (so use that)
// return 1_000_000;
}

@Override @SuppressWarnings("deprecation")
public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
return unit == null
? "(?3-?2)"
: extractPattern( unit )
.replace( "?1", unit.toString() )
.replace( "?2", "?3-?2" );
if ( unit == null ) {
return "(?3-?2)";
}
else {
return switch ( unit ) {
case NATIVE ->
fromTemporalType == TemporalType.TIME
// arguably, we don't really need to retain the milliseconds for a time, since times don't usually come with millis
? "(mod(to_number(cast(cast(sum(?3-?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?3-?2) as interval fraction to fraction) as varchar(6))))"
: "(to_number(cast(cast(sum(?3-?2) as interval day(9) to day) as varchar(12)))*86400+mod(to_number(cast(cast(sum(?3-?2) as interval second(6) to second) as varchar(9))),86400)+to_number(cast(cast(sum(?3-?2) as interval fraction to fraction) as varchar(6))))";
case SECOND -> "to_number(cast(cast(sum(?3-?2) as interval second(9) to fraction) as varchar(15)))";
case NANOSECOND -> "(to_number(cast(cast(sum(?3-?2) as interval second(9) to fraction) as varchar(15)))*1e9)";
default -> "to_number(cast(cast(sum(?3-?2) as interval ?1(9) to ?1) as varchar(12)))";
};
}
}

@Override
Expand Down Expand Up @@ -948,7 +965,7 @@ public void appendDateTimeLiteral(
break;
case TIME:
appendAsTime( appender, temporalAccessor, supportsTemporalLiteralOffset(), jdbcTimeZone );
appender.appendSql( ") hour to fraction" );
appender.appendSql( ") hour to second" ); // we ignore the milliseconds
break;
case TIMESTAMP:
appendAsTimestampWithMillis( appender, temporalAccessor, supportsTemporalLiteralOffset(), jdbcTimeZone );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.hibernate.sql.ast.spi.SqlAstTranslatorWithMerge;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression;
import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression;
import org.hibernate.sql.ast.tree.expression.CaseSimpleExpression;
import org.hibernate.sql.ast.tree.expression.Expression;
Expand Down Expand Up @@ -314,4 +315,12 @@ protected void visitCaseSearchedExpression(CaseSearchedExpression caseSearchedEx
protected void visitCaseSimpleExpression(CaseSimpleExpression caseSimpleExpression, boolean inSelect) {
visitAnsiCaseSimpleExpression( caseSimpleExpression, this::caseArgument );
}

@Override
public void visitBinaryArithmeticExpression(BinaryArithmeticExpression arithmeticExpression) {
if ( isIntegerDivisionEmulationRequired( arithmeticExpression ) ) {
appendSql( "floor" );
}
super.visitBinaryArithmeticExpression( arithmeticExpression );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected X doExtract(ResultSet rs, int position, WrapperOptions options) throws
// supposed to be supported in JDBC 4.2
return javaType.wrap( rs.getObject( position, OffsetDateTime.class ), options );
}
catch (SQLException|AbstractMethodError e) {
catch (SQLException|AbstractMethodError|ClassCastException e) {
// fall back to treating it as a JDBC Timestamp
return options.getJdbcTimeZone() != null ?
javaType.wrap( rs.getTimestamp( position, Calendar.getInstance( options.getJdbcTimeZone() ) ), options ) :
Expand All @@ -146,7 +146,7 @@ protected X doExtract(CallableStatement statement, int position, WrapperOptions
// supposed to be supported in JDBC 4.2
return javaType.wrap( statement.getObject( position, OffsetDateTime.class ), options );
}
catch (SQLException|AbstractMethodError e) {
catch (SQLException|AbstractMethodError|ClassCastException e) {
// fall back to treating it as a JDBC Timestamp
return options.getJdbcTimeZone() != null ?
javaType.wrap( statement.getTimestamp( position, Calendar.getInstance( options.getJdbcTimeZone() ) ), options ) :
Expand All @@ -160,7 +160,7 @@ protected X doExtract(CallableStatement statement, String name, WrapperOptions o
// supposed to be supported in JDBC 4.2
return javaType.wrap( statement.getObject( name, OffsetDateTime.class ), options );
}
catch (SQLException|AbstractMethodError e) {
catch (SQLException|AbstractMethodError|ClassCastException e) {
// fall back to treating it as a JDBC Timestamp
return options.getJdbcTimeZone() != null ?
javaType.wrap( statement.getTimestamp( name, Calendar.getInstance( options.getJdbcTimeZone() ) ), options ) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
import java.util.Arrays;
import java.util.List;

import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.testing.jdbc.SharedDriverManagerTypeCacheClearingIntegrator;
import org.hibernate.testing.orm.junit.BootstrapServiceRegistry;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;

import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.Test;

import jakarta.persistence.Parameter;
Expand All @@ -40,6 +42,8 @@
public class ParameterTest {

@Test
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Blobs are not allowed in this expression")
public void testPrimitiveArrayParameterBinding(SessionFactoryScope scope) {
scope.inTransaction( em -> {
CriteriaQuery<MultiTypedBasicAttributesEntity> criteria = em.getCriteriaBuilder()
Expand All @@ -56,6 +60,8 @@ public void testPrimitiveArrayParameterBinding(SessionFactoryScope scope) {
}

@Test
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Blobs are not allowed in this expression")
public void testNonPrimitiveArrayParameterBinding(SessionFactoryScope scope) {
scope.inTransaction( em -> {
CriteriaQuery<MultiTypedBasicAttributesEntity> criteria = em.getCriteriaBuilder()
Expand Down Expand Up @@ -136,6 +142,8 @@ public void testParameterInParameterList2(SessionFactoryScope scope) {

@Test
@JiraKey("HHH-17912")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Blobs are not allowed in this expression")
public void testAttributeEqualListParameter(SessionFactoryScope scope) {
scope.inTransaction( em -> {
final CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.community.dialect.DerbyDialect;
import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.dialect.HANADialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SybaseDialect;
Expand Down Expand Up @@ -197,6 +198,8 @@ public void verifyDirtyChecking(SessionFactoryScope scope) {
reason = "Oracle doesn't support comparing JSON with the = operator")
@SkipForDialect(dialectClass = AltibaseDialect.class,
reason = "Altibase doesn't support comparing CLOBs with the = operator")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Blobs are not allowed in this expression")
public void verifyComparisonWorks(SessionFactoryScope scope) {
scope.inTransaction(
(session) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.hibernate.annotations.JdbcTypeCode;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.community.dialect.AltibaseDialect;
import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.dialect.HANADialect;
import org.hibernate.community.dialect.DerbyDialect;
import org.hibernate.dialect.OracleDialect;
Expand Down Expand Up @@ -136,6 +137,7 @@ public void verifyReadWorks(SessionFactoryScope scope) {
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true, reason = "Sybase doesn't support comparing LOBs with the = operator")
@SkipForDialect(dialectClass = OracleDialect.class, matchSubTypes = true, reason = "Oracle doesn't support comparing JSON with the = operator")
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase doesn't support comparing CLOBs with the = operator")
@SkipForDialect(dialectClass = InformixDialect.class, reason = "Blobs are not allowed in this expression")
public void verifyComparisonWorks(SessionFactoryScope scope) {
scope.inTransaction(
(session) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;
import java.util.function.Consumer;

import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.dialect.SybaseASEDialect;
import org.hibernate.community.dialect.TiDBDialect;
import org.hibernate.query.Query;
Expand Down Expand Up @@ -130,6 +131,8 @@ public void testBasicJoined(SessionFactoryScope scope) {
}

@Test
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Apparently nested CTEs are not supported")
public void testNested(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ public void testCastInvalidStringToBoolean(SessionFactoryScope scope) {
@SkipForDialect(dialectClass = DerbyDialect.class)
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
@SkipForDialect(dialectClass = AltibaseDialect.class, reason = "Altibase does not support offset of datetime")
@SkipForDialect(dialectClass = InformixDialect.class, reason = "Informix does not support offset datetime")
public void testCastToOffsetDatetime(SessionFactoryScope scope) {
scope.inTransaction( session -> {
session.createQuery("select cast(datetime 1911-10-09 12:13:14-02:00 as String)", String.class).getSingleResult();
Expand Down Expand Up @@ -1490,8 +1491,6 @@ public void testIntervalAddExpressions(SessionFactoryScope scope) {
.list();
session.createQuery("select e.theTime + 30 second from EntityOfBasics e", Date.class)
.list();
session.createQuery("select e.theTime + 300000000 nanosecond from EntityOfBasics e", Date.class)
.list();

session.createQuery("select e.theTimestamp + 1 year from EntityOfBasics e", Date.class)
.list();
Expand All @@ -1511,6 +1510,18 @@ public void testIntervalAddExpressions(SessionFactoryScope scope) {
);
}

@Test
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Adding nanoseconds to a time is weird anyway")
public void testAddNanosecondsToTime(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("select e.theTime + 300000000 nanosecond from EntityOfBasics e", Date.class)
.list();
}
);
}

@Test
public void testIntervalSubExpressions(SessionFactoryScope scope) {
scope.inTransaction(
Expand Down Expand Up @@ -1794,10 +1805,12 @@ public void testDurationArithmetic(SessionFactoryScope scope) {
reason = "numeric overflow")
@SkipForDialect(dialectClass = OracleDialect.class,
reason = "numeric overflow")
@SkipForDialect( dialectClass = TiDBDialect.class,
@SkipForDialect(dialectClass = TiDBDialect.class,
reason = "Bug in the TiDB timestampadd function (https://github.com/pingcap/tidb/issues/41052)")
@SkipForDialect( dialectClass = AltibaseDialect.class,
@SkipForDialect(dialectClass = AltibaseDialect.class,
reason = "exceeds timestampadd limit in Altibase")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Overflow occurred on a datetime or interval")
public void testDurationArithmeticOverflowing(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down Expand Up @@ -1910,6 +1923,8 @@ public void testDurationSubtractionWithTimeLiterals(SessionFactoryScope scope) {
@SkipForDialect(dialectClass = SybaseDialect.class,
matchSubTypes = true,
reason = "numeric overflow")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Overflow occurred on a datetime or interval operation")
public void testDurationSubtractionWithDatetimeLiterals(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand All @@ -1926,8 +1941,11 @@ public void testDurationSubtractionWithDatetimeLiterals(SessionFactoryScope scop
);
}

@Test @SkipForDialect(dialectClass = MySQLDialect.class,
@Test
@SkipForDialect(dialectClass = MySQLDialect.class,
reason = "MySQL has a really weird TIME type")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "The result of a datetime computation is out of range")
public void testTimeDurationArithmeticWrapAroundWithLiterals(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down Expand Up @@ -1975,6 +1993,8 @@ public void testDateDurationArithmeticWithLiterals(SessionFactoryScope scope) {

@Test
@JiraKey("HHH-17074")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Bad use of aggregate in this context")
public void testDurationArithmeticWithParameters(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down Expand Up @@ -2029,12 +2049,28 @@ public void testIntervalDiffExpressions(SessionFactoryScope scope) {
);
}

@Test
@SkipForDialect(dialectClass = PostgresPlusDialect.class,
reason = "PT47H59M59.999999S instead of PT48H")
public void testIntervalDiffExpressionsWithAssertions(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
assertThat( session.createQuery("select (local datetime + 2 day) - local datetime").getSingleResult(),
is( Duration.ofDays( 2 ) ) );
assertThat( session.createQuery("select (local datetime - 12 hour) - local datetime").getSingleResult(),
is( Duration.ofHours( -12 ) ) );
}
);
}

@Test
@SkipForDialect(dialectClass = SybaseDialect.class,
matchSubTypes = true,
reason = "result in numeric overflow")
@SkipForDialect(dialectClass = PostgresPlusDialect.class,
reason = "trivial rounding error")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Overflow occurred on a datetime or interval operation")
public void testMoreIntervalDiffExpressions(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand All @@ -2051,7 +2087,10 @@ public void testMoreIntervalDiffExpressions(SessionFactoryScope scope) {


@Test
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "unsupported binary operator: <date> - <timestamp(6)>")
@SkipForDialect(dialectClass = CockroachDialect.class,
reason = "unsupported binary operator: <date> - <timestamp(6)>")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Intervals or datetimes are incompatible for the operation")
public void testIntervalDiffExpressionsDifferentTypes(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.dialect.CockroachDialect;

import org.hamcrest.number.IsCloseTo;
Expand Down Expand Up @@ -566,7 +567,10 @@ public void testIntervalDiffExpressions(SessionFactoryScope scope) {
}

@Test
@SkipForDialect(dialectClass = CockroachDialect.class, reason = "unsupported binary operator: <date> - <timestamp(6)>")
@SkipForDialect(dialectClass = CockroachDialect.class,
reason = "unsupported binary operator: <date> - <timestamp(6)>")
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Intervals or datetimes are incompatible for the operation")
public void testIntervalDiffExpressionsDifferentTypes(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.community.dialect.InformixDialect;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;

import org.hibernate.testing.orm.jdbc.PreparedStatementSpyConnectionProvider;
Expand All @@ -34,7 +34,8 @@
/**
* @author Vlad Mihalcea
*/
@SkipForDialect(dialectClass = MySQLDialect.class, matchSubTypes = true)
@SkipForDialect(dialectClass = InformixDialect.class,
reason = "Informix JDBC driver seems to misinterpret the JDBC time zone")
public class JdbcTimeCustomTimeZoneTest
extends BaseSessionFactoryFunctionalTest {

Expand Down
Loading