Login
Quick Search

Group By Support

by wolf at 22-8-2008 16:05; Wiki ID: GroupBySupport

I'm student in Computer Science at the Free University of Brussel (ULB).

For my end of studies work, i would like to add the keyword groupby to XQuery in order to evaluate the advantages of this addition for OLAP queries on a XML datawarehouse.

For example here a multiple groupby in Xquery :

for $d1 in distinct-values(/xml/dw/facts/fact/dim1_id)
for $d2 in distinct-values(/xml/dw/facts/fact/dim2_id)
for $d3 in distinct-values(/xml/dw/facts/fact/dim3_id)
let $f := /xml/dw/facts/fact[dim1_id = $d1 and dim2_id = $d2 and dim3_id = $d3]
return
<group>
  <d1>{$d1}</d1>
  <d2>{$d2}</d2>
  <d3>{$d3}</d3>
  <count>{count($f)}</count>
</group>

This expression suggest several passes over all the data.

Its equivalent in sql :

select d1, d2, d3, count(fact)
from facts
groupby d1,d2,d3

I would like to implement something like that with eXist :

for $facts in (/xml/dw/facts/fact)
groupby $facts as $facts-group by $facts/dim1_id as $d1, $facts/dim2_id as $d2, $facts/dim3_id as $d3
return
<group>
  <d1>{$d1}</d1>
  <d2>{$d2}</d2>
  <d3>{$d3}</d3>
  <count>{count($facts-group)}</count>
</group>

This last expression is easier to optimise and need less passes on the data.

PS : sorry for my poor english ;-)

Links
Latest Posts
AtomicWiki 0.4