Skip to content

Commit

Permalink
Merge pull request #8405 from soerenreichardt/adjust-to-new-arrow-str…
Browse files Browse the repository at this point in the history
…eam-command

Adjust write-back to new arrow stream command
  • Loading branch information
soerenreichardt authored Nov 17, 2023
2 parents 419380f + eb3caf8 commit 53ace2d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 72 deletions.
147 changes: 76 additions & 71 deletions neo4j-adapter/src/main/java/org/neo4j/gds/compat/Neo4jVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,81 +41,11 @@ public enum Neo4jVersion {
V_5_11,
V_5_12,
V_5_13,
V_5_14,
V_Dev;

private static final int MINOR_DEV_VERSION = 14;

@Override
public String toString() {
switch (this) {
case V_4_4:
return "4.4";
case V_5_6:
return "5.6";
case V_5_7:
return "5.7";
case V_5_8:
return "5.8";
case V_5_9:
return "5.9";
case V_5_10:
return "5.10";
case V_5_11:
return "5.11";
case V_5_12:
return "5.12";
case V_5_13:
return "5.13";
case V_Dev:
return "dev";
default:
throw new IllegalArgumentException("Unexpected value: " + this.name() + " (sad java 😞)");
}
}

public MajorMinorVersion semanticVersion() {
if (this == V_Dev) {
return ImmutableMajorMinorVersion.of(5, MINOR_DEV_VERSION);
}

String version = toString();
var subVersions = version.split("\\.");

if (subVersions.length < 2) {
throw new IllegalStateException("Cannot derive version from " + version);
}

return ImmutableMajorMinorVersion.of(Integer.parseInt(subVersions[0]), Integer.parseInt(subVersions[1]));
}

public static Neo4jVersion findNeo4jVersion() {
return Neo4jVersionHolder.VERSION;
}

private static final class Neo4jVersionHolder {
private static final Neo4jVersion VERSION = parse(neo4jVersion());
}

static String neo4jVersion() {
var neo4jVersion = Objects.requireNonNullElse(Version.class.getPackage().getImplementationVersion(), "dev");
// some versions have a build thing attached at the end
// e.g. 4.0.8,8e921029f7daebacc749034f0cb174f1f2c7a258
// This regex follows the logic from org.neo4j.kernel.internal.Version.parseReleaseVersion
Pattern pattern = Pattern.compile(
"(\\d+" + // Major version
"\\.\\d+" + // Minor version
"(\\.\\d+)?" + // Optional patch version
"(-?[^,]+)?)" + // Optional marker, like M01, GA, SNAPSHOT - anything other than a comma
".*" // Anything else, such as git revision
);
var matcher = pattern.matcher(neo4jVersion);
if (matcher.find()) {
return matcher.group(1);
}
// If no match is found, return the full version.
return neo4jVersion;
}

static Neo4jVersion parse(String version) {
var versionSegments = Pattern.compile("[.-]")
.splitAsStream(version)
Expand Down Expand Up @@ -155,6 +85,8 @@ static Neo4jVersion parse(String version) {
return Neo4jVersion.V_5_12;
case 13:
return Neo4jVersion.V_5_13;
case 14:
return Neo4jVersion.V_5_14;
default:
if (minorVersion >= MINOR_DEV_VERSION) {
return Neo4jVersion.V_Dev;
Expand All @@ -165,6 +97,79 @@ static Neo4jVersion parse(String version) {
throw new UnsupportedOperationException("Cannot run on Neo4j Version " + version);
}

public MajorMinorVersion semanticVersion() {
if (this == V_Dev) {
return ImmutableMajorMinorVersion.of(5, MINOR_DEV_VERSION);
}

String version = toString();
var subVersions = version.split("\\.");

if (subVersions.length < 2) {
throw new IllegalStateException("Cannot derive version from " + version);
}

return ImmutableMajorMinorVersion.of(Integer.parseInt(subVersions[0]), Integer.parseInt(subVersions[1]));
}

public static Neo4jVersion findNeo4jVersion() {
return Neo4jVersionHolder.VERSION;
}

private static final class Neo4jVersionHolder {
private static final Neo4jVersion VERSION = parse(neo4jVersion());
}

static String neo4jVersion() {
var neo4jVersion = Objects.requireNonNullElse(Version.class.getPackage().getImplementationVersion(), "dev");
// some versions have a build thing attached at the end
// e.g. 4.0.8,8e921029f7daebacc749034f0cb174f1f2c7a258
// This regex follows the logic from org.neo4j.kernel.internal.Version.parseReleaseVersion
Pattern pattern = Pattern.compile(
"(\\d+" + // Major version
"\\.\\d+" + // Minor version
"(\\.\\d+)?" + // Optional patch version
"(-?[^,]+)?)" + // Optional marker, like M01, GA, SNAPSHOT - anything other than a comma
".*" // Anything else, such as git revision
);
var matcher = pattern.matcher(neo4jVersion);
if (matcher.find()) {
return matcher.group(1);
}
// If no match is found, return the full version.
return neo4jVersion;
}

@Override
public String toString() {
switch (this) {
case V_4_4:
return "4.4";
case V_5_6:
return "5.6";
case V_5_7:
return "5.7";
case V_5_8:
return "5.8";
case V_5_9:
return "5.9";
case V_5_10:
return "5.10";
case V_5_11:
return "5.11";
case V_5_12:
return "5.12";
case V_5_13:
return "5.13";
case V_5_14:
return "5.14";
case V_Dev:
return "dev";
default:
throw new IllegalArgumentException("Unexpected value: " + this.name() + " (sad java 😞)");
}
}

@ValueClass
public interface MajorMinorVersion {
int major();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Neo4jVersionTest {
"5.11.0, V_5_11",
"5.12.0, V_5_12",
"5.13.0, V_5_13",
"5.14.0, V_Dev",
"5.14.0, V_5_14",
"5.15.0, V_Dev",
})
void testParse(String input, Neo4jVersion expected) {
assertEquals(expected.name(), Neo4jVersion.parse(input).name());
Expand Down

0 comments on commit 53ace2d

Please sign in to comment.