[xquery-talk] Multiple output via a stream of filters
dlee at calldei.com
Mon Jan 13 19:42:09 PST 2014
A Single XQuery invocation has only one "output stream" ... but when your working in a database often you don't need any, you want to put the data back into the database.
Functions don't have "streams" really either although the word is overloaded.
One way it to produce a "sequence" of results which you then do something with, either output in the main output or store into the database (as separate documents).
Also I believe eXist has functions for writing to files so your question my have more relevance on the exists mailing list.
But if what I think you mean by "stream" is a long result ... and your dealing with GB+ data you need to be very careful,
True "streaming" is very hard to achieve in XQuery. Functions don't "stream" they return values.
XPath doesn't "stream" ... there is no real "streams" in XQuery ... so if your not careful you end up with having to hold the entire result set in memory.
But if your output is to the 'main' output (is this an HTTP call ?) you might be able to stream to it .. all depends on the vendor implementation.
I suspect what your really after is to write multiple results to either documents or files.
XQuery doesn't support this generically but XML Databases like eXist do so you might want to ask there.
Or I may have completely misunderstood your question.
David A. Lee
dlee at calldei.com
From: Ihe Onwuka [mailto:ihe.onwuka at gmail.com]
Sent: Monday, January 13, 2014 4:56 PM
To: David Lee
Cc: talk at x-query.com
Subject: Re: [xquery-talk] Multiple output via a stream of filters
If it helps think of an entity that entails a bazillion fields like a credit card application and you have multiple ways you wish to classify it. So you have a filter for each classification scheme and the application "filters" through to the output stream of whichever predicates return true.
On Tue, Jan 14, 2014 at 12:38 AM, David Lee <dlee at calldei.com> wrote:
> Could you define what you mean by "output" ?
> David A. Lee
> dlee at calldei.com
> -----Original Message-----
> From: Ihe Onwuka [mailto:ihe.onwuka at gmail.com]
> Sent: Monday, January 13, 2014 4:19 PM
> To: David Lee
> Cc: talk at x-query.com
> Subject: Re: [xquery-talk] Multiple output via a stream of filters
> On Mon, Jan 13, 2014 at 11:54 PM, David Lee <dlee at calldei.com> wrote:
>> If your running in exist then pure XQuery is probably as good or better then anything else.
>> Could you expand on your problem ?
> I have a collection. Suppose I have 10 different outputs I want and the decision as to which output a node is routed to (not necessarily mutual exclusive though) can be encapsulated in a predicate (hence amenable to a filter HOF).
> I only want to iterate over the collection once but I wish to apply the 10 predicates to each node in the sequence so as to determine which of the 10 outputs (again not necessarily mutually exclusive) the node will feature in.
> The algorithm is straightforward using structural recursion (or tail recursion if tail call elimination is an issue). Asking whether there is an idiomatic XQuery solution that is different from this.
More information about the talk