HHH-16567 - Remove support for CockroachDB versions older than 22.1

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2023-05-09 00:01:15 +02:00 committed by Jan Schatteman
parent 467399437c
commit 2e97374660
3 changed files with 54 additions and 22 deletions

View File

@ -60,6 +60,7 @@ import org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor;
import org.hibernate.exception.spi.ViolatedConstraintNameExtractor; import org.hibernate.exception.spi.ViolatedConstraintNameExtractor;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.JdbcExceptionHelper;
import org.hibernate.query.SemanticException;
import org.hibernate.query.sqm.IntervalType; import org.hibernate.query.sqm.IntervalType;
import org.hibernate.query.sqm.NullOrdering; import org.hibernate.query.sqm.NullOrdering;
import org.hibernate.query.sqm.TemporalUnit; import org.hibernate.query.sqm.TemporalUnit;
@ -88,6 +89,7 @@ import org.jboss.logging.Logger;
import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate; import static org.hibernate.exception.spi.TemplatedViolatedConstraintNameExtractor.extractUsingTemplate;
import static org.hibernate.query.sqm.TemporalUnit.DAY; 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.query.sqm.TemporalUnit.NATIVE;
import static org.hibernate.type.SqlTypes.*; import static org.hibernate.type.SqlTypes.*;
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate; import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
@ -788,23 +790,53 @@ public class CockroachLegacyDialect extends Dialect {
} }
} }
else { else {
switch (unit) { if (getVersion().isSameOrAfter( 20, 1 )) {
case YEAR: switch (unit) {
return "extract(year from ?3-?2)"; case YEAR:
case QUARTER: return "extract(year from ?3-?2)";
return "(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)"; case QUARTER:
case MONTH: return "(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)";
return "(extract(year from ?3-?2)*12+extract(month from ?3-?2))"; case MONTH:
// Prior to v20, Cockroach didn't support extracting from an interval/duration, return "(extract(year from ?3-?2)*12+extract(month from ?3-?2))";
// so we use the extract_duration function case WEEK: //week is not supported by extract() when the argument is a duration
case WEEK: return "(extract(day from ?3-?2)/7)";
return "extract_duration(hour from ?3-?2)/168"; case DAY:
case DAY: return "extract(day from ?3-?2)";
return "extract_duration(hour from ?3-?2)/24"; //in order to avoid multiple calls to extract(),
case NANOSECOND: //we use extract(epoch from x - y) * factor for
return "extract_duration(microsecond from ?3-?2)*1e3"; //all the following units:
default:
return "extract_duration(?1 from ?3-?2)"; // Note that CockroachDB also has an extract_duration function which returns an int,
// but we don't use that here because it is deprecated since v20
case HOUR:
case MINUTE:
case SECOND:
case NANOSECOND:
case NATIVE:
return "cast(extract(epoch from ?3-?2)" + EPOCH.conversionFactor( unit, this ) + " as int)";
default:
throw new SemanticException( "unrecognized field: " + unit );
}
}
else {
switch (unit) {
case YEAR:
return "extract(year from ?3-?2)";
case QUARTER:
return "(extract(year from ?3-?2)*4+extract(month from ?3-?2)//3)";
case MONTH:
return "(extract(year from ?3-?2)*12+extract(month from ?3-?2))";
// Prior to v20, Cockroach didn't support extracting from an interval/duration,
// so we use the extract_duration function
case WEEK:
return "extract_duration(hour from ?3-?2)/168";
case DAY:
return "extract_duration(hour from ?3-?2)/24";
case NANOSECOND:
return "extract_duration(microsecond from ?3-?2)*1e3";
default:
return "extract_duration(?1 from ?3-?2)";
}
} }
} }
} }

View File

@ -125,7 +125,7 @@ public class CockroachDialect extends Dialect {
// Pre-compile and reuse pattern // Pre-compile and reuse pattern
private static final Pattern CRDB_VERSION_PATTERN = Pattern.compile( "v[\\d]+(\\.[\\d]+)?(\\.[\\d]+)?" ); private static final Pattern CRDB_VERSION_PATTERN = Pattern.compile( "v[\\d]+(\\.[\\d]+)?(\\.[\\d]+)?" );
protected static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 21, 1 ); protected static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 22, 1 );
protected final PostgreSQLDriverKind driverKind; protected final PostgreSQLDriverKind driverKind;

View File

@ -40,7 +40,7 @@ stage('Configure') {
// new BuildEnvironment( dbName: 'sybase_16' ), // There only is a Sybase ASE 16 image, so no pint in testing that nightly // new BuildEnvironment( dbName: 'sybase_16' ), // There only is a Sybase ASE 16 image, so no pint in testing that nightly
// Long running databases // Long running databases
new BuildEnvironment( dbName: 'cockroachdb', node: 'cockroachdb', longRunning: true ), new BuildEnvironment( dbName: 'cockroachdb', node: 'cockroachdb', longRunning: true ),
new BuildEnvironment( dbName: 'cockroachdb_21_2', node: 'cockroachdb', longRunning: true ), new BuildEnvironment( dbName: 'cockroachdb_22_1', node: 'cockroachdb', longRunning: true ),
new BuildEnvironment( dbName: 'hana_cloud', dbLockableResource: 'hana-cloud', dbLockResourceAsHost: true ) new BuildEnvironment( dbName: 'hana_cloud', dbLockableResource: 'hana-cloud', dbLockResourceAsHost: true )
]; ];
@ -226,11 +226,11 @@ stage('Build') {
sh "./docker_db.sh cockroachdb" sh "./docker_db.sh cockroachdb"
state[buildEnv.tag]['containerName'] = "cockroach" state[buildEnv.tag]['containerName'] = "cockroach"
break; break;
case "cockroachdb_21_2": case "cockroachdb_22_1":
docker.withRegistry('https://index.docker.io/v1/', 'hibernateci.hub.docker.com') { docker.withRegistry('https://index.docker.io/v1/', 'hibernateci.hub.docker.com') {
docker.image('cockroachdb/cockroach:v21.2.16').pull() docker.image('cockroachdb/cockroach:v22.1.13').pull()
} }
sh "./docker_db.sh cockroachdb_21_2" sh "./docker_db.sh cockroachdb_22_1"
state[buildEnv.tag]['containerName'] = "cockroach" state[buildEnv.tag]['containerName'] = "cockroach"
break; break;
} }