Reporting function for a subset
Monday, 13 July 2015 · 11 messages · last reply 14 Jul 2015
ME
Menashè Eliezer13 Jul 2015 17:33 #
Hello,
I want to call a reporting function with a subset of documents created inside a loop which will return a xml report.
I couldn't find information how and if can it be done.
The idea is that there is a main query which results in a subset. Then I want to make different processing only on this subset without making a query on the whole collection with the filters, as I've already done in the main query.
The all-in-one query will actually return inside my own xml the results of the different functions.
Is it possible?
--
With kind regards,
Menashè
CG
Christian Grün14 Jul 2015 09:30 #
Hi Menashè,
Quoted text · Menashè Eliezer · 1 line
> Is it possible?
Yes, it should be, because you can do nearly everything in XQuery.. However, I must confess I have no idea how to help you right now.. What about the reporting function, does it already exist? What is a subset: Is it a sequence of XML nodes resulting from a path
expression? Could you possibly provide us with some code you have written so far?
Christian
Quoted text · Menashè Eliezer · 17 lines
On Mon, Jul 13, 2015 at 5:33 PM, Menashè Eliezer <meliezer at ogs.trieste.it> wrote: > Hello, > I want to call a reporting function with a subset of documents created > inside a loop which will return a xml report. > I couldn't find information how and if can it be done. > The idea is that there is a main query which results in a subset. Then I > want to make different processing only on this subset without making a query > on the whole collection with the filters, as I've already done in the main > query. > The all-in-one query will actually return inside my own xml the results of > the different functions. > > -- > With kind regards, > Menashè >
ME
Menashè Eliezer14 Jul 2015 11:08 #
Hi Christian,
Quoted text · Christian Grün · 5 lines
On 07/14/2015 09:30 AM, Christian Grün wrote: > What about the reporting function, does it already exist? What is a > subset: Is it a sequence of XML nodes resulting from a path > expression? Could you possibly provide us with some code you have > written so far? Christian
I mean a sequence of XML nodes resulting from a 'for' loop. Then there are queries that for the same filters (or with a single extra condition) return different xml results.
For example: "group by" and time distribution table per year and month.
With kind regards,
Menashè
CG
Christian Grün14 Jul 2015 11:09 #
Quoted text · Menashè Eliezer · 4 lines
> I mean a sequence of XML nodes resulting from a 'for' loop. Then there are > queries that for the same filters (or with a single extra condition) return > different xml results. > For example: "group by" and time distribution table per year and month.
Well, I'll just say it's possible ;) Feel free to provide us with more code.
ME
Menashè Eliezer14 Jul 2015 11:40 #
Hi,
The initial of the code should be modified, so here is only the essence of one of the pivoting reports:
for $singleDataType in $dataType
for $singleDevice in $device
for $singleAvailability in $availability
for $singleCountry in $country
for $singleParameter in $parametergroup by
$singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter order by
$singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter
return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}"
Availability="{$singleAvailability}" Country="{$singleCountry}"
Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/>Other report will count all records with one less condition:
group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry
order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry
return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}"
Availability="{$singleAvailability}" Country="{$singleCountry}"
Parameter="Any" NumberOfRecords="{count($current-pre)}"/>I hope it's clear.
With kind regards,
Menashè
CG
Christian Grün14 Jul 2015 12:30 #
Quoted text · Menashè Eliezer · 1 line
> I hope it's clear.
Sorry, I'm still confuzzled. What is the problem? I guess you want to define different, exchangable reporting functions for more or less the same input (dataType, device, ...)?
Here is one way to define functions and call them in a second step:
let $add := function($a, $b) { $a + $b }
let $multiply := function($a, $b) { $a * $b }
for $function in ($add, $multiply)
return $function(3, 5)
Instead of $add and $multiply, you could have $report-pivoting and
$report-count.Quoted text · Menashè Eliezer · 39 lines
On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer <meliezer at ogs.trieste.it> wrote: > Hi, > The initial of the code should be modified, so here is only the essence of > one of the pivoting reports: > for $singleDataType in $dataType > > for $singleDevice in $device > > for $singleAvailability in $availability > > for $singleCountry in $country > > for $singleParameter in $parameter > > group by > $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter > order by > $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter > > return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" > Availability="{$singleAvailability}" Country="{$singleCountry}" > Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/> > > Other report will count all records with one less condition: > > group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry > order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry > > return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" > Availability="{$singleAvailability}" Country="{$singleCountry}" > Parameter="Any" NumberOfRecords="{count($current-pre)}"/> > > I hope it's clear. > > With kind regards, > Menashè > >
ME
Menashè Eliezer14 Jul 2015 12:41 #
Thank you, but would you please show me how to pass (only once) for each function the xml sequence which results from my main query, instead of simple numbers as in your example?
With kind regards,
Menashè
Quoted text · Christian Grün · 57 lines
On 07/14/2015 12:30 PM, Christian Grün wrote: >> I hope it's clear. > Sorry, I'm still confuzzled. What is the problem? I guess you want to > define different, exchangable reporting functions for more or less the > same input (dataType, device, ...)? > > Here is one way to define functions and call them in a second step: > > let $add := function($a, $b) { $a + $b } > let $multiply := function($a, $b) { $a * $b } > for $function in ($add, $multiply) > return $function(3, 5) > > Instead of $add and $multiply, you could have $report-pivoting and > $report-count. > > > > On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: >> Hi, >> The initial of the code should be modified, so here is only the essence of >> one of the pivoting reports: >> for $singleDataType in $dataType >> >> for $singleDevice in $device >> >> for $singleAvailability in $availability >> >> for $singleCountry in $country >> >> for $singleParameter in $parameter >> >> group by >> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >> order by >> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >> >> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >> Availability="{$singleAvailability}" Country="{$singleCountry}" >> Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/> >> >> Other report will count all records with one less condition: >> >> group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >> order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >> >> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >> Availability="{$singleAvailability}" Country="{$singleCountry}" >> Parameter="Any" NumberOfRecords="{count($current-pre)}"/> >> >> I hope it's clear. >> >> With kind regards, >> Menashè >> >>
CG
Christian Grün14 Jul 2015 12:51 #
E.g. like that:
let $count := function($nodes) { count($nodes) }
let $nodes := (<a/>, <b/>)
return $count($nodes)Quoted text · Menashè Eliezer · 74 lines
On Tue, Jul 14, 2015 at 12:41 PM, Menashè Eliezer <meliezer at ogs.trieste.it> wrote: > Thank you, but would you please show me how to pass (only once) for each > function the xml sequence which results from my main query, instead of > simple numbers as in your example? > > With kind regards, > Menashè > > > On 07/14/2015 12:30 PM, Christian Grün wrote: >>> >>> I hope it's clear. >> >> Sorry, I'm still confuzzled. What is the problem? I guess you want to >> define different, exchangable reporting functions for more or less the >> same input (dataType, device, ...)? >> >> Here is one way to define functions and call them in a second step: >> >> let $add := function($a, $b) { $a + $b } >> let $multiply := function($a, $b) { $a * $b } >> for $function in ($add, $multiply) >> return $function(3, 5) >> >> Instead of $add and $multiply, you could have $report-pivoting and >> $report-count. >> >> >> >> On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer >> <meliezer at ogs.trieste.it> wrote: >>> >>> Hi, >>> The initial of the code should be modified, so here is only the essence >>> of >>> one of the pivoting reports: >>> for $singleDataType in $dataType >>> >>> for $singleDevice in $device >>> >>> for $singleAvailability in $availability >>> >>> for $singleCountry in $country >>> >>> for $singleParameter in $parameter >>> >>> group by >>> >>> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >>> order by >>> >>> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >>> >>> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >>> Availability="{$singleAvailability}" Country="{$singleCountry}" >>> Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/> >>> >>> Other report will count all records with one less condition: >>> >>> group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >>> order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >>> >>> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >>> Availability="{$singleAvailability}" Country="{$singleCountry}" >>> Parameter="Any" NumberOfRecords="{count($current-pre)}"/> >>> >>> I hope it's clear. >>> >>> With kind regards, >>> Menashè >>> >>> >
ME
Menashè Eliezer14 Jul 2015 12:55 #
I'm sorry, but it's not clear how $nodes can include the result of my main query:
xquery version "3.0"; declare option output:item-separator ",";
let $db := db:open("CDI")
for $x in $db
let $beginPosition := $x//startTime
let $lon := xs:float($x//longitudine)
let $lat := xs:float($x//latitudine)
where
$beginPosition>="1889-01-01" and $beginPosition<="2015-07-10"
and $lat<=46.733 and $lat>=-67.81
and $lon<=72.7006667 and $lon >=-79.9666667
return $xWith kind regards,
Menashè
Quoted text · Christian Grün · 79 lines
On 07/14/2015 12:51 PM, Christian Grün wrote: > E.g. like that: > > let $count := function($nodes) { count($nodes) } > let $nodes := (<a/>, <b/>) > return $count($nodes) > > > > On Tue, Jul 14, 2015 at 12:41 PM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: >> Thank you, but would you please show me how to pass (only once) for each >> function the xml sequence which results from my main query, instead of >> simple numbers as in your example? >> >> With kind regards, >> Menashè >> >> >> On 07/14/2015 12:30 PM, Christian Grün wrote: >>>> I hope it's clear. >>> Sorry, I'm still confuzzled. What is the problem? I guess you want to >>> define different, exchangable reporting functions for more or less the >>> same input (dataType, device, ...)? >>> >>> Here is one way to define functions and call them in a second step: >>> >>> let $add := function($a, $b) { $a + $b } >>> let $multiply := function($a, $b) { $a * $b } >>> for $function in ($add, $multiply) >>> return $function(3, 5) >>> >>> Instead of $add and $multiply, you could have $report-pivoting and >>> $report-count. >>> >>> >>> >>> On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer >>> <meliezer at ogs.trieste.it> wrote: >>>> Hi, >>>> The initial of the code should be modified, so here is only the essence >>>> of >>>> one of the pivoting reports: >>>> for $singleDataType in $dataType >>>> >>>> for $singleDevice in $device >>>> >>>> for $singleAvailability in $availability >>>> >>>> for $singleCountry in $country >>>> >>>> for $singleParameter in $parameter >>>> >>>> group by >>>> >>>> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >>>> order by >>>> >>>> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >>>> >>>> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >>>> Availability="{$singleAvailability}" Country="{$singleCountry}" >>>> Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/> >>>> >>>> Other report will count all records with one less condition: >>>> >>>> group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >>>> order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >>>> >>>> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >>>> Availability="{$singleAvailability}" Country="{$singleCountry}" >>>> Parameter="Any" NumberOfRecords="{count($current-pre)}"/> >>>> >>>> I hope it's clear. >>>> >>>> With kind regards, >>>> Menashè >>>> >>>>
CG
Christian Grün14 Jul 2015 12:56 #
What about this?
let $nodes :=
let $db := db:open("CDI")
for $x in $db
let $beginPosition := $x//startTime
let $lon := xs:float($x//longitudine)
let $lat := xs:float($x//latitudine)
where
$beginPosition>="1889-01-01" and $beginPosition<="2015-07-10"
and $lat<=46.733 and $lat>=-67.81
and $lon<=72.7006667 and $lon >=-79.9666667
return $xreturn ...
Quoted text · Menashè Eliezer · 106 lines
On Tue, Jul 14, 2015 at 12:55 PM, Menashè Eliezer <meliezer at ogs.trieste.it> wrote: > I'm sorry, but it's not clear how $nodes can include the result of my main > query: > > xquery version "3.0"; declare option output:item-separator ","; > let $db := db:open("CDI") > for $x in $db > let $beginPosition := $x//startTime > let $lon := xs:float($x//longitudine) > let $lat := xs:float($x//latitudine) > > where > $beginPosition>="1889-01-01" and $beginPosition<="2015-07-10" > and $lat<=46.733 and $lat>=-67.81 > and $lon<=72.7006667 and $lon >=-79.9666667 > return $x > > With kind regards, > Menashè > > On 07/14/2015 12:51 PM, Christian Grün wrote: > > E.g. like that: > > let $count := function($nodes) { count($nodes) } > let $nodes := (<a/>, <b/>) > return $count($nodes) > > > > On Tue, Jul 14, 2015 at 12:41 PM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: > > Thank you, but would you please show me how to pass (only once) for each > function the xml sequence which results from my main query, instead of > simple numbers as in your example? > > With kind regards, > Menashè > > > On 07/14/2015 12:30 PM, Christian Grün wrote: > > I hope it's clear. > > Sorry, I'm still confuzzled. What is the problem? I guess you want to > define different, exchangable reporting functions for more or less the > same input (dataType, device, ...)? > > Here is one way to define functions and call them in a second step: > > let $add := function($a, $b) { $a + $b } > let $multiply := function($a, $b) { $a * $b } > for $function in ($add, $multiply) > return $function(3, 5) > > Instead of $add and $multiply, you could have $report-pivoting and > $report-count. > > > > On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: > > Hi, > The initial of the code should be modified, so here is only the essence > of > one of the pivoting reports: > for $singleDataType in $dataType > > for $singleDevice in $device > > for $singleAvailability in $availability > > for $singleCountry in $country > > for $singleParameter in $parameter > > group by > > $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter > order by > > $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter > > return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" > Availability="{$singleAvailability}" Country="{$singleCountry}" > Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/> > > Other report will count all records with one less condition: > > group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry > order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry > > return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" > Availability="{$singleAvailability}" Country="{$singleCountry}" > Parameter="Any" NumberOfRecords="{count($current-pre)}"/> > > I hope it's clear. > > With kind regards, > Menashè > > >
ME
Menashè Eliezer14 Jul 2015 14:42 #
Thank you for the helpful ideas!
With kind regards,
Menashè
Quoted text · Christian Grün · 125 lines
On 07/14/2015 12:56 PM, Christian Grün wrote: > What about this? > > let $nodes := > let $db := db:open("CDI") > for $x in $db > let $beginPosition := $x//startTime > let $lon := xs:float($x//longitudine) > let $lat := xs:float($x//latitudine) > > where > $beginPosition>="1889-01-01" and $beginPosition<="2015-07-10" > and $lat<=46.733 and $lat>=-67.81 > and $lon<=72.7006667 and $lon >=-79.9666667 > return $x > > return ... > > > On Tue, Jul 14, 2015 at 12:55 PM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: >> I'm sorry, but it's not clear how $nodes can include the result of my main >> query: >> >> xquery version "3.0"; declare option output:item-separator ","; >> let $db := db:open("CDI") >> for $x in $db >> let $beginPosition := $x//startTime >> let $lon := xs:float($x//longitudine) >> let $lat := xs:float($x//latitudine) >> >> where >> $beginPosition>="1889-01-01" and $beginPosition<="2015-07-10" >> and $lat<=46.733 and $lat>=-67.81 >> and $lon<=72.7006667 and $lon >=-79.9666667 >> return $x >> >> With kind regards, >> Menashè >> >> On 07/14/2015 12:51 PM, Christian Grün wrote: >> >> E.g. like that: >> >> let $count := function($nodes) { count($nodes) } >> let $nodes := (<a/>, <b/>) >> return $count($nodes) >> >> >> >> On Tue, Jul 14, 2015 at 12:41 PM, Menashè Eliezer >> <meliezer at ogs.trieste.it> wrote: >> >> Thank you, but would you please show me how to pass (only once) for each >> function the xml sequence which results from my main query, instead of >> simple numbers as in your example? >> >> With kind regards, >> Menashè >> >> >> On 07/14/2015 12:30 PM, Christian Grün wrote: >> >> I hope it's clear. >> >> Sorry, I'm still confuzzled. What is the problem? I guess you want to >> define different, exchangable reporting functions for more or less the >> same input (dataType, device, ...)? >> >> Here is one way to define functions and call them in a second step: >> >> let $add := function($a, $b) { $a + $b } >> let $multiply := function($a, $b) { $a * $b } >> for $function in ($add, $multiply) >> return $function(3, 5) >> >> Instead of $add and $multiply, you could have $report-pivoting and >> $report-count. >> >> >> >> On Tue, Jul 14, 2015 at 11:40 AM, Menashè Eliezer >> <meliezer at ogs.trieste.it> wrote: >> >> Hi, >> The initial of the code should be modified, so here is only the essence >> of >> one of the pivoting reports: >> for $singleDataType in $dataType >> >> for $singleDevice in $device >> >> for $singleAvailability in $availability >> >> for $singleCountry in $country >> >> for $singleParameter in $parameter >> >> group by >> >> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >> order by >> >> $singleDataType,$singleDevice,$singleAvailability,$singleCountry,$singleParameter >> >> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >> Availability="{$singleAvailability}" Country="{$singleCountry}" >> Parameter="{$singleParameter}" NumberOfRecords="{count($current-pre)}"/> >> >> Other report will count all records with one less condition: >> >> group by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >> order by $singleDataType,$singleDevice,$singleAvailability,$singleCountry >> >> return <Row DatasetType="{$singleDataType}" Instrument="{$singleDevice}" >> Availability="{$singleAvailability}" Country="{$singleCountry}" >> Parameter="Any" NumberOfRecords="{count($current-pre)}"/> >> >> I hope it's clear. >> >> With kind regards, >> Menashè >> >> >>
Written for BaseX 8.2. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery