Query failed with dynamic error: Cannot serialize a map using this output method - saxon

This has to be a noob issue, as I'm just starting with XQuery. I was successfully able to build a simple XQuery for eXist that runs an XSL transform. But I have been unsuccessful in building a similar XQuery for Saxon (9.9.1.5J) that runs an XSL transform.
Working XQuery for eXist:
xquery version "3.0";
transform:transform(doc("sample.xml"), doc("sample.xsl"), ())
Failing XQuery for Saxon:
xquery version "3.1";
transform(map{'source-node': doc('sample.xml'),'stylesheet-node':doc('sample.xsl')})
The error reported by Saxon is:
Query failed with dynamic error: Cannot serialize a map using this
output method
I've searched Google and SO for this error, but get nothing. I have tried it with and without the output declaration, and with and without an output declaration in the XSL. I've tried it with fn:transform() and transform(). I put in a declaration for the fn namespace too. The transform works from the Saxon command line and from eXist. So I must be missing something simple about the building of the map for the options to fn:transform().

The result of the fn:transform() function is a map, and it looks like you are running the query in a way where the query result gets serialized using the default XML output method. Trying to serialize a map using the XML output method will fail.
There are several things you could do, depending what exactly you want to achieve. The simplest fix might be to change the body of the query to
transform(map{'source-node': doc('sample.xml'),'stylesheet-node':doc('sample.xsl')})
? output
in which case the result will be the principal result document of the transformation, which is probably what you are most interested in.

Related

XSLT - Saxon malformed URL unknown protocol: xmldb

In eXist 4.4/XQuery 3.1 I perform an XSL 2.0 transformation using transform:transform(). In the transformation I pass a parameter into the XSL transformation for Saxon to use to access information in the database.
<param name="paramSaxondatapath" value="xmldb:exist:///db/apps/deheresi/data/"/>
Everything works great: Saxon retrieves the nodes needed from documents in eXist-DB and the XSL transformation is successful.
Now, I am trying to do execute the same but from outside the eXist-DB environment (local drive, using Oxygen). Thus, in the XSLT document I have hardcoded the parameter:
<xsl:param name="paramSaxondatapath">xmldb:exist:///db/apps/deheresi/data/</xsl:param>
Yet when I fire this XSLT file off locally (in Oxygen, local XSLT file, Saxon-HE 9.6.0.7), Saxon throws me an exception unknown protocol: xmldb
FODC0002: Exception thrown by URIResolver:
Malformed URL
xmldb:exist:///db/apps/deheresi/data/bibliography.xml
(base file:/Users/foo/Desktop/De_Heresi/deheresi_TEI/fo_dep_single.xsl):
unknown protocol: xmldb
Considering that this is passed to Saxon in identical manner (ie wrapped in doc(concat(paramSaxondatapath,'somefile.xml')), I'm surprised this isn't reacting the same way both times.
Is there a different URI I should be using?
Many thanks.
EDIT: Curiously, if I use command line for the transformation (ie not triggered by Oxygen), Saxon accepts it and performs the transformation. It appears to have something to do with Oxygen...
My guess is that when eXist invokes Saxon, it sets a URIResolver that recognizes URIs with the "xmldb:exist:" prefix and handles them itself. Outside the eXist environment, you would need to supply your own URIResolver that does something similar - connects to the database and retrieves the required document.

Apache Beam and avro : Create a dataflow pipeline without schema

I am building a dataflow pipeline with Apache beam. Below is the pseudo code:
PCollection<GenericRecord> rows = pipeline.apply("Read Json from PubSub", <some reader>)
.apply("Convert Json to pojo", ParDo.of(new JsonToPojo()))
.apply("Convert pojo to GenericRecord", ParDo.of(new PojoToGenericRecord()))
.setCoder(AvroCoder.of(GenericRecord.class, schema));
I am trying to get rid of setting the coder in the pipeline as schema won't be known at pipeline creation time (it will be present in the message).
I commented out the line that sets the coder and got an Exception saying that default coder is not configured. I used one argument version of of method and got the following Exception:
Not a Specific class: interface org.apache.avro.generic.GenericRecord
at org.apache.avro.specific.SpecificData.createSchema(SpecificData.java:285)
at org.apache.avro.reflect.ReflectData.createSchema(ReflectData.java:594)
at org.apache.avro.specific.SpecificData$2.load(SpecificData.java:218)
at org.apache.avro.specific.SpecificData$2.load(SpecificData.java:215)
at avro.shaded.com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3568)
at avro.shaded.com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2350)
at avro.shaded.com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2313)
at avro.shaded.com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2228)
... 9 more
Is there any way for us to supply the coder at runtime, without knowing the schema beforehand?
This is possible. I recommend the following approach:
Do not use an intermediate collection of type GenericRecord. Keep it as a collection of your POJOs.
Write some transform that extracts the schema of your data and makes it available as a PCollectionView<however you want to represent the schema>.
When writing to BigQuery, write your PCollection<YourPojo> via write().to(DynamicDestinations), and when writing to Avro, use FileIO.write() or writeDynamic() in combination with AvroIO.sinkViaGenericRecords(). Both of these can take a dynamically computed schema from a side input (that you computed above).

Machine parseable error messages

(From https://groups.google.com/d/msg/bazel-discuss/cIBIP-Oyzzw/caesbhdEAAAJ)
What is the recommended way for rules to export information about failures such that downstream tools can include them in UIs.
Example use case:
I ran bazel test //my:target, and one of the actions for //my:target fails because there is an unknown variable "usrname" in my/target.foo at line 7 column 10. It would also like to report that "username" is a valid variable and this is a possible misspelling. And thus wants to suggest an addition of an "e" character.
One way I have thought to do this is to have a separate file that my action produces //my:target.errors that is in a separate output group and have it write machine parseable data there in addition to human readable data on stdout.
I can then find all of these files and parse the data in them in downstream tools.
Is there any prior work on this, or does everything just try to parse the human readable output?
I recommend running the error checkers as extra actions.
I don't think Bazel currently has hooks for custom error handlers like you describe. Please consider opening a feature request: https://github.com/bazelbuild/bazel/issues/new

Jenkins Dynamic Combination Matrix

I've been using the option Restrict matrix execution to a subset from the Parameterized Trigger Plugin to pass on a combination filter to a rather large Matrix Project where all test execution is made. As the number of tests grow, so does the combination filter (which is dynamically built up) and I seemed to hit the cap. The following job gets this error message:
FATAL: Invalid method Code length 69871 in class file Script1
java.lang.ClassFormatError: Invalid method Code length 69871 in class file Script1
After reading about this problem, it seems to be a JVM constraint after reading the JVM documentation
The value of the code_length item must be less than 65536.
I get the impression that this is not something I can (or even should) tinker with in Jenkins.
My second idea was to go around this problem was to create the combination filter and then pass it as String parameter to the following Matrix Project, then use the Combination Filter option and expand the variable to achieve the same result.
Unfortunately I get this exception when trying to save my Matrix Project with a String parameter as combination filter
javax.servlet.ServletException: groovy.lang.MissingPropertyException: No such property: $COMBINATION_FILTER for class: groovy.lang.Binding
I guess this is because the variable needs to be available in the configuration when saving but I want to inject it when starting the Matrix Project.
I am running out of ideas to solve this problem. Any ideas?
You could try the Matrix Groovy Execution Strategy which is like a super combination filter
If I can quote myself
A plugin to decide the execution order and valid combinations of
matrix projects.
This uses a user defined groovy script to arrange the order which will
then be executed
Disclaimer: I built this plugin

NullPointerException in saxon IdentityTransformer.transform when extracting data from javax DOMSource

I am using Spring Webservice (2.1.0) Client to send a very simple Message to a Soap UI Mock Webservice. (Hello World style, no namespaces)
Before Sending the DOMSource via the SpringWebserviceTemplate it is extracted from
a jdom2.Element as jdom2.transform.JDOMSource. (JDOM 2.0.2)
The Transformer is Saxon 9.4.0.4.
While calling the Spring Webservice Template function sendSourceAndReceiveToResult
the net.sf.saxon.IdentityTransformer throws a NullPointerException when executing
the transform(DOMSource,responseResult) function.
Since DOMSource is available at that point I do not know what could have gone wrong.
Stacktrace tells me the Nullpointer was thrown at:
net.sf.saxon.lib.SerializerFactory.getReceiver (line 239).
It would help me greatly if you could speculate on possible causes.
Please note that the best way of reporting a Saxon problem is to use either the Saxon forums at http://saxonica.plan.io, or the saxon-help mailing list on SourceForge. We try to monitor questions on StackOverflow, but it's often a few days before we notice them.
With this kind of problem, the cause is often that some piece of software (like Spring Webservice) is using the JAXP TransformerFactory mechanism to load whatever XSLT transformer it finds on the classpath, but hasn't actually done the testing to ensure that it works with an arbitrary XSLT transformer; people often test only with the default one provided by the JDK. It's not clear from your question whether you actually intended for it to use Saxon or not.
Line 239 of SerializerFactory is actually doing
throw new IllegalArgumentException("Unknown type of result: " + result.getClass());
(having tested whether result is one of the kinds of Result that it recognizes); so it looks to me as if result (which is probably the value passed to the transform() method) is null. Check the contents of your responseResult value.

Resources