Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximizing (ordering) version number elements in Neo4j database

I have used jQAssistant to fill a Neo4j database with information about java artifacts.

Now I want to find the latest version of some artifact fulfilling some conditions. At first glance, I could use max(a.version) on the version property of an artifact. But artifact versions are not ordered by the usual String order, but actually 1.10.0 is a later version than 1.2.0.

How could I implement or use a custom ordering scheme like the one described above?

like image 953
J Fabian Meier Avatar asked Apr 17 '26 06:04

J Fabian Meier


1 Answers

How about that for version numbers (major, minor and patch) to have their nodes? Something like that:

// Major
MERGE (M0:Semver:Major {v: 0}) 
MERGE (M1:Semver:Major {v: 1})
// Minor
MERGE (Mi0: Semver:Minor {v: 0 }) 
MERGE (Mi2: Semver:Minor {v: 2 }) 
MERGE (Mi10:Semver:Minor {v: 10})
// Patch
MERGE (P0:Semver:Patch {v:0}) 
MERGE (P2:Semver:Patch {v:2})

// Artifacts
MERGE (A1:Artifact {name:'Artifact 13afd'})
MERGE (A2:Artifact {name:'Artifact asdfk'})
MERGE (A3:Artifact {name:'Artifact 09sd2'})
MERGE (A4:Artifact {name:'Artifact skw30'})

// Versioning
MERGE (A1)-[:semver]->(M0) MERGE (A1)-[:semver]->(Mi0 ) MERGE (A1)-[:semver]->(P0)
MERGE (A2)-[:semver]->(M0) MERGE (A2)-[:semver]->(Mi0 ) MERGE (A2)-[:semver]->(P2)
MERGE (A3)-[:semver]->(M1) MERGE (A3)-[:semver]->(Mi2 ) MERGE (A3)-[:semver]->(P0)
MERGE (A4)-[:semver]->(M1) MERGE (A4)-[:semver]->(Mi10) MERGE (A4)-[:semver]->(P0)

RETURN *;

enter image description here

And the desired query:

MATCH  (A:Artifact)-[:semver]->(Mj:Semver:Major),
       (A         )-[:semver]->(Mi:Semver:Minor),
       (A         )-[:semver]->(Pt:Semver:Patch)
RETURN A.name,  Mj.v,     Mi.v,     Pt.v
       ORDER BY Mj.v asc, Mi.v asc, Pt.v asc
like image 124
stdob-- Avatar answered Apr 18 '26 21:04

stdob--



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!