aggregate-functions


Usage of aggregate functions in MarkLogic


I have an XML like this.
<?xml version="1.0" encoding="UTF-8"?>
<doc>
<ticker> CSGN.VX </ticker>
<stockExchange> NYSE </stockExchange>
<stockDatas>
<stockData>
<date>2015-08-06</date>
<closingPrice>140</closingPrice>
</stockData>
<stockData>
<date>2015-08-07</date>
<closingPrice>140.25</closingPrice>
</stockData>
<stockData>
<date>2015-08-10</date>
<closingPrice>140.75</closingPrice>
</stockData>
</stockDatas>
</doc>
And I will be having similar XMLs for different companies around different years. Now I want to search for documents which have the ticker as CSGN.VX for a particular time duration, so I use this query.
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy";
search:search(
'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")',
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="dateRange">
<range type="xs:date" facet="false">
<element ns="" name="date"/>
</range>
</constraint>
<constraint name="ticker">
<range type="xs:string" >
<element ns="" name="ticker"/>
</range>
</constraint>
</options>)
Is there a way where along with the document search, I can also get the closingPrice average for that particular time duration?
I just got a solution but i have a further query, i was looking for a way to implement this using java client API of Marklogic so is there a way to implement search:parse and search:values using Java Client API
I know one way to implement this is through MarklogicXCC API but i wanted to know if there is a way through which these functions can be run using Client API
Provided you have a range index on closingPrice you should be able to do something like this:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"at "/MarkLogic/appservices/search/search.xqy";
let $query :=
search:parse(
'ticker:CSGN.VX AND (dateRange GE "2015-08-07" AND dateRange LE "2015-08-21")',
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="dateRange">
<range type="xs:date" facet="false">
<element ns="" name="date"/>
</range>
</constraint>
<constraint name="ticker">
<range type="xs:string" >
<element ns="" name="ticker"/>
</range>
</constraint>
</options>,
"search:query"
)
return
search:values(
'closingPrice',
<options xmlns="http://marklogic.com/appservices/search">
<values name="closingPrice">
<range type="xs:double">
<element ns="" name="closingPrice"/>
</range>
<aggregate apply="avg"/>
</values>
</options>,
$query
)
Note: I do recommend storing each stockData separately, otherwise the dateRange filter probably won't work as expected.
HTH!

Related Links

Tableau Aggregate Percentage
use aggregates (min, max, avg) in CONSTRUCT query [duplicate]
R: transposing and aggregating columns
SQL Query Aggregate Error
Usage of aggregate functions in MarkLogic
Querying customDimensions in Google Bigquery
NHibernate - QueryOver criteria appearing in Where instead in Having clause, error
Howto aggregate on full data set in Spring Batch jobs?
Creating an aggregate function fails
Necessity of declaration of function in c and cpp
Calculate window average in tableau
Complexity asymptotic relation (theta, Big O, little o, Big Omega, little omega) between functions
What are TOP_COUNT and TOP_MAXCOUNT in BigQuery?
marklogic need advise for approach to aggregate documents
multiply(num) aggregate function in postgresql
Binding the Result of an Aggregate Function to a Projected Variable

Categories

HOME
excel-formula
swift3
macros
sip
service
snappy
gap-system
dynamic
x86-64
spss
hiveql
aggregation-framework
atlassian-fisheye
rethinkdb
digital
xmlhttprequest
dat.gui
md2
draw2d
android-wifi
gnu-screen
infinite-loop
policy
datanucleus
expressionengine
paper-trail-gem
overflow
voyager
intersection
rtsp
yelp
binary-decision-diagram
amazon-rds-aurora
apiman
ocamlbuild
infovis
runner
import.io
denodo
visualizer
kendo-scheduler
business-catalyst
petapoco
multi-select
node.js-client
spring-cloud-aws
was
suitesparse
consolidation
queuing
avaudiorecorder
database-administration
user-profile
cexception
datamodel
clear
imageicon
producer-consumer
cyberduck
callfire
pymol
uiblureffect
information-hiding
breeze-sharp
indic
code-smell
infor-eam
acrofields
db2-connect
nomachine
google-oauth-java-client
setcookie
jquery-ui-map
unordered-set
utm
automapper-2
cryptolicensing
mediastreamsource
cross-cutting-concerns

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App