From 3f97f08037717c0c63de62ff72f5d0510c086a9d Mon Sep 17 00:00:00 2001 From: niegrzybkowski Date: Thu, 17 Jul 2025 10:22:08 +0200 Subject: [PATCH 1/2] Add a warning for unsupported logical / physical combinations --- .../jelly/cli/command/rdf/RdfToJelly.scala | 24 +++++++++++ .../cli/command/rdf/RdfToJellySpec.scala | 42 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala index 7fcde62..364a662 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala @@ -82,6 +82,7 @@ object RdfToJelly extends RdfSerDesCommand[RdfToJellyOptions, RdfFormat.Readable options.inputFormat, remainingArgs.remaining.headOption, ) + if !isQuietMode then checkAndWarnTypeCombination() override def matchFormatToAction( format: RdfFormat.Readable, @@ -191,6 +192,29 @@ object RdfToJelly extends RdfSerDesCommand[RdfToJellyOptions, RdfFormat.Readable } } + private def checkAndWarnTypeCombination(): Unit = { + val rdfStreamOptions = getOptions.jellySerializationOptions.asRdfStreamOptions + + val physicalType = rdfStreamOptions.getPhysicalType + val isPhysicalTriple = physicalType == PhysicalStreamType.TRIPLES + + val logicalType = rdfStreamOptions.getLogicalType + val logicalTripleTypes = Seq( + LogicalStreamType.GRAPHS, + LogicalStreamType.SUBJECT_GRAPHS, + LogicalStreamType.FLAT_TRIPLES, + ) + val isLogicalTriple = logicalTripleTypes.contains(logicalType) + + if isPhysicalTriple != isLogicalTriple then + printLine( + s"WARNING: Selected combination of logical/physical stream types ($logicalType/$physicalType) is unsupported. " + + "Use --quiet to silence this warning.", + true, + ) + + } + /** Check if the logical type is defined and grouped. * @param jellyOpt * the Jelly options diff --git a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala index c6cf447..6a87d9d 100644 --- a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala +++ b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala @@ -685,4 +685,46 @@ class RdfToJellySpec extends AnyWordSpec with TestFixtureHelper with Matchers: e.code should be(1) } } + + "emit a warning" when { + "requesting an unsupported logical / physical combination" in withFullJenaFile { f => + val (out, err) = + RdfToJelly.runTestCommand( + List( + "rdf", + "to-jelly", + "--opt.logical-type=SUBJECT_GRAPHS", + "--opt.physical-type=QUADS", + f, + ), + ) + err should ( + include("WARNING") and + include("unsupported") and + include("SUBJECT_GRAPHS/QUADS") + ) + } + } + + "not emit a warning" when { + "requesting an unsupported logical / physical combination with --quiet flag" in withFullJenaFile { + f => + val (out, err) = + RdfToJelly.runTestCommand( + List( + "rdf", + "to-jelly", + "--quiet", + "--opt.logical-type=SUBJECT_GRAPHS", + "--opt.physical-type=QUADS", + f, + ), + ) + err should not( + include("WARNING") and + include("unsupported") and + include("SUBJECT_GRAPHS/QUADS"), + ) + } + } } From 7ae9d44858090f1fb0bef823c6ba64939cc59525 Mon Sep 17 00:00:00 2001 From: niegrzybkowski Date: Thu, 17 Jul 2025 15:32:56 +0200 Subject: [PATCH 2/2] Change to the check to JellyOptions.checkCompatibility(x,x) --- .../jelly/cli/command/rdf/RdfToJelly.scala | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala index 364a662..85631e1 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJelly.scala @@ -8,6 +8,7 @@ import eu.neverblink.jelly.cli.command.rdf.util.RdfFormat.* import eu.neverblink.jelly.cli.util.jena.riot.JellyStreamWriterGraphs import eu.neverblink.jelly.convert.jena.JenaConverterFactory import eu.neverblink.jelly.convert.jena.riot.{JellyFormatVariant, JellyLanguage, JellyStreamWriter} +import eu.neverblink.jelly.core.{JellyOptions, RdfProtoDeserializationError} import eu.neverblink.jelly.core.proto.google.v1 as google import eu.neverblink.jelly.core.proto.v1.{LogicalStreamType, PhysicalStreamType, RdfStreamOptions} import org.apache.jena.riot.lang.LabelToNode @@ -193,26 +194,23 @@ object RdfToJelly extends RdfSerDesCommand[RdfToJellyOptions, RdfFormat.Readable } private def checkAndWarnTypeCombination(): Unit = { - val rdfStreamOptions = getOptions.jellySerializationOptions.asRdfStreamOptions + val rdfStreamOptions = getOptions.jellySerializationOptions.asRdfStreamOptions val physicalType = rdfStreamOptions.getPhysicalType - val isPhysicalTriple = physicalType == PhysicalStreamType.TRIPLES - val logicalType = rdfStreamOptions.getLogicalType - val logicalTripleTypes = Seq( - LogicalStreamType.GRAPHS, - LogicalStreamType.SUBJECT_GRAPHS, - LogicalStreamType.FLAT_TRIPLES, - ) - val isLogicalTriple = logicalTripleTypes.contains(logicalType) - - if isPhysicalTriple != isLogicalTriple then - printLine( - s"WARNING: Selected combination of logical/physical stream types ($logicalType/$physicalType) is unsupported. " + - "Use --quiet to silence this warning.", - true, - ) + try { + // This check will find physical/logical clashes, since all other fields are checked with <=, + // so they pass when compared against themselves + JellyOptions.checkCompatibility(rdfStreamOptions, rdfStreamOptions) + } catch { + case _: RdfProtoDeserializationError => + printLine( + s"WARNING: Selected combination of logical/physical stream types ($logicalType/$physicalType) is unsupported. " + + "Use --quiet to silence this warning.", + true, + ) + } } /** Check if the logical type is defined and grouped.