Skip to content

Commit

Permalink
align Ref
Browse files Browse the repository at this point in the history
Signed-off-by: qGYdXbY2 <[email protected]>
  • Loading branch information
qGYdXbY2 committed Apr 29, 2024
1 parent 4b5f5e9 commit ce4ba2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,8 @@ public void setSource(DatasetDescription source) {

Ref ref = space.getVersionRef();

if (ref != null && ref.isSingleVersion() && !ref.isHead())
export.setTargetVersion("" + ref.getVersion());
if (ref != null && !ref.isHead() && ( ref.isSingleVersion() || ref.isRange() ) )
export.setTargetVersion( ref.toString() );

export.setFilters(space.getFilters());
if (export.getFilters() != null) {
Expand Down
6 changes: 3 additions & 3 deletions xyz-models/src/main/java/com/here/xyz/models/hub/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public String toString() {
if (allVersions)
return ALL_VERSIONS;
if( isRange() )
return String.format("[%d..%d]",version, fromVersion);
return String.format("%d..%d",fromVersion,version);

return String.valueOf(version);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public long getFromVersion() {
}

public long getToVersion() {
return getVersion();
return version;
}

public boolean isHead() {
Expand All @@ -143,7 +143,7 @@ public boolean isAllVersions() {
}

public boolean isSingleVersion() {
return !isAllVersions();
return !isAllVersions() && !isRange();
}

public boolean isRange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ AND id in ( select distinct id FROM ${schema}.${table} WHERE version between #{f

private SQLQuery buildVersionComparison(SelectiveEvent event) {
Ref ref = event.getRef();

if (event.getVersionsToKeep() == 1 || ref.isAllVersions() || ref.isHead())
return new SQLQuery("");

Expand Down Expand Up @@ -205,16 +206,21 @@ private SQLQuery buildBaseVersionCheckFragment(String versionParamName) {

private SQLQuery buildMinVersionFragment(SelectiveEvent event) {
Ref ref = event.getRef();
boolean isHeadOrAllVersions = ref.isHead() || ref.isAllVersions();
long version = isHeadOrAllVersions ? Long.MAX_VALUE : ref.getVersion();

long version = Long.MAX_VALUE; // => ref.isHead() || ref.isAllVersions();

if( ref.isSingleVersion() && !ref.isHead() )
version = ref.getVersion();
else if( ref.isRange() )
version = ref.getToVersion(); // HEAD -> Long.MAX_VALUE;

if (event.getVersionsToKeep() > 1)
return new SQLQuery("AND greatest(#{minVersion}, (SELECT max(version) - #{versionsToKeep} FROM ${schema}.${table})) <= #{version}")
.withNamedParameter("versionsToKeep", event.getVersionsToKeep())
.withNamedParameter("minVersion", event.getMinVersion())
.withNamedParameter("version", version);

return isHeadOrAllVersions ? new SQLQuery("") : new SQLQuery("AND #{version} = (SELECT max(version) AS HEAD FROM ${schema}.${table})")
return version == Long.MAX_VALUE ? new SQLQuery("") : new SQLQuery("AND #{version} = (SELECT max(version) AS HEAD FROM ${schema}.${table})")
.withNamedParameter("version", version);
}

Expand Down

0 comments on commit ce4ba2c

Please sign in to comment.