HHH-18053 TiDB timestampadd/diff pattern for fractional seconds

This commit is contained in:
Marco Belladelli 2024-05-06 09:44:22 +02:00 committed by Christian Beikov
parent f45a7975c4
commit 5e9223ee5c
1 changed files with 22 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import org.hibernate.dialect.sequence.SequenceSupport;
import org.hibernate.dialect.sequence.TiDBSequenceSupport;
import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.query.sqm.IntervalType;
import org.hibernate.query.sqm.TemporalUnit;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstTranslatorFactory;
import org.hibernate.sql.ast.spi.StandardSqlAstTranslatorFactory;
@ -19,6 +21,8 @@ import org.hibernate.sql.exec.spi.JdbcOperation;
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorTiDBDatabaseImpl;
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
import jakarta.persistence.TemporalType;
/**
* A {@linkplain Dialect SQL dialect} for TiDB.
*
@ -177,4 +181,22 @@ public class TiDBDialect extends MySQLDialect {
public FunctionalDependencyAnalysisSupport getFunctionalDependencyAnalysisSupport() {
return FunctionalDependencyAnalysisSupportImpl.TABLE_REFERENCE;
}
@Override
public String timestampaddPattern(TemporalUnit unit, TemporalType temporalType, IntervalType intervalType) {
if ( unit == TemporalUnit.SECOND ) {
// TiDB doesn't natively support adding fractional seconds
return "timestampadd(microsecond,?2*1e6,?3)";
}
return super.timestampaddPattern( unit, temporalType, intervalType );
}
@Override
public String timestampdiffPattern(TemporalUnit unit, TemporalType fromTemporalType, TemporalType toTemporalType) {
if ( unit == TemporalUnit.SECOND ) {
// TiDB doesn't natively support adding fractional seconds
return "timestampadd(microsecond,?2*1e6,?3)";
}
return super.timestampdiffPattern( unit, fromTemporalType, toTemporalType );
}
}