Last active
August 29, 2015 14:19
-
-
Save joemfb/b682504c7c19cd6fae11 to your computer and use it in GitHub Desktop.
aggregate function metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
declare variable $numeric-scalar-types := ("int", "unsignedInt", "long", "unsignedLong", "float", "double", "decimal"); | |
declare function local:scalar-types() | |
{ | |
xdmp:read-cluster-config-file("database.xsd")/xs:schema | |
/xs:simpleType[@name eq "scalar-type"]/xs:restriction/xs:enumeration/@value/fn:string() | |
}; | |
declare function local:aggregate-types() | |
{ | |
map:new(( | |
(: TODO: test :) | |
("covariance", "covariance-population", "correlation") ! | |
map:entry(., $numeric-scalar-types), | |
("median", "stddev", "stddev-population", "variance", "variance-population") ! | |
map:entry(., $numeric-scalar-types), | |
("sum", "avg") ! | |
map:entry(., ($numeric-scalar-types, "yearMonthDuration", "dayTimeDuration")), | |
("min", "max") ! | |
map:entry(., ($numeric-scalar-types, "point", "yearMonthDuration", "dayTimeDuration", "date", "dateTime", "time", "gYear", "gMonth", "gYearMonth", "gDay")), | |
map:entry("count", ("point", local:scalar-types())))) | |
}; | |
declare function local:aggregate-info() | |
{ | |
map:new(( | |
("covariance", "covariance-population", "correlation") ! | |
map:entry(., | |
map:entry("reference-arity", 2)), | |
map:keys(local:aggregate-types())[fn:not(. = ("covariance", "covariance-population", "correlation"))] ! | |
map:entry(., | |
map:entry("reference-arity", 1)))) | |
}; | |
declare function local:map-values-as-arrays($map as map:map) as map:map | |
{ | |
map:new( | |
for $key in map:keys($map) | |
let $val := map:get($map, $key) | |
return | |
map:entry($key, | |
if ($val instance of json:array) | |
then $val | |
else json:to-array($val))) | |
}; | |
xdmp:to-json( | |
map:new(( | |
map:entry("info", local:aggregate-info()), | |
map:entry("by-type", | |
local:map-values-as-arrays( | |
-local:aggregate-types()))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment