Skip to content

Commit

Permalink
Stabilize statement order in Jelly distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ostrzyciel committed Sep 17, 2024
1 parent 6411d77 commit a5bacbf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/commands/PackageCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,11 @@ object PackageCommand extends Command:
val serializeFlow = (
if metadata.streamTypes.exists(_.elementType == ElementType.Triple) then
Flow[(DatasetGraph, Long)]
.map((ds, _) => ds.getDefaultGraph.asTriples)
.map((ds, _) => ds.getDefaultGraph.asTriples.toSeq.sorted)
.via(EncoderFlow.graphStream(None, jOpt))
else
Flow[(DatasetGraph, Long)]
.map((ds, _) => ds.asQuads)
.map((ds, _) => ds.asQuads.toSeq.sorted)
.via(EncoderFlow.datasetStreamFromQuads(None, jOpt))
)
.via(JellyIo.toBytesDelimited)
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/util/RdfOrdering.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package io.github.riverbench.ci_worker
package util

import org.apache.jena.graph.Triple
import org.apache.jena.sparql.core.Quad

object RdfOrdering:

given Ordering[Triple] with
override def compare(x: Triple, y: Triple): Int =
val cmpSubject = x.getSubject.toString.compareTo(y.getSubject.toString)
if cmpSubject != 0 then cmpSubject
else
val cmpPredicate = x.getPredicate.toString.compareTo(y.getPredicate.toString)
if cmpPredicate != 0 then cmpPredicate
else
x.getObject.toString.compareTo(y.getObject.toString)

given Ordering[Quad] with
def compare(x: Quad, y: Quad): Int =
val cmpGraph = x.getGraph.toString.compareTo(y.getGraph.toString)
if cmpGraph != 0 then cmpGraph
else
// Repeated code because Quad and Triple don't implement a common interface
val cmpSubject = x.getSubject.toString.compareTo(y.getSubject.toString)
if cmpSubject != 0 then cmpSubject
else
Expand Down

0 comments on commit a5bacbf

Please sign in to comment.