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

rrdtool does not keep max
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

Categories

HOME
ssms
pelican
glsl
arguments
coordinates
mingw
confluence-rest-api
mediarecorder
aggregation-framework
richtextbox
schema
google-search-appliance
elastalert
suitecrm
distinct
jetbrains
xmlhttprequest
tmux
template10
datasource
email-client
ckeditor4.x
proof-general
emr
units-of-measurement
cqlsh
vtd-xml
selenium3
matlab-compiler
const
lex
gem-fury
google-chrome-console
definition
xmldom
activesupport
ajv
multi-select
nls
computed-properties
foreground
jmap
nd4j
innertext
salesforce-service-cloud
datamodel
skscene
commercetools
cyberduck
litedb
tidesdk
pymol
caption
jsonmodel
apache-pivot
redmine-plugins
xts
banana-pi
git-subtree
node-mongodb-native
xcode6.1-gm-seed
grunt-contrib-imagemin
sygic
aspnet-compiler
typography
magicsuggest
servicemanager
nx
mail-gem
states
aspmenu-control
erlide
mysql-connector
scriptmanager
openwrap
recess
object-tag
hwnd
netduino
chromebug
miniport
dgml
calendarextender
data-formats
ihtmldocument2
file-icons
software-update

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