blob: c24df886d2cefa7205f16beb31e5f143167afad6 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia at 2015-05-31
| Rendered using Apache Maven Fluido Skin 1.3.0
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="Date-Revision-yyyymmdd" content="20150531" />
<meta http-equiv="Content-Language" content="en" />
<title>AsterixDB - </title>
<link rel="stylesheet" href="../css/apache-maven-fluido-1.3.0.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script type="text/javascript" src="../js/apache-maven-fluido-1.3.0.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<a href=".././" id="bannerLeft">
<img src="../images/asterixlogo.png" alt="AsterixDB"/>
</a>
</div>
<div class="pull-right"> <a href="http://incubator.apache.org/" id="bannerRight">
<img src="../images/egg-logo.png" alt="Apache Software Foundation Incubator"/>
</a>
</div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2015-05-31</li>
<li id="projectVersion" class="pull-right">Version: 0.8.7-SNAPSHOT</li>
<li class="divider pull-right">|</li>
<li class="pull-right"> <a href="../index.html" title="Home">
Home</a>
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Apache Software Foundation</li>
<li>
<a href="http://www.apache.org/" class="externalLink" title="Home">
<i class="none"></i>
Home</a>
</li>
<li>
<a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Donate">
<i class="none"></i>
Donate</a>
</li>
<li>
<a href="http://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks">
<i class="none"></i>
Thanks</a>
</li>
<li>
<a href="http://www.apache.org/security/" class="externalLink" title="Security">
<i class="none"></i>
Security</a>
</li>
<li class="nav-header">User Documentation</li>
<li>
<a href="../install.html" title="Installing and Managing AsterixDB using Managix">
<i class="none"></i>
Installing and Managing AsterixDB using Managix</a>
</li>
<li>
<a href="../aql/primer.html" title="AsterixDB 101: An ADM and AQL Primer">
<i class="none"></i>
AsterixDB 101: An ADM and AQL Primer</a>
</li>
<li>
<a href="../aql/primer-sql-like.html" title="AsterixDB 101: An ADM and AQL Primer (For SQL Fans)">
<i class="none"></i>
AsterixDB 101: An ADM and AQL Primer (For SQL Fans)</a>
</li>
<li>
<a href="../aql/js-sdk.html" title="AsterixDB Javascript SDK">
<i class="none"></i>
AsterixDB Javascript SDK</a>
</li>
<li>
<a href="../aql/datamodel.html" title="Asterix Data Model (ADM)">
<i class="none"></i>
Asterix Data Model (ADM)</a>
</li>
<li>
<a href="../aql/manual.html" title="Asterix Query Language (AQL)">
<i class="none"></i>
Asterix Query Language (AQL)</a>
</li>
<li class="active">
<a href="#"><i class="none"></i>AQL Functions</a>
</li>
<li>
<a href="../aql/allens.html" title="AQL Allen's Relations Functions">
<i class="none"></i>
AQL Allen's Relations Functions</a>
</li>
<li>
<a href="../aql/similarity.html" title="AQL Support of Similarity Queries">
<i class="none"></i>
AQL Support of Similarity Queries</a>
</li>
<li>
<a href="../aql/externaldata.html" title="Accessing External Data">
<i class="none"></i>
Accessing External Data</a>
</li>
<li>
<a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
<i class="none"></i>
Filter-Based LSM Index Acceleration</a>
</li>
<li>
<a href="../api.html" title="REST API to AsterixDB">
<i class="none"></i>
REST API to AsterixDB</a>
</li>
</ul>
<hr class="divider" />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href=".././" title="Hyracks" class="builtBy">
<img class="builtBy" alt="Hyracks" src="../images/hyrax_ts.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span9" >
<h1>Asterix: Using Functions</h1>
<div class="section">
<h2><a name="toc" id="toc">Table of Contents</a><a name="Table_of_Contents"></a></h2>
<ul>
<li><a href="#NumericFunctions">Numeric Functions</a></li>
<li><a href="#StringFunctions">String Functions</a></li>
<li><a href="#AggregateFunctions">Aggregate Functions</a></li>
<li><a href="#SpatialFunctions">Spatial Functions</a></li>
<li><a href="#SimilarityFunctions">Similarity Functions</a></li>
<li><a href="#TokenizingFunctions">Tokenizing Functions</a></li>
<li><a href="#TemporalFunctions">Temporal Functions</a></li>
<li><a href="#OtherFunctions">Other Functions</a></li>
</ul>
<p>Asterix provides various classes of functions to support operations on numeric, string, spatial, and temporal data. This document explains how to use these functions.</p></div>
<div class="section">
<h2><a name="NumericFunctions" id="NumericFunctions">Numeric Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Numeric_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>abs<a name="abs"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>abs(numeric_expression)
</pre></div></li>
<li>
<p>Computes the absolute value of the argument.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt>/<tt>float</tt>/<tt>double</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The absolute value of the argument with the same type as the input argument, or <tt>null</tt> if the argument is a <tt>null</tt> value.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $v1 := abs(2013)
let $v2 := abs(-4036)
let $v3 := abs(0)
let $v4 := abs(float(&quot;-2013.5&quot;))
let $v5 := abs(double(&quot;-2013.593823748327284&quot;))
return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: 4036, &quot;v3&quot;: 0, &quot;v4&quot;: 2013.5f, &quot;v5&quot;: 2013.5938237483274d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>ceiling<a name="ceiling"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>ceiling(numeric_expression)
</pre></div></li>
<li>
<p>Computes the smallest (closest to negative infinity) number with no fractional part that is not less than the value of the argument. If the argument is already equal to mathematical integer, then the result is the same as the argument.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt>/<tt>float</tt>/<tt>double</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The ceiling value for the given number in the same type as the input argument, or <tt>null</tt> if the input is <tt>null</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $v1 := ceiling(2013)
let $v2 := ceiling(-4036)
let $v3 := ceiling(0.3)
let $v4 := ceiling(float(&quot;-2013.2&quot;))
let $v5 := ceiling(double(&quot;-2013.893823748327284&quot;))
return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 1.0d, &quot;v4&quot;: -2013.0f, &quot;v5&quot;: -2013.0d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>floor<a name="floor"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>floor(numeric_expression)
</pre></div></li>
<li>
<p>Computes the largest (closest to positive infinity) number with no fractional part that is not greater than the value. If the argument is already equal to mathematical integer, then the result is the same as the argument.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt>/<tt>float</tt>/<tt>double</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The floor value for the given number in the same type as the input argument, or <tt>null</tt> if the input is <tt>null</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $v1 := floor(2013)
let $v2 := floor(-4036)
let $v3 := floor(0.8)
let $v4 := floor(float(&quot;-2013.2&quot;))
let $v5 := floor(double(&quot;-2013.893823748327284&quot;))
return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 0.0d, &quot;v4&quot;: -2014.0f, &quot;v5&quot;: -2014.0d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>round<a name="round"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>round(numeric_expression)
</pre></div></li>
<li>
<p>Computes the number with no fractional part that is closest (and also closest to positive infinity) to the argument.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt>/<tt>float</tt>/<tt>double</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The rounded value for the given number in the same type as the input argument, or <tt>null</tt> if the input is <tt>null</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $v1 := round(2013)
let $v2 := round(-4036)
let $v3 := round(0.8)
let $v4 := round(float(&quot;-2013.256&quot;))
let $v5 := round(double(&quot;-2013.893823748327284&quot;))
return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 1.0d, &quot;v4&quot;: -2013.0f, &quot;v5&quot;: -2014.0d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>round-half-to-even<a name="round-half-to-even"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>round-half-to-even(numeric_expression, [precision])
</pre></div></li>
<li>
<p>Computes the closest numeric value to <tt>numeric_expression</tt> that is a multiple of ten to the power of minus <tt>precision</tt>. <tt>precision</tt> is optional and by default value <tt>0</tt> is used.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt>/<tt>float</tt>/<tt>double</tt> value.</li>
<li><tt>precision</tt>: An optional integer field representing the number of digits in the fraction of the the result</li>
</ul></li>
<li>Return Value:
<ul>
<li>The rounded value for the given number in the same type as the input argument, or <tt>null</tt> if the input is <tt>null</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $v1 := round-half-to-even(2013)
let $v2 := round-half-to-even(-4036)
let $v3 := round-half-to-even(0.8)
let $v4 := round-half-to-even(float(&quot;-2013.256&quot;))
let $v5 := round-half-to-even(double(&quot;-2013.893823748327284&quot;))
let $v6 := round-half-to-even(double(&quot;-2013.893823748327284&quot;), 2)
let $v7 := round-half-to-even(2013, 4)
let $v8 := round-half-to-even(float(&quot;-2013.256&quot;), 5)
return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5, &quot;v6&quot;: $v6, &quot;v7&quot;: $v7, &quot;v8&quot;: $v8 }
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 1.0d, &quot;v4&quot;: -2013.0f, &quot;v5&quot;: -2014.0d, &quot;v6&quot;: -2013.89d, &quot;v7&quot;: 2013, &quot;v8&quot;: -2013.256f }
</pre></div></li>
</ul></div></div>
<div class="section">
<h2><a name="StringFunctions" id="StringFunctions">String Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="String_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>string-to-codepoint<a name="string-to-codepoint"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>string-to-codepoint(string_expression)
</pre></div></li>
<li>
<p>Converts the string <tt>string_expression</tt> to its code-based representation.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that will be converted.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>OrderedList</tt> of the code points for the string <tt>string_expression</tt>.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>codepoint-to-string<a name="codepoint-to-string"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>codepoint-to-string(list_expression)
</pre></div></li>
<li>
<p>Converts the ordered code-based representation <tt>list_expression</tt> to the corresponding string.</p></li>
<li>Arguments:
<ul>
<li><tt>list_expression</tt> : An <tt>OrderedList</tt> of code-points.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> representation of <tt>list_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $s := &quot;Hello ASTERIX!&quot;
let $l := string-to-codepoint($s)
let $ss := codepoint-to-string($l)
return {&quot;codes&quot;: $l, &quot;string&quot;: $ss}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;codes&quot;: [ 72, 101, 108, 108, 111, 32, 65, 83, 84, 69, 82, 73, 88, 33 ], &quot;string&quot;: &quot;Hello ASTERIX!&quot; }
</pre></div></li>
</ul></div>
<div class="section">
<h3>contains<a name="contains"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>contains(string_expression, substring_to_contain)
</pre></div></li>
<li>
<p>Checks whether the string <tt>string_expression</tt> contains the string <tt>substring_to_contain</tt></p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the given substring.</li>
<li><tt>substring_to_contain</tt> : A target <tt>string</tt> that might be contained.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt> value, <tt>true</tt> if <tt>string_expression</tt> contains <tt>substring_to_contain</tt>, and <tt>false</tt> otherwise.</li>
</ul></li>
<li>Note: An n-gram index can be utilized for this function.</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where contains($i.message, &quot;phone&quot;)
return {&quot;mid&quot;: $i.message-id, &quot;message&quot;: $i.message}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;mid&quot;: 2, &quot;message&quot;: &quot; dislike iphone its touch-screen is horrible&quot; }
{ &quot;mid&quot;: 13, &quot;message&quot;: &quot; dislike iphone the voice-command is bad:(&quot; }
{ &quot;mid&quot;: 15, &quot;message&quot;: &quot; like iphone the voicemail-service is awesome&quot; }
</pre></div></li>
</ul></div>
<div class="section">
<h3>like<a name="like"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>like(string_expression, string_pattern)
</pre></div></li>
<li>
<p>Checks whether the string <tt>string_expression</tt> contains the string pattern <tt>string_pattern</tt>. Compared to the <tt>contains</tt> function, the <tt>like</tt> function also supports regular expressions.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the pattern or <tt>null</tt>.</li>
<li><tt>string_pattern</tt> : A pattern <tt>string</tt> that might be contained or <tt>null</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt> value, <tt>true</tt> if <tt>string_expression</tt> contains the pattern <tt>string_pattern</tt>, and <tt>false</tt> otherwise.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where like($i.message, &quot;%at&amp;t%&quot;)
return $i.message
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot; can't stand at&amp;t the network is horrible:(&quot;
&quot; can't stand at&amp;t its plan is terrible&quot;
&quot; love at&amp;t its 3G is good:)&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>starts-with<a name="starts-with"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>starts-with(string_expression, substring_to_start_with)
</pre></div></li>
<li>
<p>Checks whether the string <tt>string_expression</tt> starts with the string <tt>substring_to_start_with</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that might start with the given string.</li>
<li><tt>substring_to_start_with</tt> : A <tt>string</tt> that might be contained as the starting substring.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt>, returns <tt>true</tt> if <tt>string_expression</tt> starts with the string <tt>substring_to_start_with</tt>, and <tt>false</tt> otherwise.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where starts-with($i.message, &quot; like&quot;)
return $i.message
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot; like samsung the plan is amazing&quot;
&quot; like t-mobile its platform is mind-blowing&quot;
&quot; like verizon the 3G is awesome:)&quot;
&quot; like iphone the voicemail-service is awesome&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>ends-with<a name="ends-with"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>ends-with(string_expression, substring_to_end_with)
</pre></div></li>
<li>
<p>Checks whether the string <tt>string_expression</tt> ends with the string <tt>substring_to_end_with</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that might end with the given string.</li>
<li><tt>substring_to_end_with</tt> : A <tt>string</tt> that might be contained as the ending substring.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt>, returns <tt>true</tt> if <tt>string_expression</tt> ends with the string <tt>substring_to_end_with</tt>, and <tt>false</tt> otherwise.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where ends-with($i.message, &quot;:)&quot;)
return $i.message
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot; love sprint its shortcut-menu is awesome:)&quot;
&quot; like verizon the 3G is awesome:)&quot;
&quot; love at&amp;t its 3G is good:)&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>string-concat<a name="string-concat"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>string-concat(list_expression)
</pre></div></li>
<li>
<p>Concatenates a list of strings <tt>list_expression</tt> into a single string.</p></li>
<li>Arguments:
<ul>
<li><tt>list_expression</tt> : An <tt>OrderedList</tt> or <tt>UnorderedList</tt> of <tt>string</tt>s (could be <tt>null</tt>) to be concatenated.</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns the concatenated <tt>string</tt> value.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := &quot;ASTERIX&quot;
let $j := &quot; &quot;
let $k := &quot;ROCKS!&quot;
return string-concat([$i, $j, $k])
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;ASTERIX ROCKS!&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>string-join<a name="string-join"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>string-join(list_expression, string_expression)
</pre></div></li>
<li>
<p>Joins a list of strings <tt>list_expression</tt> with the given separator <tt>string_expression</tt> into a single string.</p></li>
<li>Arguments:
<ul>
<li><tt>list_expression</tt> : An <tt>OrderedList</tt> or <tt>UnorderedList</tt> of strings (could be <tt>null</tt>) to be joined.</li>
<li><tt>string_expression</tt> : A <tt>string</tt> as the separator.</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns the joined <tt>String</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $i := [&quot;ASTERIX&quot;, &quot;ROCKS~&quot;]
return string-join($i, &quot;!! &quot;)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;ASTERIX!! ROCKS~&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>lowercase<a name="lowercase"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>lowercase(string_expression)
</pre></div></li>
<li>
<p>Converts a given string <tt>string_expression</tt> to its lowercase form.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> to be converted.</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns a <tt>string</tt> as the lowercase form of the given <tt>string_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $i := &quot;ASTERIX&quot;
return lowercase($i)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>asterix
</pre></div></li>
</ul></div>
<div class="section">
<h3>uppercase<a name="uppercase"></a></h3>
<ul>
<li>Syntax:</li>
</ul>
<p>uppercase(string_expression)</p>
<ul>
<li>Converts a given string <tt>string_expression</tt> to its uppercase form.</li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> to be converted.</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns a <tt>string</tt> as the uppercase form of the given <tt>string_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $i := &quot;asterix&quot;
return uppercase($i)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>ASTERIX
</pre></div></li>
</ul></div>
<div class="section">
<h3>uppercase<a name="uppercase"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>uppercase(string_expression)
</pre></div></li>
<li>
<p>Converts a given string <tt>string_expression</tt> to its uppercase form.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> to be converted.</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns a <tt>string</tt> as the uppercase form of the given <tt>string_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $i := &quot;asterix&quot;
return uppercase($i)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>ASTERIX
</pre></div></li>
</ul></div>
<div class="section">
<h3>matches<a name="matches"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>matches(string_expression, string_pattern)
</pre></div></li>
<li>
<p>Checks whether the strings <tt>string_expression</tt> matches the given pattern <tt>string_pattern</tt> (A Java regular expression pattern).</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the pattern.</li>
<li><tt>string_pattern</tt> : A pattern <tt>string</tt> to be matched.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt>, returns <tt>true</tt> if <tt>string_expression</tt> matches the pattern <tt>string_pattern</tt>, and <tt>false</tt> otherwise.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where matches($i.message, &quot;dislike iphone&quot;)
return $i.message
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot; dislike iphone its touch-screen is horrible&quot;
&quot; dislike iphone the voice-command is bad:(&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>replace<a name="replace"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>replace(string_expression, string_pattern, string_replacement[, string_flags])
</pre></div></li>
<li>
<p>Checks whether the string <tt>string_expression</tt> matches the given pattern <tt>string_pattern</tt>, and replace the matched pattern <tt>string_pattern</tt> with the new pattern <tt>string_replacement</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the pattern.</li>
<li><tt>string_pattern</tt> : A pattern <tt>string</tt> to be matched.</li>
<li><tt>string_replacement</tt> : A pattern <tt>string</tt> to be used as the replacement.</li>
<li><tt>string_flag</tt> : (Optional) A <tt>string</tt> with flags to be used during replace.</li>
<li>The following modes are enabled with these flags: dotall (s), multiline (m), case-insenitive (i), and comments and whitespace (x).</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns a <tt>string</tt> that is obtained after the replacements.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where matches($i.message, &quot; like iphone&quot;)
return replace($i.message, &quot; like iphone&quot;, &quot;like android&quot;)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;like android the voicemail-service is awesome&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>string-length<a name="string-length"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>string-length(string_expression)
</pre></div></li>
<li>
<p>Returns the length of the string <tt>string_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> or <tt>null</tt> that represents the string to be checked.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int64</tt> that represents the length of <tt>string_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
return {&quot;mid&quot;: $i.message-id, &quot;message-len&quot;: string-length($i.message)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;mid&quot;: 1, &quot;message-len&quot;: 43 }
{ &quot;mid&quot;: 2, &quot;message-len&quot;: 44 }
{ &quot;mid&quot;: 3, &quot;message-len&quot;: 33 }
{ &quot;mid&quot;: 4, &quot;message-len&quot;: 43 }
{ &quot;mid&quot;: 5, &quot;message-len&quot;: 46 }
{ &quot;mid&quot;: 6, &quot;message-len&quot;: 43 }
{ &quot;mid&quot;: 7, &quot;message-len&quot;: 37 }
{ &quot;mid&quot;: 8, &quot;message-len&quot;: 33 }
{ &quot;mid&quot;: 9, &quot;message-len&quot;: 34 }
{ &quot;mid&quot;: 10, &quot;message-len&quot;: 50 }
{ &quot;mid&quot;: 11, &quot;message-len&quot;: 38 }
{ &quot;mid&quot;: 12, &quot;message-len&quot;: 52 }
{ &quot;mid&quot;: 13, &quot;message-len&quot;: 42 }
{ &quot;mid&quot;: 14, &quot;message-len&quot;: 27 }
{ &quot;mid&quot;: 15, &quot;message-len&quot;: 45 }
</pre></div></li>
</ul></div>
<div class="section">
<h3>substring<a name="substring"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>substring(string_expression, offset[, length])
</pre></div></li>
<li>
<p>Returns the substring from the given string <tt>string_expression</tt> based on the given start offset <tt>offset</tt> with the optional <tt>length</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> to be extracted.</li>
<li><tt>offset</tt> : An <tt>int64</tt> as the starting offset of the substring in <tt>string_expression</tt>.</li>
<li><tt>length</tt> : (Optional) An <tt>int64</tt> as the length of the substring.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> that represents the substring.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where string-length($i.message) &gt; 50
return substring($i.message, 50)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;G:(&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>substring-before<a name="substring-before"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>substring-before(string_expression, string_pattern)
</pre></div></li>
<li>
<p>Returns the substring from the given string <tt>string_expression</tt> before the given pattern <tt>string_pattern</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> to be extracted.</li>
<li><tt>string_pattern</tt> : A <tt>string</tt> pattern to be searched.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> that represents the substring.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where contains($i.message, &quot;iphone&quot;)
return substring-before($i.message, &quot;iphone&quot;)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot; dislike &quot;
&quot; dislike &quot;
&quot; like &quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>substring-after<a name="substring-after"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>substring-after(string_expression, string_pattern)
</pre></div></li>
<li>
<p>Returns the substring from the given string <tt>string_expression</tt> after the given pattern <tt>string_pattern</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> to be extracted.</li>
<li><tt>string_pattern</tt> : A <tt>string</tt> pattern to be searched.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> that represents the substring.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('FacebookMessages')
where contains($i.message, &quot;iphone&quot;)
return substring-after($i.message, &quot;iphone&quot;)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot; its touch-screen is horrible&quot;
&quot; the voice-command is bad:(&quot;
&quot; the voicemail-service is awesome&quot;
</pre></div></li>
</ul></div></div>
<div class="section">
<h2><a name="AggregateFunctions" id="AggregateFunctions">Aggregate Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Aggregate_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>count<a name="count"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>count(list)
</pre></div></li>
<li>
<p>Gets the number of items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing the items to be counted, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int64</tt> value representing the number of items in the given list. <tt>0i64</tt> is returned if the input is <tt>null</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $l1 := ['hello', 'world', 1, 2, 3]
let $l2 := for $i in dataset TwitterUsers return $i
return {&quot;count1&quot;: count($l1), &quot;count2&quot;: count($l2)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;count1&quot;: 5i64, &quot;count2&quot;: 4i64 }
</pre></div></li>
</ul></div>
<div class="section">
<h3>avg<a name="avg"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>avg(num_list)
</pre></div></li>
<li>
<p>Gets the average value of the items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>num_list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing numeric or null values, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>double</tt> value representing the average of the numbers in the given list. <tt>null</tt> is returned if the input is <tt>null</tt>, or the input list contains <tt>null</tt>. Non-numeric types in the input list will cause an error.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $l := for $i in dataset TwitterUsers return $i.friends_count
return {&quot;avg_friend_count&quot;: avg($l)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;avg_friend_count&quot;: 191.5d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>sum<a name="sum"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>sum(num_list)
</pre></div></li>
<li>
<p>Gets the sum of the items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>num_list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing numeric or null values, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The sum of the numbers in the given list. The returning type is decided by the item type with the highest order in the numeric type promotion order (<tt>int8</tt>-&gt; <tt>int16</tt>-&gt;<tt>int32</tt>-&gt;<tt>int64</tt>-&gt;<tt>float</tt>-&gt;<tt>double</tt>) among items. <tt>null</tt> is returned if the input is <tt>null</tt>, or the input list contains <tt>null</tt>. Non-numeric types in the input list will cause an error.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $l := for $i in dataset TwitterUsers return $i.friends_count
return {&quot;sum_friend_count&quot;: sum($l)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;sum_friend_count&quot;: 766 }
</pre></div></li>
</ul></div>
<div class="section">
<h3>min/max<a name="minmax"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>min(num_list), max(num_list)
</pre></div></li>
<li>
<p>Gets the min/max value of numeric items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>num_list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing the items to be compared, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The min/max value of the given list. The returning type is decided by the item type with the highest order in the numeric type promotion order (<tt>int8</tt>-&gt; <tt>int16</tt>-&gt;<tt>int32</tt>-&gt;<tt>int64</tt>-&gt;<tt>float</tt>-&gt;<tt>double</tt>) among items. <tt>null</tt> is returned if the input is <tt>null</tt>, or the input list contains <tt>null</tt>. Non-numeric types in the input list will cause an error.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $l := for $i in dataset TwitterUsers return $i. friends_count
return {&quot;min_friend_count&quot;: min($l), &quot;max_friend_count&quot;: max($l)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;min_friend_count&quot;: 18, &quot;max_friend_count&quot;: 445 }
</pre></div></li>
</ul></div>
<div class="section">
<h3>sql-count<a name="sql-count"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>sql-count(list)
</pre></div></li>
<li>
<p>Gets the number of non-null items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing the items to be counted, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int64</tt> value representing the number of non-null items in the given list. The value <tt>0i64</tt> is returned if the input is <tt>null</tt>.</li>
</ul></li>
<li>
<p>Example:</p></li>
</ul>
<div class="source">
<pre> let $l1 := ['hello', 'world', 1, 2, 3, null]
return {&quot;count&quot;: sql-count($l1)}
</pre></div>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;count&quot;: 5i64 }
</pre></div></li>
</ul></div>
<div class="section">
<h3>sql-avg<a name="sql-avg"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>sql-avg(num_list)
</pre></div></li>
<li>
<p>Gets the average value of the non-null items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>num_list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing numeric or null values, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>double</tt> value representing the average of the non-null numbers in the given list. The <tt>null</tt> value is returned if the input is <tt>null</tt>. Non-numeric types in the input list will cause an error.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $l := [1.2, 2.3, 3.4, 0, null]
return {&quot;avg&quot;: sql-avg($l)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;avg&quot;: 1.725d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>sql-sum<a name="sql-sum"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>sql-sum(num_list)
</pre></div></li>
<li>
<p>Gets the sum of the non-null items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>num_list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing numeric or null values, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The sum of the non-null numbers in the given list. The returning type is decided by the item type with the highest order in the numeric type promotion order (<tt>int8</tt>-&gt; <tt>int16</tt>-&gt;<tt>int32</tt>-&gt;<tt>int64</tt>-&gt;<tt>float</tt>-&gt;<tt>double</tt>) among items. The value <tt>null</tt> is returned if the input is <tt>null</tt>. Non-numeric types in the input list will cause an error.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $l := [1.2, 2.3, 3.4, 0, null]
return {&quot;sum&quot;: sql-sum($l)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;sum&quot;: 6.9d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>sql-min/max<a name="sql-minmax"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>sql-min(num_list), sql-max(num_list)
</pre></div></li>
<li>
<p>Gets the min/max value of the non-null numeric items in the given list.</p></li>
<li>Arguments:
<ul>
<li><tt>num_list</tt>: An <tt>orderedList</tt> or <tt>unorderedList</tt> containing the items to be compared, or a <tt>null</tt> value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>The min/max value of the given list. The returning type is decided by the item type with the highest order in the numeric type promotion order (<tt>int8</tt>-&gt; <tt>int16</tt>-&gt;<tt>int32</tt>-&gt;<tt>int64</tt>-&gt;<tt>float</tt>-&gt;<tt>double</tt>) among items. The value <tt>null</tt> is returned if the input is <tt>null</tt>. Non-numeric types in the input list will cause an error.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $l := [1.2, 2.3, 3.4, 0, null]
return {&quot;min&quot;: sql-min($l), &quot;max&quot;: sql-max($l)}
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;min&quot;: 0.0d, &quot;max&quot;: 3.4d }
</pre></div></li>
</ul></div></div>
<div class="section">
<h2><a name="SpatialFunctions" id="SpatialFunctions">Spatial Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Spatial_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>create-point<a name="create-point"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>create-point(x, y)
</pre></div></li>
<li>
<p>Creates the primitive type <tt>point</tt> using an <tt>x</tt> and <tt>y</tt> value.</p></li>
<li>Arguments:</li>
<li><tt>x</tt> : A <tt>double</tt> that represents the x-coordinate.</li>
<li><tt>y</tt> : A <tt>double</tt> that represents the y-coordinate.</li>
<li>Return Value:</li>
<li>A <tt>point</tt> representing the ordered pair (<tt>x</tt>, <tt>y</tt>).</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $c := create-point(30.0,70.0)
return {&quot;point&quot;: $c}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;point&quot;: point(&quot;30.0,70.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>create-line<a name="create-line"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>create-line(point_expression1, point_expression2)
</pre></div></li>
<li>
<p>Creates the primitive type <tt>line</tt> using <tt>point_expression1</tt> and <tt>point_expression2</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>point_expression1</tt> : A <tt>point</tt> that represents the start point of the line.</li>
<li><tt>point_expression2</tt> : A <tt>point</tt> that represents the end point of the line.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A spatial <tt>line</tt> created using the points provided in <tt>point_expression1</tt> and <tt>point_expression2</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $c := create-line(create-point(30.0,70.0), create-point(50.0,90.0))
return {&quot;line&quot;: $c}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;line&quot;: line(&quot;30.0,70.0 50.0,90.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>create-rectangle<a name="create-rectangle"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>create-rectangle(point_expression1, point_expression2)
</pre></div></li>
<li>
<p>Creates the primitive type <tt>rectangle</tt> using <tt>point_expression1</tt> and <tt>point_expression2</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>point_expression1</tt> : A <tt>point</tt> that represents the lower-left point of the rectangle.</li>
<li><tt>point_expression2</tt> : A <tt>point</tt> that represents the upper-right point of the rectangle.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A spatial <tt>rectangle</tt> created using the points provided in <tt>point_expression1</tt> and <tt>point_expression2</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $c := create-rectangle(create-point(30.0,70.0), create-point(50.0,90.0))
return {&quot;rectangle&quot;: $c}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;rectangle&quot;: rectangle(&quot;30.0,70.0 50.0,90.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>create-circle<a name="create-circle"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>create-circle(point_expression, radius)
</pre></div></li>
<li>
<p>Creates the primitive type <tt>circle</tt> using <tt>point_expression</tt> and <tt>radius</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>point_expression</tt> : A <tt>point</tt> that represents the center of the circle.</li>
<li><tt>radius</tt> : A <tt>double</tt> that represents the radius of the circle.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A spatial <tt>circle</tt> created using the center point and the radius provided in <tt>point_expression</tt> and <tt>radius</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $c := create-circle(create-point(30.0,70.0), 5.0)
return {&quot;circle&quot;: $c}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;circle&quot;: circle(&quot;30.0,70.0 5.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>create-polygon<a name="create-polygon"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>create-polygon(list_expression)
</pre></div></li>
<li>
<p>Creates the primitive type <tt>polygon</tt> using the double values provided in the argument <tt>list_expression</tt>. Each two consecutive double values represent a point starting from the first double value in the list. Note that at least six double values should be specified, meaning a total of three points.</p></li>
<li>Arguments:</li>
<li><tt>list_expression</tt> : An OrderedList of doubles representing the points of the polygon.</li>
<li>Return Value:</li>
<li>A <tt>polygon</tt>, represents a spatial simple polygon created using the points provided in <tt>list_expression</tt>.</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $c := create-polygon([1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0])
return {&quot;polygon&quot;: $c}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;polygon&quot;: polygon(&quot;1.0,1.0 2.0,2.0 3.0,3.0 4.0,4.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-x/get-y<a name="get-xget-y"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-x(point_expression) or get-y(point_expression)
</pre></div></li>
<li>
<p>Returns the x or y coordinates of a point <tt>point_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>point_expression</tt> : A <tt>point</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>double</tt> representing the x or y coordinates of the point <tt>point_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $point := create-point(2.3,5.0)
return {&quot;x-coordinate&quot;: get-x($point), &quot;y-coordinate&quot;: get-y($point)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;x-coordinate&quot;: 2.3d, &quot;y-coordinate&quot;: 5.0d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-points<a name="get-points"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-points(spatial_expression)
</pre></div></li>
<li>
<p>Returns an ordered list of the points forming the spatial object <tt>spatial_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>spatial_expression</tt> : A <tt>point</tt>, <tt>line</tt>, <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>OrderedList</tt> of the points forming the spatial object <tt>spatial_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $line := create-line(create-point(100.6,99.4), create-point(-72.0,-76.9))
let $rectangle := create-rectangle(create-point(9.2,49.0), create-point(77.8,111.1))
let $polygon := create-polygon([1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0])
let $line_list := get-points($line)
let $rectangle_list := get-points($rectangle)
let $polygon_list := get-points($polygon)
return {&quot;line-first-point&quot;: $line_list[0], &quot;line-second-point&quot;: $line_list[1], &quot;rectangle-left-bottom-point&quot;: $rectangle_list[0], &quot;rectangle-top-upper-point&quot;: $rectangle_list[1], &quot;polygon-first-point&quot;: $polygon_list[0], &quot;polygon-second-point&quot;: $polygon_list[1], &quot;polygon-third-point&quot;: $polygon_list[2], &quot;polygon-forth-point&quot;: $polygon_list[3]}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;line-first-point&quot;: point(&quot;100.6,99.4&quot;), &quot;line-second-point&quot;: point(&quot;-72.0,-76.9&quot;), &quot;rectangle-left-bottom-point&quot;: point(&quot;9.2,49.0&quot;), &quot;rectangle-top-upper-point&quot;: point(&quot;77.8,111.1&quot;), &quot;polygon-first-point&quot;: point(&quot;1.0,1.0&quot;), &quot;polygon-second-point&quot;: point(&quot;2.0,2.0&quot;), &quot;polygon-third-point&quot;: point(&quot;3.0,3.0&quot;), &quot;polygon-forth-point&quot;: point(&quot;4.0,4.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-center/get-radius<a name="get-centerget-radius"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-center(circle_expression) or get-radius(circle_expression)
</pre></div></li>
<li>
<p>Returns the center and the radius of a circle <tt>circle_expression</tt>, respectively.</p></li>
<li>Arguments:
<ul>
<li><tt>circle_expression</tt> : A <tt>circle</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>point</tt> or <tt>double</tt>, represent the center or radius of the circle <tt>circle_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $circle := create-circle(create-point(6.0,3.0), 1.0)
return {&quot;circle-radius&quot;: get-radius($circle), &quot;circle-center&quot;: get-center($circle)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;circle-radius&quot;: 1.0d, &quot;circle-center&quot;: point(&quot;6.0,3.0&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>spatial-distance<a name="spatial-distance"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>spatial-distance(point_expression1, point_expression2)
</pre></div></li>
<li>
<p>Returns the Euclidean distance between <tt>point_expression1</tt> and <tt>point_expression2</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>point_expression1</tt> : A <tt>point</tt>.</li>
<li><tt>point_expression2</tt> : A <tt>point</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>double</tt> as the Euclidean distance between <tt>point_expression1</tt> and <tt>point_expression2</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $d := spatial-distance($t.sender-location, create-point(30.0,70.0))
return {&quot;point&quot;: $t.sender-location, &quot;distance&quot;: $d}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;point&quot;: point(&quot;47.44,80.65&quot;), &quot;distance&quot;: 20.434678857275934d }
{ &quot;point&quot;: point(&quot;29.15,76.53&quot;), &quot;distance&quot;: 6.585089217315132d }
{ &quot;point&quot;: point(&quot;37.59,68.42&quot;), &quot;distance&quot;: 7.752709203884797d }
{ &quot;point&quot;: point(&quot;24.82,94.63&quot;), &quot;distance&quot;: 25.168816023007512d }
{ &quot;point&quot;: point(&quot;32.84,67.14&quot;), &quot;distance&quot;: 4.030533463451212d }
{ &quot;point&quot;: point(&quot;29.72,75.8&quot;), &quot;distance&quot;: 5.806754687430835d }
{ &quot;point&quot;: point(&quot;39.28,70.48&quot;), &quot;distance&quot;: 9.292405501268227d }
{ &quot;point&quot;: point(&quot;40.09,92.69&quot;), &quot;distance&quot;: 24.832321679617472d }
{ &quot;point&quot;: point(&quot;47.51,83.99&quot;), &quot;distance&quot;: 22.41250097601782d }
{ &quot;point&quot;: point(&quot;36.21,72.6&quot;), &quot;distance&quot;: 6.73231758015024d }
{ &quot;point&quot;: point(&quot;46.05,93.34&quot;), &quot;distance&quot;: 28.325926286707734d }
{ &quot;point&quot;: point(&quot;36.86,74.62&quot;), &quot;distance&quot;: 8.270671073135482d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>spatial-area<a name="spatial-area"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>spatial-area(spatial_2d_expression)
</pre></div></li>
<li>
<p>Returns the spatial area of <tt>spatial_2d_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>spatial_2d_expression</tt> : A <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>double</tt> representing the area of <tt>spatial_2d_expression</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $circleArea := spatial-area(create-circle(create-point(0.0,0.0), 5.0))
return {&quot;Area&quot;:$circleArea}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;Area&quot;: 78.53981625d }
</pre></div></li>
</ul></div>
<div class="section">
<h3>spatial-intersect<a name="spatial-intersect"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>spatial-intersect(spatial_expression1, spatial_expression2)
</pre></div></li>
<li>
<p>Checks whether <tt>@arg1</tt> and <tt>@arg2</tt> spatially intersect each other.</p></li>
<li>Arguments:
<ul>
<li><tt>spatial_expression1</tt> : A <tt>point</tt>, <tt>line</tt>, <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
<li><tt>spatial_expression2</tt> : A <tt>point</tt>, <tt>line</tt>, <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt> representing whether <tt>spatial_expression1</tt> and <tt>spatial_expression2</tt> spatially overlap with each other.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $t in dataset('TweetMessages')
where spatial-intersect($t.sender-location, create-rectangle(create-point(30.0,70.0), create-point(40.0,80.0)))
return $t
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;tweetid&quot;: &quot;4&quot;, &quot;user&quot;: { &quot;screen-name&quot;: &quot;NathanGiesen@211&quot;, &quot;lang&quot;: &quot;en&quot;, &quot;friends_count&quot;: 39339, &quot;statuses_count&quot;: 473, &quot;name&quot;: &quot;Nathan Giesen&quot;, &quot;followers_count&quot;: 49416 }, &quot;sender-location&quot;: point(&quot;39.28,70.48&quot;), &quot;send-time&quot;: datetime(&quot;2011-12-26T10:10:00.000Z&quot;), &quot;referred-topics&quot;: {{ &quot;sprint&quot;, &quot;voice-command&quot; }}, &quot;message-text&quot;: &quot; like sprint the voice-command is mind-blowing:)&quot; }
{ &quot;tweetid&quot;: &quot;7&quot;, &quot;user&quot;: { &quot;screen-name&quot;: &quot;ChangEwing_573&quot;, &quot;lang&quot;: &quot;en&quot;, &quot;friends_count&quot;: 182, &quot;statuses_count&quot;: 394, &quot;name&quot;: &quot;Chang Ewing&quot;, &quot;followers_count&quot;: 32136 }, &quot;sender-location&quot;: point(&quot;36.21,72.6&quot;), &quot;send-time&quot;: datetime(&quot;2011-08-25T10:10:00.000Z&quot;), &quot;referred-topics&quot;: {{ &quot;samsung&quot;, &quot;platform&quot; }}, &quot;message-text&quot;: &quot; like samsung the platform is good&quot; }
{ &quot;tweetid&quot;: &quot;9&quot;, &quot;user&quot;: { &quot;screen-name&quot;: &quot;NathanGiesen@211&quot;, &quot;lang&quot;: &quot;en&quot;, &quot;friends_count&quot;: 39339, &quot;statuses_count&quot;: 473, &quot;name&quot;: &quot;Nathan Giesen&quot;, &quot;followers_count&quot;: 49416 }, &quot;sender-location&quot;: point(&quot;36.86,74.62&quot;), &quot;send-time&quot;: datetime(&quot;2012-07-21T10:10:00.000Z&quot;), &quot;referred-topics&quot;: {{ &quot;verizon&quot;, &quot;voicemail-service&quot; }}, &quot;message-text&quot;: &quot; love verizon its voicemail-service is awesome&quot; }
</pre></div></li>
</ul></div>
<div class="section">
<h3>spatial-cell<a name="spatial-cell"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>spatial-cell(point_expression1, point_expression2, x_increment, y_increment)
</pre></div></li>
<li>
<p>Returns the grid cell that <tt>point_expression1</tt> belongs to.</p></li>
<li>Arguments:
<ul>
<li><tt>point_expression1</tt> : A <tt>point</tt> representing the point of interest that its grid cell will be returned.</li>
<li><tt>point_expression2</tt> : A <tt>point</tt> representing the origin of the grid.</li>
<li><tt>x_increment</tt> : A <tt>double</tt>, represents X increments.</li>
<li><tt>y_increment</tt> : A <tt>double</tt>, represents Y increments.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>rectangle</tt> representing the grid cell that <tt>point_expression1</tt> belongs to.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $t in dataset('TweetMessages')
group by $c := spatial-cell($t.sender-location, create-point(20.0,50.0), 5.5, 6.0) with $t
let $num := count($t)
return { &quot;cell&quot;: $c, &quot;count&quot;: $num}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;cell&quot;: rectangle(&quot;20.0,92.0 25.5,98.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;25.5,74.0 31.0,80.0&quot;), &quot;count&quot;: 2i64 }
{ &quot;cell&quot;: rectangle(&quot;31.0,62.0 36.5,68.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;31.0,68.0 36.5,74.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;36.5,68.0 42.0,74.0&quot;), &quot;count&quot;: 2i64 }
{ &quot;cell&quot;: rectangle(&quot;36.5,74.0 42.0,80.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;36.5,92.0 42.0,98.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;42.0,80.0 47.5,86.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;42.0,92.0 47.5,98.0&quot;), &quot;count&quot;: 1i64 }
{ &quot;cell&quot;: rectangle(&quot;47.5,80.0 53.0,86.0&quot;), &quot;count&quot;: 1i64 }
</pre></div></li>
</ul></div></div>
<div class="section">
<h2><a name="SimilarityFunctions" id="SimilarityFunctions">Similarity Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Similarity_Functions_Back_to_TOC"></a></h2>
<p>AsterixDB supports queries with different similarity functions, including edit distance and Jaccard.</p>
<div class="section">
<h3>edit-distance<a name="edit-distance"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>edit-distance(expression1, expression2)
</pre></div></li>
<li>
<p>Returns the <a class="externalLink" href="http://en.wikipedia.org/wiki/Levenshtein_distance">edit distance</a> of <tt>expression1</tt> and <tt>expression2</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>expression1</tt> : A <tt>string</tt> or a homogeneous <tt>OrderedList</tt> of a comparable item type.</li>
<li><tt>expression2</tt> : The same type as <tt>expression1</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int64</tt> that represents the edit distance between <tt>expression1</tt> and <tt>expression2</tt>.</li>
</ul></li>
<li>Note: An n-gram index can be utilized for this function.</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $user in dataset('FacebookUsers')
let $ed := edit-distance($user.name, &quot;Suzanna Tilson&quot;)
where $ed &lt;= 2
return $user
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{
&quot;id&quot;: 7, &quot;alias&quot;: &quot;Suzanna&quot;, &quot;name&quot;: &quot;SuzannaTillson&quot;, &quot;user-since&quot;: datetime(&quot;2012-08-07T10:10:00.000Z&quot;), &quot;friend-ids&quot;: {{ 6 }},
&quot;employment&quot;: [ { &quot;organization-name&quot;: &quot;Labzatron&quot;, &quot;start-date&quot;: date(&quot;2011-04-19&quot;), &quot;end-date&quot;: null } ]
}
</pre></div></li>
</ul></div>
<div class="section">
<h3>edit-distance-check<a name="edit-distance-check"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>edit-distance-check(expression1, expression2, threshold)
</pre></div></li>
<li>
<p>Checks whether <tt>expression1</tt> and <tt>expression2</tt> have an <a class="externalLink" href="http://en.wikipedia.org/wiki/Levenshtein_distance">edit distance</a> within a given threshold. The &#x201c;check&#x201d; version of edit distance is faster than the &#x201c;non-check&#x201d; version because the former can detect whether two items satisfy a given threshold using early-termination techniques, as opposed to computing their real distance. Although possible, it is not necessary for the user to write queries using the &#x201c;check&#x201d; versions explicitly, since a rewrite rule can perform an appropriate transformation from a &#x201c;non-check&#x201d; version to a &#x201c;check&#x201d; version.</p></li>
<li>
<p>Arguments:</p>
<ul>
<li><tt>expression1</tt> : A <tt>string</tt> or a homogeneous <tt>OrderedList</tt> of a comparable item type.</li>
<li><tt>expression2</tt> : The same type as <tt>expression1</tt>.</li>
<li><tt>threshold</tt> : An <tt>int64</tt> that represents the distance threshold.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>OrderedList</tt> with two items:
<ul>
<li>The first item contains a <tt>boolean</tt> value representing whether <tt>expression1</tt> and <tt>expression2</tt> are similar.</li>
<li>The second item contains an <tt>int64</tt> that represents the edit distance of <tt>expression1</tt> and <tt>expression2</tt> if it is within the threshold, or 0 otherwise.</li>
</ul></li>
</ul></li>
<li>Note: An n-gram index can be utilized for this function.</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $user in dataset('FacebookUsers')
let $ed := edit-distance-check($user.name, &quot;Suzanna Tilson&quot;, 2)
where $ed[0]
return $ed[1]
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>2
</pre></div></li>
</ul></div>
<div class="section">
<h3>edit-distance-contains<a name="edit-distance-contains"></a></h3>
<ul>
<li>Syntax:</li>
</ul>
<p>edit-distance-contains(expression1, expression2, threshold)</p>
<ul>
<li>
<p>Checks whether <tt>expression1</tt> contains <tt>expression2</tt> with an <a class="externalLink" href="http://en.wikipedia.org/wiki/Levenshtein_distance">edit distance</a> within a given threshold.</p></li>
<li>
<p>Arguments:</p>
<ul>
<li><tt>expression1</tt> : A <tt>string</tt> or a homogeneous <tt>OrderedList</tt> of a comparable item type.</li>
<li><tt>expression2</tt> : The same type as <tt>expression1</tt>.</li>
<li><tt>threshold</tt> : An <tt>int32</tt> that represents the distance threshold.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>OrderedList</tt> with two items:
<ul>
<li>The first item contains a <tt>boolean</tt> value representing whether <tt>expression1</tt> can contain <tt>expression2</tt>.</li>
<li>The second item contains an <tt>int32</tt> that represents the required edit distance for <tt>expression1</tt> to contain <tt>expression2</tt> if the first item is true.</li>
</ul></li>
</ul></li>
<li>Note: An n-gram index can be utilized for this function.</li>
<li>Example: let $i := edit-distance-contains(&#x201c;happy&#x201d;,&#x201c;hapr&#x201d;,2) return $i;</li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>[ true, 1 ]
</pre></div></li>
</ul></div>
<div class="section">
<h3>similarity-jaccard<a name="similarity-jaccard"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>similarity-jaccard(list_expression1, list_expression2)
</pre></div></li>
<li>
<p>Returns the <a class="externalLink" href="http://en.wikipedia.org/wiki/Jaccard_index">Jaccard similarity</a> of <tt>list_expression1</tt> and <tt>list_expression2</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>list_expression1</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
<li><tt>list_expression2</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>float</tt> that represents the Jaccard similarity of <tt>list_expression1</tt> and <tt>list_expression2</tt>.</li>
</ul></li>
<li>Note: A keyword index can be utilized for this function.</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $user in dataset('FacebookUsers')
let $sim := similarity-jaccard($user.friend-ids, [1,5,9])
where $sim &gt;= 0.6f
return $user
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{
&quot;id&quot;: 3, &quot;alias&quot;: &quot;Emory&quot;, &quot;name&quot;: &quot;EmoryUnk&quot;, &quot;user-since&quot;: datetime(&quot;2012-07-10T10:10:00.000Z&quot;), &quot;friend-ids&quot;: {{ 1, 5, 8, 9 }},
&quot;employment&quot;: [ { &quot;organization-name&quot;: &quot;geomedia&quot;, &quot;start-date&quot;: date(&quot;2010-06-17&quot;), &quot;end-date&quot;: date(&quot;2010-01-26&quot;) } ]
}
{
&quot;id&quot;: 10, &quot;alias&quot;: &quot;Bram&quot;, &quot;name&quot;: &quot;BramHatch&quot;, &quot;user-since&quot;: datetime(&quot;2010-10-16T10:10:00.000Z&quot;), &quot;friend-ids&quot;: {{ 1, 5, 9 }},
&quot;employment&quot;: [ { &quot;organization-name&quot;: &quot;physcane&quot;, &quot;start-date&quot;: date(&quot;2007-06-05&quot;), &quot;end-date&quot;: date(&quot;2011-11-05&quot;) } ]
}
</pre></div></li>
</ul></div>
<div class="section">
<h3>similarity-jaccard-check<a name="similarity-jaccard-check"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>similarity-jaccard-check(list_expression1, list_expression2, threshold)
</pre></div></li>
<li>
<p>Checks whether <tt>list_expression1</tt> and <tt>list_expression2</tt> have a <a class="externalLink" href="http://en.wikipedia.org/wiki/Jaccard_index">Jaccard similarity</a> greater than or equal to threshold. Again, the &#x201c;check&#x201d; version of Jaccard is faster than the &#x201c;non-check&#x201d; version.</p></li>
<li>
<p>Arguments:</p>
<ul>
<li><tt>list_expression1</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
<li><tt>list_expression2</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
<li><tt>threshold</tt> : A <tt>float</tt> that represents the similarity threshold.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>OrderedList</tt> with two items:</li>
<li>The first item contains a <tt>boolean</tt> value representing whether <tt>list_expression1</tt> and <tt>list_expression2</tt> are similar.</li>
<li>The second item contains a <tt>float</tt> that represents the Jaccard similarity of <tt>list_expression1</tt> and <tt>list_expression2</tt> if it is greater than or equal to the threshold, or 0 otherwise.</li>
</ul></li>
<li>Note: A keyword index can be utilized for this function.</li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $user in dataset('FacebookUsers')
let $sim := similarity-jaccard-check($user.friend-ids, [1,5,9], 0.6f)
where $sim[0]
return $sim[1]
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>0.75f
1.0f
</pre></div></li>
</ul></div>
<div class="section">
<h3>Similarity Operator ~#<a name="Similarity_Operator_"></a></h3>
<ul>
<li>&#x201c;<tt>~=</tt>&#x201d; is syntactic sugar for expressing a similarity condition with a given similarity threshold.</li>
<li>The similarity function and threshold for &#x201c;<tt>~=</tt>&#x201d; are controlled via &#x201c;set&#x201d; directives.</li>
<li>The &#x201c;<tt>~=</tt>&#x201d; operator returns a <tt>boolean</tt> value that represents whether the operands are similar.</li>
<li>
<p>Example for Jaccard similarity:</p>
<div class="source">
<pre>use dataverse TinySocial;
set simfunction &quot;jaccard&quot;;
set simthreshold &quot;0.6f&quot;;
for $user in dataset('FacebookUsers')
where $user.friend-ids ~= [1,5,9]
return $user
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{
&quot;id&quot;: 3, &quot;alias&quot;: &quot;Emory&quot;, &quot;name&quot;: &quot;EmoryUnk&quot;, &quot;user-since&quot;: datetime(&quot;2012-07-10T10:10:00.000Z&quot;), &quot;friend-ids&quot;: {{ 1, 5, 8, 9 }},
&quot;employment&quot;: [ { &quot;organization-name&quot;: &quot;geomedia&quot;, &quot;start-date&quot;: date(&quot;2010-06-17&quot;), &quot;end-date&quot;: date(&quot;2010-01-26&quot;) } ]
}
{
&quot;id&quot;: 10, &quot;alias&quot;: &quot;Bram&quot;, &quot;name&quot;: &quot;BramHatch&quot;, &quot;user-since&quot;: datetime(&quot;2010-10-16T10:10:00.000Z&quot;), &quot;friend-ids&quot;: {{ 1, 5, 9 }},
&quot;employment&quot;: [ { &quot;organization-name&quot;: &quot;physcane&quot;, &quot;start-date&quot;: date(&quot;2007-06-05&quot;), &quot;end-date&quot;: date(&quot;2011-11-05&quot;) } ]
}
</pre></div></li>
</ul>
<ul>
<li>
<p>Example for edit-distance similarity:</p>
<div class="source">
<pre>use dataverse TinySocial;
set simfunction &quot;edit-distance&quot;;
set simthreshold &quot;2&quot;;
for $user in dataset('FacebookUsers')
where $user.name ~= &quot;Suzanna Tilson&quot;
return $user
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected output is:</p>
<div class="source">
<pre>{
&quot;id&quot;: 7, &quot;alias&quot;: &quot;Suzanna&quot;, &quot;name&quot;: &quot;SuzannaTillson&quot;, &quot;user-since&quot;: datetime(&quot;2012-08-07T10:10:00.000Z&quot;), &quot;friend-ids&quot;: {{ 6 }},
&quot;employment&quot;: [ { &quot;organization-name&quot;: &quot;Labzatron&quot;, &quot;start-date&quot;: date(&quot;2011-04-19&quot;), &quot;end-date&quot;: null } ]
}
</pre></div></li>
</ul></div></div>
<div class="section">
<h2><a name="TokenizingFunctions" id="TokenizingFunctions">Tokenizing Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Tokenizing_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>word-tokens<a name="word-tokens"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>word-tokens(string_expression)
</pre></div></li>
<li>
<p>Returns a list of word tokens of <tt>string_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression</tt> : A <tt>string</tt> that will be tokenized.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>OrderedList</tt> of <tt>string</tt> word tokens.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $tokens := word-tokens($t.message-text)
where $t.send-time &gt;= datetime('2012-01-01T00:00:00')
return {
&quot;tweetid&quot;: $t.tweetid,
&quot;word-tokens&quot;: $tokens
}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;tweetid&quot;: &quot;9&quot;, &quot;word-tokens&quot;: [ &quot;love&quot;, &quot;verizon&quot;, &quot;its&quot;, &quot;voicemail&quot;, &quot;service&quot;, &quot;is&quot;, &quot;awesome&quot; ] }
</pre></div></li>
</ul>
<!-- ### hashed-word-tokens ###
* Syntax:
hashed-word-tokens(string_expression)
* Returns a list of hashed word tokens of `string_expression`.
* Arguments:
* `string_expression` : A `string` that will be tokenized.
* Return Value:
* An `OrderedList` of `int32` hashed tokens.
* Example:
use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $tokens := hashed-word-tokens($t.message-text)
where $t.send-time >= datetime('2012-01-01T00:00:00')
return {
"tweetid": $t.tweetid,
"hashed-word-tokens": $tokens
}
* The expected result is:
{ "tweetid": "9", "hashed-word-tokens": [ -1217719622, -447857469, -1884722688, -325178649, 210976949, 285049676, 1916743959 ] }
### counthashed-word-tokens ###
* Syntax:
counthashed-word-tokens(string_expression)
* Returns a list of hashed word tokens of `string_expression`. The hashing mechanism gives duplicate tokens different hash values, based on the occurrence count of that token.
* Arguments:
* `string_expression` : A `String` that will be tokenized.
* Return Value:
* An `OrderedList` of `Int32` hashed tokens.
* Example:
use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $tokens := counthashed-word-tokens($t.message-text)
where $t.send-time >= datetime('2012-01-01T00:00:00')
return {
"tweetid": $t.tweetid,
"counthashed-word-tokens": $tokens
}
* The expected result is:
{ "tweetid": "9", "counthashed-word-tokens": [ -1217719622, -447857469, -1884722688, -325178649, 210976949, 285049676, 1916743959 ] }
### gram-tokens ###
* Syntax:
gram-tokens(string_expression, gram_length, boolean_expression)
* Returns a list of gram tokens of `string_expression`, which can be obtained by scanning the characters using a sliding window of a fixed length.
* Arguments:
* `string_expression` : A `String` that will be tokenized.
* `gram_length` : An `Int32` as the length of grams.
* `boolean_expression` : A `Boolean` value to indicate whether to generate additional grams by pre- and postfixing `string_expression` with special characters.
* Return Value:
* An `OrderedList` of String gram tokens.
* Example:
use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $tokens := gram-tokens($t.message-text, 3, true)
where $t.send-time >= datetime('2012-01-01T00:00:00')
return {
"tweetid": $t.tweetid,
"gram-tokens": $tokens
}
* The expected result is:
{
"tweetid": "9",
"gram-tokens": [ "## ", "# l", " lo", "lov", "ove", "ve ", "e v", " ve", "ver", "eri", "riz", "izo", "zon", "on ", "n i", " it", "its", "ts ", "s v", " vo", "voi", "oic", "ice",
"cem", "ema", "mai", "ail", "il-", "l-s", "-se", "ser", "erv", "rvi", "vic", "ice", "ce ", "e i", " is", "is ", "s a", " aw", "awe", "wes", "eso", "som", "ome", "me$", "e$$" ]
}
### hashed-gram-tokens ###
* Syntax:
hashed-gram-tokens(string_expression, gram_length, boolean_expression)
* Returns a list of hashed gram tokens of `string_expression`.
* Arguments:
* `string_expression` : A `String` that will be tokenized.
* `gram_length` : An `Int32` as the length of grams.
* `boolean_expression` : A `Boolean` to indicate whether to generate additional grams by pre- and postfixing `string_expression` with special characters.
* Return Value:
* An `OrderedList` of `Int32` hashed gram tokens.
* Example:
use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $tokens := hashed-gram-tokens($t.message-text, 3, true)
where $t.send-time >= datetime('2012-01-01T00:00:00')
return {
"tweetid": $t.tweetid,
"hashed-gram-tokens": $tokens
}
* The expected result is:
{
"tweetid": "9",
"hashed-gram-tokens": [ 40557178, -2002241593, 161665899, -856104603, -500544946, 693410611, 395674299, -1015235909, 1115608337, 1187999872, -31006095, -219180466, -1676061637,
1040194153, -1339307841, -1527110163, -1884722688, -179148713, -431014627, -1789789823, -1209719926, 684519765, -486734513, 1734740619, -1971673751, -932421915, -2064668066,
-937135958, -790946468, -69070309, 1561601454, 26169001, -160734571, 1330043462, -486734513, -18796768, -470303314, 113421364, 1615760212, 1688217556, 1223719184, 536568131,
1682609873, 2935161, -414769471, -1027490137, 1602276102, 1050490461 ]
}
### counthashed-gram-tokens ###
* Syntax:
counthashed-gram-tokens(string_expression, gram_length, boolean_expression)
* Returns a list of hashed gram tokens of `string_expression`. The hashing mechanism gives duplicate tokens different hash values, based on the occurrence count of that token.
* Arguments:
* `string_expression` : A `String` that will be tokenized.
* `gram_length` : An `Int32`, length of grams to generate.
* `boolean_expression` : A `Boolean`, whether to generate additional grams by pre- and postfixing `string_expression` with special characters.
* Return Value:
* An `OrderedList` of `Int32` hashed gram tokens.
* Example:
use dataverse TinySocial;
for $t in dataset('TweetMessages')
let $tokens := counthashed-gram-tokens($t.message-text, 3, true)
where $t.send-time >= datetime('2012-01-01T00:00:00')
return {
"tweetid": $t.tweetid,
"counthashed-gram-tokens": $tokens
}
* The expected result is:
{
"tweetid": "9",
"counthashed-gram-tokens": [ 40557178, -2002241593, 161665899, -856104603, -500544946, 693410611, 395674299, -1015235909, 1115608337, 1187999872, -31006095, -219180466, -1676061637,
1040194153, -1339307841, -1527110163, -1884722688, -179148713, -431014627, -1789789823, -1209719926, 684519765, -486734513, 1734740619, -1971673751, -932421915, -2064668066, -937135958,
-790946468, -69070309, 1561601454, 26169001, -160734571, 1330043462, -486734512, -18796768, -470303314, 113421364, 1615760212, 1688217556, 1223719184, 536568131, 1682609873, 2935161,
-414769471, -1027490137, 1602276102, 1050490461 ]
} --></div></div>
<div class="section">
<h2><a name="TemporalFunctions" id="TemporalFunctions">Temporal Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Temporal_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>get-year/get-month/get-day/get-hour/get-minute/get-second/get-millisecond<a name="get-yearget-monthget-dayget-hourget-minuteget-secondget-millisecond"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-year/get-month/get-day/get-hour/get-minute/get-second/get-millisecond(temporal_expression)
</pre></div></li>
<li>
<p>Accessors for accessing fields in a temporal value</p></li>
<li>Arguments:
<ul>
<li><tt>temporal_expression</tt> : a temporal value represented as one of the following types: <tt>date</tt>, <tt>datetime</tt>, <tt>time</tt>, and <tt>duration</tt>.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int64</tt> value representing the field to be extracted.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $c1 := date(&quot;2010-10-30&quot;)
let $c2 := datetime(&quot;1987-11-19T23:49:23.938&quot;)
let $c3 := time(&quot;12:23:34.930+07:00&quot;)
let $c4 := duration(&quot;P3Y73M632DT49H743M3948.94S&quot;)
return {&quot;year&quot;: get-year($c1), &quot;month&quot;: get-month($c2), &quot;day&quot;: get-day($c1), &quot;hour&quot;: get-hour($c3), &quot;min&quot;: get-minute($c4), &quot;second&quot;: get-second($c2), &quot;ms&quot;: get-millisecond($c4)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;year&quot;: 2010, &quot;month&quot;: 11, &quot;day&quot;: 30, &quot;hour&quot;: 5, &quot;min&quot;: 28, &quot;second&quot;: 23, &quot;ms&quot;: 94 }
</pre></div></li>
</ul></div>
<div class="section">
<h3>adjust-datetime-for-timezone<a name="adjust-datetime-for-timezone"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>adjust-datetime-for-timezone(datetime_expression, string_expression)
</pre></div></li>
<li>
<p>Adjusts the given datetime <tt>datetime_expression</tt> by applying the timezone information <tt>string_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>datetime_expression</tt> : A <tt>datetime</tt> value to be adjusted.</li>
<li><tt>string_expression</tt> : A <tt>string</tt> representing the timezone information.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> value representing the new datetime after being adjusted by the timezone information.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('TweetMessages')
return {&quot;adjusted-send-time&quot;: adjust-datetime-for-timezone($i.send-time, &quot;+08:00&quot;), &quot;message&quot;: $i.message-text}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;adjusted-send-time&quot;: &quot;2008-04-26T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; love t-mobile its customization is good:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2010-05-13T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like verizon its shortcut-menu is awesome:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2006-11-04T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like motorola the speed is good:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2011-12-26T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like sprint the voice-command is mind-blowing:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2006-08-04T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; can't stand motorola its speed is terrible:(&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2010-05-07T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like iphone the voice-clarity is good:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2011-08-25T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like samsung the platform is good&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2005-10-14T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like t-mobile the shortcut-menu is awesome:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2012-07-21T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; love verizon its voicemail-service is awesome&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2008-01-26T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; hate verizon its voice-clarity is OMG:(&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2008-03-09T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; can't stand iphone its platform is terrible&quot; }
{ &quot;adjusted-send-time&quot;: &quot;2010-02-13T18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like samsung the voice-command is amazing:)&quot; }
</pre></div></li>
</ul></div>
<div class="section">
<h3>adjust-time-for-timezone<a name="adjust-time-for-timezone"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>adjust-time-for-timezone(time_expression, string_expression)
</pre></div></li>
<li>
<p>Adjusts the given time <tt>time_expression</tt> by applying the timezone information <tt>string_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>time_expression</tt> : A <tt>time</tt> value to be adjusted.</li>
<li><tt>string_expression</tt> : A <tt>string</tt> representing the timezone information.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> value representing the new time after being adjusted by the timezone information.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('TweetMessages')
return {&quot;adjusted-send-time&quot;: adjust-time-for-timezone(time-from-datetime($i.send-time), &quot;+08:00&quot;), &quot;message&quot;: $i.message-text}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; love t-mobile its customization is good:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like verizon its shortcut-menu is awesome:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like motorola the speed is good:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like sprint the voice-command is mind-blowing:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; can't stand motorola its speed is terrible:(&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like iphone the voice-clarity is good:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like samsung the platform is good&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like t-mobile the shortcut-menu is awesome:)&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; love verizon its voicemail-service is awesome&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; hate verizon its voice-clarity is OMG:(&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; can't stand iphone its platform is terrible&quot; }
{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like samsung the voice-command is amazing:)&quot; }
</pre></div></li>
</ul></div>
<div class="section">
<h3>calendar-duration-from-datetime<a name="calendar-duration-from-datetime"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>calendar-duration-from-datetime(datetime_expression, duration_expression)
</pre></div></li>
<li>
<p>Gets a user-friendly representation of the duration <tt>duration_expression</tt> based on the given datetime <tt>datetime_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>datetime_expression</tt> : A <tt>datetime</tt> value to be used as the reference time point.</li>
<li><tt>duration_expression</tt> : A <tt>duration</tt> value to be converted.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>duration</tt> value with the duration as <tt>duration_expression</tt> but with a user-friendly representation.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('TweetMessages')
where $i.send-time &gt; datetime(&quot;2011-01-01T00:00:00&quot;)
return {&quot;since-2011&quot;: subtract-datetime($i.send-time, datetime(&quot;2011-01-01T00:00:00&quot;)), &quot;since-2011-user-friendly&quot;: calendar-duration-from-datetime($i.send-time, subtract-datetime($i.send-time, datetime(&quot;2011-01-01T00:00:00&quot;)))}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;since-2011&quot;: duration(&quot;P359DT10H10M&quot;), &quot;since-2011-user-friendly&quot;: duration(&quot;P11M23DT10H10M&quot;) }
{ &quot;since-2011&quot;: duration(&quot;P236DT10H10M&quot;), &quot;since-2011-user-friendly&quot;: duration(&quot;P7M23DT10H10M&quot;) }
{ &quot;since-2011&quot;: duration(&quot;P567DT10H10M&quot;), &quot;since-2011-user-friendly&quot;: duration(&quot;P1Y6M18DT10H10M&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-year-month-duration/get-day-time-duration<a name="get-year-month-durationget-day-time-duration"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-year-month-duration/get-day-time-duration(duration_expression)
</pre></div></li>
<li>
<p>Extracts the correct <tt>duration</tt> subtype from <tt>duration_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>duration_expression</tt> : A <tt>duration</tt> value to be converted.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>year-month-duration</tt> value or a <tt>day-time-duration</tt> value.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := get-year-month-duration(duration(&quot;P12M50DT10H&quot;))
return $i;
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>year-month-duration(&quot;P1Y&quot;)
</pre></div></li>
</ul></div>
<div class="section">
<h3>months-from-year-month-duration/milliseconds-from-day-time-duration<a name="months-from-year-month-durationmilliseconds-from-day-time-duration"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>months-from-year-month-duration/milliseconds-from-day-time-duration(duration_expression)
</pre></div></li>
<li>
<p>Extracts the number of months or the number of milliseconds from the <tt>duration</tt> subtype.</p></li>
<li>Arguments:
<ul>
<li><tt>duration_expression</tt> : A <tt>duration</tt> of the correct subtype.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int64</tt> representing the number or months/milliseconds.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := months-from-year-month-duration(get-year-month-duration(duration(&quot;P5Y7MT50M&quot;)))
return $i;
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>67
</pre></div></li>
</ul></div>
<div class="section">
<h3>duration-from-months/duration-from-ms<a name="duration-from-monthsduration-from-ms"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>duration-from-months/duration-from-ms(number_expression)
</pre></div></li>
<li>
<p>Creates a <tt>duration</tt> from <tt>number_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>number_expression</tt> : An <tt>int64</tt> representing the number of months/milliseconds</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>duration</tt> containing <tt>number_expression</tt> value for months/milliseconds</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := duration-from-months(8)
return $i;
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>duration(&quot;P8M&quot;)
</pre></div></li>
</ul></div>
<div class="section">
<h3>duration-from-interval<a name="duration-from-interval"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>duration-from-interval(interval_expression)
</pre></div></li>
<li>
<p>Creates a <tt>duration</tt> from <tt>interval_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>interval_expression</tt> : An <tt>interval</tt> value</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>duration</tt> repesenting the time in the <tt>interval_expression</tt></li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $itv1 := interval-from-date(&quot;2010-10-30&quot;, &quot;2010-12-21&quot;)
let $itv2 := interval-from-datetime(&quot;2012-06-26T01:01:01.111&quot;, &quot;2012-07-27T02:02:02.222&quot;)
let $itv3 := interval-from-time(&quot;12:32:38&quot;, &quot;20:29:20&quot;)
return { &quot;dr1&quot; : duration-from-interval($itv1),
&quot;dr2&quot; : duration-from-interval($itv2),
&quot;dr3&quot; : duration-from-interval($itv3),
&quot;dr4&quot; : duration-from-interval(null) }
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;dr1&quot;: day-time-duration(&quot;P52D&quot;),
&quot;dr2&quot;: day-time-duration(&quot;P31DT1H1M1.111S&quot;),
&quot;dr3&quot;: day-time-duration(&quot;PT7H56M42S&quot;),
&quot;dr4&quot;: null }
</pre></div></li>
</ul></div>
<div class="section">
<h3>current-date<a name="current-date"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>current-date()
</pre></div></li>
<li>
<p>Gets the current date.</p></li>
<li>Arguments: None</li>
<li>Return Value:
<ul>
<li>A <tt>date</tt> value of the date when the function is called.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>current-time<a name="current-time"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>current-time()
</pre></div></li>
<li>
<p>Get the current time</p></li>
<li>Arguments: None</li>
<li>Return Value:
<ul>
<li>A <tt>time</tt> value of the time when the function is called.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>current-datetime<a name="current-datetime"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>current-datetime()
</pre></div></li>
<li>
<p>Get the current datetime</p></li>
<li>Arguments: None</li>
<li>Return Value:
<ul>
<li>A <tt>datetime</tt> value of the datetime when the function is called.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>{&quot;current-date&quot;: current-date(),
&quot;current-time&quot;: current-time(),
&quot;current-datetime&quot;: current-datetime()}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;current-date&quot;: date(&quot;2013-04-06&quot;),
&quot;current-time&quot;: time(&quot;00:48:44.093Z&quot;),
&quot;current-datetime&quot;: datetime(&quot;2013-04-06T00:48:44.093Z&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-date-from-datetime<a name="get-date-from-datetime"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-date-from-datetime(datetime_expression)
</pre></div></li>
<li>
<p>Gets the date value from the given datetime value <tt>datetime_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>datetime_expression</tt>: A <tt>datetime</tt> value to be extracted from.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>date</tt> value from the datetime.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>get-time-from-datetime<a name="get-time-from-datetime"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-time-from-datetime(datetime_expression)
</pre></div></li>
<li>
<p>Get the time value from the given datetime value <tt>datetime_expression</tt></p></li>
<li>Arguments:
<ul>
<li><tt>datetime_expression</tt>: A <tt>datetime</tt> value to be extracted from</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>time</tt> value from the datetime.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
for $i in dataset('TweetMessages')
where $i.send-time &gt; datetime(&quot;2011-01-01T00:00:00&quot;)
return {&quot;send-date&quot;: get-date-from-datetime($i.send-time), &quot;send-time&quot;: get-time-from-datetime($i.send-time)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;send-date&quot;: date(&quot;2011-12-26&quot;), &quot;send-time&quot;: time(&quot;10:10:00.000Z&quot;) }
{ &quot;send-date&quot;: date(&quot;2011-08-25&quot;), &quot;send-time&quot;: time(&quot;10:10:00.000Z&quot;) }
{ &quot;send-date&quot;: date(&quot;2012-07-21&quot;), &quot;send-time&quot;: time(&quot;10:10:00.000Z&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>day-of-week<a name="day-of-week"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>day-of-week(date_expression)
</pre></div></li>
<li>
<p>Finds the day of the week for a given date (1-7)</p></li>
<li>Arguments:
<ul>
<li><tt>date_expression</tt>: A <tt>date</tt> value (Can also be a <tt>datetime</tt>)</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>int8</tt> representing the day of the week (1-7)</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := day-of-week( datetime(&quot;2012-12-30T12:12:12.039Z&quot;))
return $i;
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>7
</pre></div></li>
</ul></div>
<div class="section">
<h3>date-from-unix-time-in-days<a name="date-from-unix-time-in-days"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>date-from-unix-time-in-days(numeric_expression)
</pre></div></li>
<li>
<p>Gets a date representing the time after <tt>numeric_expression</tt> days since 1970-01-01.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt> value representing the number of days.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>date</tt> value as the time after <tt>numeric_expression</tt> days since 1970-01-01.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>datetime-from-unix-time-in-ms<a name="datetime-from-unix-time-in-ms"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>datetime-from-unix-time-in-ms(numeric_expression)
</pre></div></li>
<li>
<p>Gets a datetime representing the time after <tt>numeric_expression</tt> milliseconds since 1970-01-01T00:00:00Z.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt> value representing the number of milliseconds.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>datetime</tt> value as the time after <tt>numeric_expression</tt> milliseconds since 1970-01-01T00:00:00Z.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>datetime-from-unix-time-in-secs<a name="datetime-from-unix-time-in-secs"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>datetime-from-unix-time-in-secs(numeric_expression)
</pre></div></li>
<li>
<p>Gets a datetime representing the time after <tt>numeric_expression</tt> seconds since 1970-01-01T00:00:00Z.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt> value representing the number of seconds.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>datetime</tt> value as the time after <tt>numeric_expression</tt> seconds since 1970-01-01T00:00:00Z.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>datetime-from-date-time<a name="datetime-from-date-time"></a></h3>
<ul>
<li>Syntax:</li>
</ul>
<p>datetime-from-date-time(date_expression,time_expression)</p>
<ul>
<li>Gets a datetime representing the combination of <tt>date_expression</tt> and <tt>time_expression</tt>
<ul>
<li>Arguments:</li>
<li><tt>date_expression</tt>: A <tt>date</tt> value</li>
<li><tt>time_expression</tt> A <tt>time</tt> value</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>datetime</tt> value by combining <tt>date_expression</tt> and <tt>time_expression</tt></li>
</ul></li>
</ul></div>
<div class="section">
<h3>time-from-unix-time-in-ms<a name="time-from-unix-time-in-ms"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>time-from-unix-time-in-ms(numeric_expression)
</pre></div></li>
<li>
<p>Gets a time representing the time after <tt>numeric_expression</tt> milliseconds since 00:00:00.000Z.</p></li>
<li>Arguments:
<ul>
<li><tt>numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt> value representing the number of milliseconds.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>time</tt> value as the time after <tt>numeric_expression</tt> milliseconds since 00:00:00.000Z.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $d := date-from-unix-time-in-days(15800)
let $dt := datetime-from-unix-time-in-ms(1365139700000)
let $t := time-from-unix-time-in-ms(3748)
return {&quot;date&quot;: $d, &quot;datetime&quot;: $dt, &quot;time&quot;: $t}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;date&quot;: date(&quot;2013-04-05&quot;), &quot;datetime&quot;: datetime(&quot;2013-04-05T05:28:20.000Z&quot;), &quot;time&quot;: time(&quot;00:00:03.748Z&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>parse-date/parse-time/parse-datetime<a name="parse-dateparse-timeparse-datetime"></a></h3>
<ul>
<li>Syntax:</li>
</ul>
<p>parse-date/parse-time/parse-datetime(date_expression,formatting_expression)</p>
<ul>
<li>Creates a <tt>date/time/date-time</tt> value by treating <tt>date_expression</tt> with formatting <tt>formatting_expression</tt></li>
<li>Arguments:
<ul>
<li><tt>date_expression</tt>: A <tt>string</tt> value representing the <tt>date/time/datetime</tt>.</li>
<li><tt>formatting_expression</tt> A <tt>string</tt> value providing the formatting for <tt>date_expression</tt>.Characters used to create date expression:</li>
<li><tt>h</tt> hours</li>
<li><tt>m</tt> minutes</li>
<li><tt>s</tt> seconds</li>
<li><tt>n</tt> milliseconds</li>
<li><tt>a</tt> am/pm</li>
<li><tt>z</tt> timezone</li>
<li><tt>Y</tt> year</li>
<li><tt>M</tt> month</li>
<li><tt>D</tt> day</li>
<li><tt>W</tt> weekday</li>
<li><tt>-</tt>, <tt>'</tt>, <tt>/</tt>, <tt>.</tt>, <tt>,</tt>, <tt>T</tt> seperators for both time and date</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>date/time/date-time</tt> value corresponding to <tt>date_expression</tt></li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := parse-time(&quot;30:30&quot;,&quot;m:s&quot;)
return $i;
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>time(&quot;00:30:30.000Z&quot;)
</pre></div></li>
</ul></div>
<div class="section">
<h3>print-date/print-time/print-datetime<a name="print-dateprint-timeprint-datetime"></a></h3>
<ul>
<li>Syntax:</li>
</ul>
<p>print-date/print-time/print-datetime(date_expression,formatting_expression)</p>
<ul>
<li>Creates a <tt>string</tt> representing a <tt>date/time/date-time</tt> value of the <tt>date_expression</tt> using the formatting <tt>formatting_expression</tt></li>
<li>Arguments:
<ul>
<li><tt>date_expression</tt>: A <tt>date/time/datetime</tt> value.</li>
<li><tt>formatting_expression</tt> A <tt>string</tt> value providing the formatting for <tt>date_expression</tt>. Characters used to create date expression:</li>
<li><tt>h</tt> hours</li>
<li><tt>m</tt> minutes</li>
<li><tt>s</tt> seconds</li>
<li><tt>n</tt> milliseconds</li>
<li><tt>a</tt> am/pm</li>
<li><tt>z</tt> timezone</li>
<li><tt>Y</tt> year</li>
<li><tt>M</tt> month</li>
<li><tt>D</tt> day</li>
<li><tt>W</tt> weekday</li>
<li><tt>-</tt>, <tt>'</tt>, <tt>/</tt>, <tt>.</tt>, <tt>,</tt>, <tt>T</tt> seperators for both time and date</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>string</tt> value corresponding to <tt>date_expression</tt></li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $i := print-time(time(&quot;00:30:30.000Z&quot;),&quot;m:s&quot;)
return $i;
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;30:30&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-interval-start, get-interval-end<a name="get-interval-start_get-interval-end"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-interval-start/get-interval-end(interval)
</pre></div></li>
<li>
<p>Gets the start/end of the given interval.</p></li>
<li>Arguments:
<ul>
<li><tt>interval</tt>: the interval to be accessed.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>time</tt>, <tt>date</tt>, or <tt>datetime</tt> (depending on the time instances of the interval) representing the starting or ending time.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $itv := interval-start-from-date(&quot;1984-01-01&quot;, &quot;P1Y&quot;)
return {&quot;start&quot;: get-interval-start($itv), &quot;end&quot;: get-interval-end($itv)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;start&quot;: date(&quot;1984-01-01&quot;), &quot;end&quot;: date(&quot;1985-01-01&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-interval-start-date/get-interval-start-datetimeget-interval-start-time, get-interval-end-date/get-interval-end-datetime/get-interval-end-time<a name="get-interval-start-dateget-interval-start-datetimeget-interval-start-time_get-interval-end-dateget-interval-end-datetimeget-interval-end-time"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-interval-start-date/get-interval-start-datetime/get-interval-start-time/get-interval-end-date/get-interval-end-datetime/get-interval-end-time(interval)
</pre></div></li>
<li>
<p>Gets the start/end of the given interval for the specific date/datetime/time type.</p></li>
<li>Arguments:
<ul>
<li><tt>interval</tt>: the interval to be accessed.</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>time</tt>, <tt>date</tt>, or <tt>datetime</tt> (depending on the function) representing the starting or ending time.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $itv1 := interval-start-from-date(&quot;1984-01-01&quot;, &quot;P1Y&quot;)
let $itv2 := interval-start-from-datetime(&quot;1984-01-01T08:30:00.000&quot;, &quot;P1Y1H&quot;)
let $itv3 := interval-start-from-time(&quot;08:30:00.000&quot;, &quot;P1H&quot;)
return {&quot;start&quot;: get-interval-start-date($itv1), &quot;end&quot;: get-interval-end-date($itv1), &quot;start&quot;: get-interval-start-datetime($itv2), &quot;end&quot;: get-interval-end-datetime($itv2), &quot;start&quot;: get-interval-start-time($itv3), &quot;end&quot;: get-interval-end-time($itv3)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;start&quot;: date(&quot;1984-01-01&quot;), &quot;end&quot;: date(&quot;1985-01-01&quot;), &quot;start&quot;: datetime(&quot;1984-01-01T08:30:00.000&quot;), &quot;end&quot;: datetime(&quot;1984-02-01T09:30:00.000&quot;), &quot;start&quot;: date(&quot;08:30:00.000&quot;), &quot;end&quot;: time(&quot;09:30:00.000&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>get-overlapping-interval<a name="get-overlapping-interval"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>get-overlapping-interval(interval_expression_1, interval_expression_2)
</pre></div></li>
<li>
<p>Gets the start/end of the given interval for the specific date/datetime/time type.</p></li>
<li>Arguments:
<ul>
<li><tt>interval_expression_1</tt>: an <tt>interval</tt> value</li>
<li><tt>interval_expression_2</tt>: an <tt>interval</tt> value</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns an <tt>interval</tt> that is overlapping <tt>interval_expression_1</tt> and <tt>interval_expression_2</tt>. If <tt>interval_expression_1</tt> and <tt>interval_expression_2</tt> do not overlap <tt>null</tt> is returned. Note each interval must be of the same type.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>{ &quot;overlap1&quot;: get-overlapping-interval(interval-from-time(time(&quot;11:23:39&quot;), time(&quot;18:27:19&quot;)), interval-from-time(time(&quot;12:23:39&quot;), time(&quot;23:18:00&quot;))),
&quot;overlap2&quot;: get-overlapping-interval(interval-from-time(time(&quot;12:23:39&quot;), time(&quot;18:27:19&quot;)), interval-from-time(time(&quot;07:19:39&quot;), time(&quot;09:18:00&quot;))),
&quot;overlap3&quot;: get-overlapping-interval(interval-from-date(date(&quot;1980-11-30&quot;), date(&quot;1999-09-09&quot;)), interval-from-date(date(&quot;2013-01-01&quot;), date(&quot;2014-01-01&quot;))),
&quot;overlap4&quot;: get-overlapping-interval(interval-from-date(date(&quot;1980-11-30&quot;), date(&quot;2099-09-09&quot;)), interval-from-date(date(&quot;2013-01-01&quot;), date(&quot;2014-01-01&quot;))),
&quot;overlap5&quot;: get-overlapping-interval(interval-from-datetime(datetime(&quot;1844-03-03T11:19:39&quot;), datetime(&quot;2000-10-30T18:27:19&quot;)), interval-from-datetime(datetime(&quot;1989-03-04T12:23:39&quot;), datetime(&quot;2009-10-10T23:18:00&quot;))),
&quot;overlap6&quot;: get-overlapping-interval(interval-from-datetime(datetime(&quot;1989-03-04T12:23:39&quot;), datetime(&quot;2000-10-30T18:27:19&quot;)), interval-from-datetime(datetime(&quot;1844-03-03T11:19:39&quot;), datetime(&quot;1888-10-10T23:18:00&quot;))) }
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;overlap1&quot;: interval-time(&quot;12:23:39.000Z, 18:27:19.000Z&quot;),
&quot;overlap2&quot;: null,
&quot;overlap3&quot;: null,
&quot;overlap4&quot;: interval-date(&quot;2013-01-01, 2014-01-01&quot;),
&quot;overlap5&quot;: interval-datetime(&quot;1989-03-04T12:23:39.000Z, 2000-10-30T18:27:19.000Z&quot;),
&quot;overlap6&quot;: null }
</pre></div></li>
</ul></div>
<div class="section">
<h3>interval-before/interval-after/interval-meets/interval-met-by/interval-overlaps/interval-overlapped-by/interval-overlapping/interval-starts/interval-started-by/interval-covers/interval-covered-by/interval-ends/interval-ended-by<a name="interval-beforeinterval-afterinterval-meetsinterval-met-byinterval-overlapsinterval-overlapped-byinterval-overlappinginterval-startsinterval-started-byinterval-coversinterval-covered-byinterval-endsinterval-ended-by"></a></h3>
<p>See the <a href="allens.html">Allen&#x2019;s Relations</a>.</p></div>
<div class="section">
<h3>interval-bin<a name="interval-bin"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>interval-bin(time-to-bin, time-bin-anchor, duration-bin-size)
</pre></div></li>
<li>
<p>Return the <tt>interval</tt> value representing the bin containing the <tt>time-to-bin</tt> value.</p></li>
<li>Arguments:
<ul>
<li><tt>time-to-bin</tt>: a date/time/datetime value representing the time to be binned.</li>
<li><tt>time-bin-anchor</tt>: a date/time/datetime value representing an anchor of a bin starts. The type of this argument should be the same as the first <tt>time-to-bin</tt> argument.</li>
<li><tt>duration-bin-size</tt>: the duration value representing the size of the bin, in the type of year-month-duration or day-time-duration. The type of this duration should be compatible with the type of <tt>time-to-bin</tt>, so that the arithmetic operation between <tt>time-to-bin</tt> and <tt>duration-bin-size</tt> is well-defined. Currently AsterixDB supports the following arithmetic operations:
<ul>
<li>datetime +|- year-month-duration</li>
<li>datetime +|- day-time-duration</li>
<li>date +|- year-month-duration</li>
<li>date +|- day-time-duration</li>
<li>time +|- day-time-duration</li>
</ul></li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>interval</tt> value representing the bin containing the <tt>time-to-bin</tt> value. Note that the internal type of this interval value should be the same as the <tt>time-to-bin</tt> type.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $c1 := date(&quot;2010-10-30&quot;)
let $c2 := datetime(&quot;-1987-11-19T23:49:23.938&quot;)
let $c3 := time(&quot;12:23:34.930+07:00&quot;)
return { &quot;bin1&quot;: interval-bin($c1, date(&quot;1990-01-01&quot;), year-month-duration(&quot;P1Y&quot;)),
&quot;bin2&quot;: interval-bin($c2, datetime(&quot;1990-01-01T00:00:00.000Z&quot;), year-month-duration(&quot;P6M&quot;)),
&quot;bin3&quot;: interval-bin($c3, time(&quot;00:00:00&quot;), day-time-duration(&quot;PD1M&quot;)),
&quot;bin4&quot;: interval-bin($c2, datetime(&quot;2013-01-01T00:00:00.000&quot;), day-time-duration(&quot;PT24H&quot;))
</pre></div> }</li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;bin1&quot;: interval-date(&quot;2010-01-01, 2011-01-01&quot;),
&quot;bin2&quot;: interval-datetime(&quot;-1987-07-01T00:00:00.000Z, -1986-01-01T00:00:00.000Z&quot;),
&quot;bin3&quot;: interval-time(&quot;05:23:00.000Z, 05:24:00.000Z&quot;),
&quot;bin4&quot;: interval-datetime(&quot;-1987-11-19T00:00:00.000Z, -1987-11-20T00:00:00.000Z&quot;)}
</pre></div></li>
</ul></div>
<div class="section">
<h3>interval-from-date<a name="interval-from-date"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>interval-from-date(string_expression1, string_expression2)
</pre></div></li>
<li>
<p>Constructor function for the <tt>interval</tt> type by parsing two date strings.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression1</tt> : The <tt>string</tt> value representing the starting date.</li>
<li><tt>string_expression2</tt> : The <tt>string</tt> value representing the ending date.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>interval</tt> value between the two dates.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>{&quot;date-interval&quot;: interval-from-date(&quot;2012-01-01&quot;, &quot;2013-04-01&quot;)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;date-interval&quot;: interval-date(&quot;2012-01-01, 2013-04-01&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>interval-from-time<a name="interval-from-time"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>interval-from-time(string_expression1, string_expression2)
</pre></div></li>
<li>
<p>Constructor function for the <tt>interval</tt> type by parsing two time strings.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression1</tt> : The <tt>string</tt> value representing the starting time.</li>
<li><tt>string_expression2</tt> : The <tt>string</tt> value representing the ending time.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>interval</tt> value between the two times.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>{&quot;time-interval&quot;: interval-from-time(&quot;12:23:34.456Z&quot;, &quot;233445567+0800&quot;)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;time-interval&quot;: interval-time(&quot;12:23:34.456Z, 15:34:45.567Z&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>interval-from-datetime<a name="interval-from-datetime"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>interval-from-datetime(string_expression1, string_expression2)
</pre></div></li>
<li>
<p>Constructor function for <tt>interval</tt> type by parsing two datetime strings.</p></li>
<li>Arguments:
<ul>
<li><tt>string_expression1</tt> : The <tt>string</tt> value representing the starting datetime.</li>
<li><tt>string_expression2</tt> : The <tt>string</tt> value representing the ending datetime.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>interval</tt> value between the two datetimes.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>{&quot;datetime-interval&quot;: interval-from-datetime(&quot;2012-01-01T12:23:34.456+08:00&quot;, &quot;20130401T153445567Z&quot;)}
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;datetime-interval&quot;: interval-datetime(&quot;2012-01-01T04:23:34.456Z, 2013-04-01T15:34:45.567Z&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>interval-start-from-date/time/datetime<a name="interval-start-from-datetimedatetime"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>interval-start-from-date/time/datetime(date/time/datetime, duration)
</pre></div></li>
<li>
<p>Construct an <tt>interval</tt> value by the given starting <tt>date</tt>/<tt>time</tt>/<tt>datetime</tt> and the <tt>duration</tt> that the interval lasts.</p></li>
<li>Arguments:
<ul>
<li><tt>date/time/datetime</tt>: a <tt>string</tt> representing a <tt>date</tt>, <tt>time</tt> or <tt>datetime</tt>, or a <tt>date</tt>/<tt>time</tt>/<tt>datetime</tt> value, representing the starting time point.</li>
<li><tt>duration</tt>: a <tt>string</tt> or <tt>duration</tt> value representing the duration of the interval. Note that duration cannot be negative value.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>interval</tt> value representing the interval starting from the given time point with the length of duration.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $itv1 := interval-start-from-date(&quot;1984-01-01&quot;, &quot;P1Y&quot;)
let $itv2 := interval-start-from-time(time(&quot;02:23:28.394&quot;), &quot;PT3H24M&quot;)
let $itv3 := interval-start-from-datetime(&quot;1999-09-09T09:09:09.999&quot;, duration(&quot;P2M30D&quot;))
return {&quot;interval1&quot;: $itv1, &quot;interval2&quot;: $itv2, &quot;interval3&quot;: $itv3}
</pre></div></li>
<li>
<p>The expectecd result is:</p>
<div class="source">
<pre>{ &quot;interval1&quot;: interval-date(&quot;1984-01-01, 1985-01-01&quot;), &quot;interval2&quot;: interval-time(&quot;02:23:28.394Z, 05:47:28.394Z&quot;), &quot;interval3&quot;: interval-datetime(&quot;1999-09-09T09:09:09.999Z, 1999-12-09T09:09:09.999Z&quot;) }
</pre></div></li>
</ul></div>
<div class="section">
<h3>overlap-bins<a name="overlap-bins"></a></h3>
<ul>
<li>
<p>Return Value:</p>
<ul>
<li>A <tt>interval</tt> value representing the bin containing the <tt>time-to-bin</tt> value. Note that the internal type of this interval value should be the same as the <tt>time-to-bin</tt> type.</li>
</ul></li>
<li>
<p>Syntax:</p>
<div class="source">
<pre>overlap-bins(interval_expression, time-bin-anchor, duration-bin-size)
</pre></div></li>
<li>
<p>Returns an ordered list of <tt>interval</tt> values representing each bin that is overlapping the <tt>interval_expression</tt>.</p></li>
<li>Arguments:
<ul>
<li><tt>interval_expression</tt>: an <tt>interval</tt> value</li>
<li><tt>time-bin-anchor</tt>: a date/time/datetime value representing an anchor of a bin starts. The type of this argument should be the same as the first <tt>time-to-bin</tt> argument.</li>
<li><tt>duration-bin-size</tt>: the duration value representing the size of the bin, in the type of year-month-duration or day-time-duration. The type of this duration should be compatible with the type of <tt>time-to-bin</tt>, so that the arithmetic operation between <tt>time-to-bin</tt> and <tt>duration-bin-size</tt> is well-defined. Currently AsterixDB supports the following arithmetic operations:
<ul>
<li>datetime +|- year-month-duration</li>
<li>datetime +|- day-time-duration</li>
<li>date +|- year-month-duration</li>
<li>date +|- day-time-duration</li>
<li>time +|- day-time-duration</li>
</ul></li>
</ul></li>
<li>Return Value:
<ul>
<li>A ordered list of <tt>interval</tt> values representing each bin that is overlapping the <tt>interval_expression</tt>. Note that the internal type as <tt>time-to-bin</tt> and <tt>duration-bin-size</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>let $itv1 := interval-from-time(time(&quot;17:23:37&quot;), time(&quot;18:30:21&quot;))
let $itv2 := interval-from-date(date(&quot;1984-03-17&quot;), date(&quot;2013-08-22&quot;))
let $itv3 := interval-from-datetime(datetime(&quot;1800-01-01T23:59:48.938&quot;), datetime(&quot;2015-07-26T13:28:30.218&quot;))
return { &quot;timebins&quot;: overlap-bins($itv1, time(&quot;00:00:00&quot;), day-time-duration(&quot;PT30M&quot;)),
&quot;datebins&quot;: overlap-bins($itv2, date(&quot;1990-01-01&quot;), year-month-duration(&quot;P20Y&quot;)),
&quot;datetimebins&quot;: overlap-bins($itv3, datetime(&quot;1900-01-01T00:00:00.000&quot;), year-month-duration(&quot;P100Y&quot;)) }
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>{ &quot;timebins&quot;: [ interval-time(&quot;17:00:00.000Z, 17:30:00.000Z&quot;), interval-time(&quot;17:30:00.000Z, 18:00:00.000Z&quot;), interval-time(&quot;18:00:00.000Z, 18:30:00.000Z&quot;), interval-time(&quot;18:30:00.000Z, 19:00:00.000Z&quot;) ],
&quot;datebins&quot;: [ interval-date(&quot;1970-01-01, 1990-01-01&quot;), interval-date(&quot;1990-01-01, 2010-01-01&quot;), interval-date(&quot;2010-01-01, 2030-01-01&quot;) ],
&quot;datetimebins&quot;: [ interval-datetime(&quot;1800-01-01T00:00:00.000Z, 1900-01-01T00:00:00.000Z&quot;), interval-datetime(&quot;1900-01-01T00:00:00.000Z, 2000-01-01T00:00:00.000Z&quot;), interval-datetime(&quot;2000-01-01T00:00:00.000Z, 2100-01-01T00:00:00.000Z&quot;) ] }
</pre></div></li>
</ul></div></div>
<div class="section">
<h2><a name="OtherFunctions" id="OtherFunctions">Other Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font><a name="Other_Functions_Back_to_TOC"></a></h2>
<div class="section">
<h3>create-uuid<a name="create-uuid"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>create-uuid()
</pre></div></li>
<li>
<p>Generates a <tt>uuid</tt>.</p></li>
<li>Arguments:
<ul>
<li>none</li>
</ul></li>
<li>Return Value:
<ul>
<li>A generated <tt>uuid</tt>.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>is-null<a name="is-null"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>is-null(var)
</pre></div></li>
<li>
<p>Checks whether the given variable is a <tt>null</tt> value.</p></li>
<li>Arguments:
<ul>
<li><tt>var</tt> : A variable (any type is allowed).</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt> on whether the variable is a <tt>null</tt> or not.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>for $m in ['hello', 'world', null]
where not(is-null($m))
return $m
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;hello&quot;
&quot;world&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>is-system-null<a name="is-system-null"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>is-system-null(var)
</pre></div></li>
<li>
<p>Checks whether the given variable is a <tt>system null</tt> value.</p></li>
<li>Arguments:
<ul>
<li><tt>var</tt> : A variable (any type is allowed).</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt> on whether the variable is a <tt>system null</tt> or not.</li>
</ul></li>
</ul></div>
<div class="section">
<h3>len<a name="len"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<p>len(list_expression)</p></li>
<li>
<p>Returns the length of the list list_expression.</p></li>
<li>Arguments:
<ul>
<li><tt>list_expression</tt> : An <tt>OrderedList</tt>, <tt>UnorderedList</tt> or <tt>null</tt>, represents the list need to be checked.</li>
</ul></li>
<li>Return Value:
<ul>
<li>An <tt>Int32</tt> that represents the length of list_expression.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>use dataverse TinySocial;
let $l := [&quot;ASTERIX&quot;, &quot;Hyracks&quot;]
return len($l)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>2
</pre></div></li>
</ul></div>
<div class="section">
<h3>not<a name="not"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>not(var)
</pre></div></li>
<li>
<p>Inverts a <tt>boolean</tt> value</p></li>
<li>Arguments:
<ul>
<li><tt>var</tt> : A <tt>boolean</tt> (or <tt>null</tt>)</li>
</ul></li>
<li>Return Value:
<ul>
<li>A <tt>boolean</tt>, the inverse of <tt>var</tt>. returns <tt>null</tt> if <tt>var</tt> is null</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>for $m in ['hello', 'world', null]
where not(is-null($m))
return $m
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>&quot;hello&quot;
&quot;world&quot;
</pre></div></li>
</ul></div>
<div class="section">
<h3>range<a name="range"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>range(start_numeric_expression, end_numeric_expression)
</pre></div></li>
<li>
<p>Generates a series of <tt>int64</tt> values based start the <tt>start_numeric_expression</tt> until the <tt>end_numeric_expression</tt>. The <tt>range</tt> fucntion must be used list argument of a <tt>for</tt> expression.</p></li>
<li>Arguments:</li>
<li><tt>start_numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt> value representing the start value.</li>
<li><tt>end_numeric_expression</tt>: A <tt>int8</tt>/<tt>int16</tt>/<tt>int32</tt>/<tt>int64</tt> value representing the max final value.</li>
<li>Return Value:
<ul>
<li>A generated <tt>uuid</tt>.</li>
</ul></li>
<li>
<p>Example:</p>
<div class="source">
<pre>for $i in range(0, 3)
return $i;
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>[ 0
, 1
, 2
, 3
]
</pre></div></li>
</ul></div>
<div class="section">
<h3>switch-case<a name="switch-case"></a></h3>
<ul>
<li>
<p>Syntax:</p>
<div class="source">
<pre>switch-case(condition,
case1, case1-result,
case2, case2-result,
...,
default, default-result
)
</pre></div></li>
<li>
<p>Switches amongst a sequence of cases and returns the result of the first matching case. If no match is found, the result of the default case is returned.</p></li>
<li>Arguments:
<ul>
<li><tt>condition</tt>: A variable (any type is allowed).</li>
<li><tt>caseI/default</tt>: A variable (any type is allowed).</li>
<li><tt>caseI/default-result</tt>: A variable (any type is allowed).</li>
</ul></li>
<li>Return Value:
<ul>
<li>Returns <tt>caseI-result</tt> if <tt>condition</tt> matches <tt>caseI</tt>, otherwise <tt>default-result</tt>.</li>
</ul></li>
<li>
<p>Example 1:</p>
<div class="source">
<pre>switch-case(&quot;a&quot;,
&quot;a&quot;, 0,
&quot;x&quot;, 1,
&quot;y&quot;, 2,
&quot;z&quot;, 3
)
</pre></div></li>
</ul>
<ul>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>0
</pre></div></li>
<li>
<p>Example 2:</p>
<div class="source">
<pre>switch-case(&quot;a&quot;,
&quot;x&quot;, 1,
&quot;y&quot;, 2,
&quot;z&quot;, 3
)
</pre></div></li>
<li>
<p>The expected result is:</p>
<div class="source">
<pre>3
</pre></div></li>
</ul></div></div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row span12">Copyright &copy; 2015.
All Rights Reserved.
</div>
<?xml version="1.0" encoding="UTF-8"?>
<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
feather logo, and the Apache AsterixDB project logo are either
registered trademarks or trademarks of The Apache Software
Foundation in the United States and other countries.
All other marks mentioned may be trademarks or registered
trademarks of their respective owners.</div>
</div>
</footer>
</body>
</html>