blob: 28d5fbe4afe1bf64f04cad39aba1d707ee3887de [file] [log] [blame]
Ian Maxone2b799e2015-11-24 18:20:03 -08001<!DOCTYPE html>
2<!--
3 | Generated by Apache Maven Doxia at 2015-11-24
4 | Rendered using Apache Maven Fluido Skin 1.3.0
5-->
6<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7 <head>
8 <meta charset="UTF-8" />
9 <meta name="viewport" content="width=device-width, initial-scale=1.0" />
10 <meta name="Date-Revision-yyyymmdd" content="20151124" />
11 <meta http-equiv="Content-Language" content="en" />
12 <title>AsterixDB &#x2013; Asterix: Using Functions</title>
13 <link rel="stylesheet" href="../css/apache-maven-fluido-1.3.0.min.css" />
14 <link rel="stylesheet" href="../css/site.css" />
15 <link rel="stylesheet" href="../css/print.css" media="print" />
16
17
18 <script type="text/javascript" src="../js/apache-maven-fluido-1.3.0.min.js"></script>
19
20
21
22<script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
23 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
24 m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
25 })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
26
27 ga('create', 'UA-41536543-1', 'uci.edu');
28 ga('send', 'pageview');</script>
29
30 </head>
31 <body class="topBarDisabled">
32
33
34
35
36 <div class="container-fluid">
37 <div id="banner">
38 <div class="pull-left">
39 <a href="http://asterixdb.apache.org/" id="bannerLeft">
40 <img src="../images/asterixlogo.png" alt="AsterixDB"/>
41 </a>
42 </div>
43 <div class="pull-right"> </div>
44 <div class="clear"><hr/></div>
45 </div>
46
47 <div id="breadcrumbs">
48 <ul class="breadcrumb">
49
50
51 <li id="publishDate">Last Published: 2015-11-24</li>
52
53
54
55 <li id="projectVersion" class="pull-right">Version: 0.8.7-incubating</li>
56
57 <li class="divider pull-right">|</li>
58
59 <li class="pull-right"> <a href="../index.html" title="Documentation Home">
60 Documentation Home</a>
61 </li>
62
63 </ul>
64 </div>
65
66
67 <div class="row-fluid">
68 <div id="leftColumn" class="span3">
69 <div class="well sidebar-nav">
70
71
72 <ul class="nav nav-list">
73 <li class="nav-header">Documentation</li>
74
75 <li>
76
77 <a href="../install.html" title="Installing and Managing AsterixDB using Managix">
78 <i class="none"></i>
79 Installing and Managing AsterixDB using Managix</a>
80 </li>
81
82 <li>
83
84 <a href="../yarn.html" title="Deploying AsterixDB using YARN">
85 <i class="none"></i>
86 Deploying AsterixDB using YARN</a>
87 </li>
88
89 <li>
90
91 <a href="../aql/primer.html" title="AsterixDB 101: An ADM and AQL Primer">
92 <i class="none"></i>
93 AsterixDB 101: An ADM and AQL Primer</a>
94 </li>
95
96 <li>
97
98 <a href="../aql/primer-sql-like.html" title="AsterixDB 101: An ADM and AQL Primer (For SQL Fans)">
99 <i class="none"></i>
100 AsterixDB 101: An ADM and AQL Primer (For SQL Fans)</a>
101 </li>
102
103 <li>
104
105 <a href="../aql/js-sdk.html" title="AsterixDB Javascript SDK">
106 <i class="none"></i>
107 AsterixDB Javascript SDK</a>
108 </li>
109
110 <li>
111
112 <a href="../aql/datamodel.html" title="Asterix Data Model (ADM)">
113 <i class="none"></i>
114 Asterix Data Model (ADM)</a>
115 </li>
116
117 <li>
118
119 <a href="../aql/manual.html" title="Asterix Query Language (AQL)">
120 <i class="none"></i>
121 Asterix Query Language (AQL)</a>
122 </li>
123
124 <li class="active">
125
126 <a href="#"><i class="none"></i>AQL Functions</a>
127 </li>
128
129 <li>
130
131 <a href="../aql/allens.html" title="AQL Allen's Relations Functions">
132 <i class="none"></i>
133 AQL Allen's Relations Functions</a>
134 </li>
135
136 <li>
137
138 <a href="../aql/similarity.html" title="AQL Support of Similarity Queries">
139 <i class="none"></i>
140 AQL Support of Similarity Queries</a>
141 </li>
142
143 <li>
144
145 <a href="../aql/externaldata.html" title="Accessing External Data">
146 <i class="none"></i>
147 Accessing External Data</a>
148 </li>
149
150 <li>
151
152 <a href="../feeds/tutorial.html" title="Support for Data Ingestion in AsterixDB">
153 <i class="none"></i>
154 Support for Data Ingestion in AsterixDB</a>
155 </li>
156
157 <li>
158
159 <a href="../udf.html" title="Support for User Defined Functions in AsterixDB">
160 <i class="none"></i>
161 Support for User Defined Functions in AsterixDB</a>
162 </li>
163
164 <li>
165
166 <a href="../aql/filters.html" title="Filter-Based LSM Index Acceleration">
167 <i class="none"></i>
168 Filter-Based LSM Index Acceleration</a>
169 </li>
170
171 <li>
172
173 <a href="../api.html" title="HTTP API to AsterixDB">
174 <i class="none"></i>
175 HTTP API to AsterixDB</a>
176 </li>
177 </ul>
178
179
180
181 <hr class="divider" />
182
183 <div id="poweredBy">
184 <div class="clear"></div>
185 <div class="clear"></div>
186 <div class="clear"></div>
187 <a href="https://code.google.com/p/hyracks/" title="Hyracks" class="builtBy">
188 <img class="builtBy" alt="Hyracks" src="../images/hyrax_ts.png" />
189 </a>
190 </div>
191 </div>
192 </div>
193
194
195 <div id="bodyColumn" class="span9" >
196
197 <!-- ! Licensed to the Apache Software Foundation (ASF) under one
198 ! or more contributor license agreements. See the NOTICE file
199 ! distributed with this work for additional information
200 ! regarding copyright ownership. The ASF licenses this file
201 ! to you under the Apache License, Version 2.0 (the
202 ! "License"); you may not use this file except in compliance
203 ! with the License. You may obtain a copy of the License at
204 !
205 ! http://www.apache.org/licenses/LICENSE-2.0
206 !
207 ! Unless required by applicable law or agreed to in writing,
208 ! software distributed under the License is distributed on an
209 ! "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
210 ! KIND, either express or implied. See the License for the
211 ! specific language governing permissions and limitations
212 ! under the License.
213 ! --><h1>Asterix: Using Functions</h1>
214<div class="section">
215<h2><a name="Table_of_Contents"></a><a name="toc" id="toc">Table of Contents</a></h2>
216
217<ul>
218
219<li><a href="#NumericFunctions">Numeric Functions</a></li>
220
221<li><a href="#StringFunctions">String Functions</a></li>
222
223<li><a href="#AggregateFunctions">Aggregate Functions</a></li>
224
225<li><a href="#SpatialFunctions">Spatial Functions</a></li>
226
227<li><a href="#SimilarityFunctions">Similarity Functions</a></li>
228
229<li><a href="#TokenizingFunctions">Tokenizing Functions</a></li>
230
231<li><a href="#TemporalFunctions">Temporal Functions</a></li>
232
233<li><a href="#RecordFunctions">Record Functions</a></li>
234
235<li><a href="#OtherFunctions">Other Functions</a></li>
236</ul>
237<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>
238<div class="section">
239<h2><a name="Numeric_Functions_Back_to_TOC"></a><a name="NumericFunctions" id="NumericFunctions">Numeric Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
240<div class="section">
241<h3><a name="abs"></a>abs</h3>
242
243<ul>
244
245<li>
246<p>Syntax:</p>
247
248<div class="source">
249<div class="source">
250<pre>abs(numeric_expression)
251</pre></div></div></li>
252
253<li>
254<p>Computes the absolute value of the argument.</p></li>
255
256<li>Arguments:
257
258<ul>
259
260<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>
261 </ul></li>
262
263<li>Return Value:
264
265<ul>
266
267<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>
268 </ul></li>
269
270<li>
271<p>Example:</p>
272
273<div class="source">
274<div class="source">
275<pre>let $v1 := abs(2013)
276let $v2 := abs(-4036)
277let $v3 := abs(0)
278let $v4 := abs(float(&quot;-2013.5&quot;))
279let $v5 := abs(double(&quot;-2013.593823748327284&quot;))
280return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
281</pre></div></div></li>
282</ul>
283
284<ul>
285
286<li>
287<p>The expected result is:</p>
288
289<div class="source">
290<div class="source">
291<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: 4036, &quot;v3&quot;: 0, &quot;v4&quot;: 2013.5f, &quot;v5&quot;: 2013.5938237483274d }
292</pre></div></div></li>
293</ul></div>
294<div class="section">
295<h3><a name="ceiling"></a>ceiling</h3>
296
297<ul>
298
299<li>
300<p>Syntax:</p>
301
302<div class="source">
303<div class="source">
304<pre>ceiling(numeric_expression)
305</pre></div></div></li>
306
307<li>
308<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>
309
310<li>Arguments:
311
312<ul>
313
314<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>
315 </ul></li>
316
317<li>Return Value:
318
319<ul>
320
321<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>
322 </ul></li>
323
324<li>
325<p>Example:</p>
326
327<div class="source">
328<div class="source">
329<pre>let $v1 := ceiling(2013)
330let $v2 := ceiling(-4036)
331let $v3 := ceiling(0.3)
332let $v4 := ceiling(float(&quot;-2013.2&quot;))
333let $v5 := ceiling(double(&quot;-2013.893823748327284&quot;))
334return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
335</pre></div></div></li>
336</ul>
337
338<ul>
339
340<li>
341<p>The expected result is:</p>
342
343<div class="source">
344<div class="source">
345<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 1.0d, &quot;v4&quot;: -2013.0f, &quot;v5&quot;: -2013.0d }
346</pre></div></div></li>
347</ul></div>
348<div class="section">
349<h3><a name="floor"></a>floor</h3>
350
351<ul>
352
353<li>
354<p>Syntax:</p>
355
356<div class="source">
357<div class="source">
358<pre>floor(numeric_expression)
359</pre></div></div></li>
360
361<li>
362<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>
363
364<li>Arguments:
365
366<ul>
367
368<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>
369 </ul></li>
370
371<li>Return Value:
372
373<ul>
374
375<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>
376 </ul></li>
377
378<li>
379<p>Example:</p>
380
381<div class="source">
382<div class="source">
383<pre>let $v1 := floor(2013)
384let $v2 := floor(-4036)
385let $v3 := floor(0.8)
386let $v4 := floor(float(&quot;-2013.2&quot;))
387let $v5 := floor(double(&quot;-2013.893823748327284&quot;))
388return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
389</pre></div></div></li>
390</ul>
391
392<ul>
393
394<li>
395<p>The expected result is:</p>
396
397<div class="source">
398<div class="source">
399<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 0.0d, &quot;v4&quot;: -2014.0f, &quot;v5&quot;: -2014.0d }
400</pre></div></div></li>
401</ul></div>
402<div class="section">
403<h3><a name="round"></a>round</h3>
404
405<ul>
406
407<li>
408<p>Syntax:</p>
409
410<div class="source">
411<div class="source">
412<pre>round(numeric_expression)
413</pre></div></div></li>
414
415<li>
416<p>Computes the number with no fractional part that is closest (and also closest to positive infinity) to the argument.</p></li>
417
418<li>Arguments:
419
420<ul>
421
422<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>
423 </ul></li>
424
425<li>Return Value:
426
427<ul>
428
429<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>
430 </ul></li>
431
432<li>
433<p>Example:</p>
434
435<div class="source">
436<div class="source">
437<pre>let $v1 := round(2013)
438let $v2 := round(-4036)
439let $v3 := round(0.8)
440let $v4 := round(float(&quot;-2013.256&quot;))
441let $v5 := round(double(&quot;-2013.893823748327284&quot;))
442return { &quot;v1&quot;: $v1, &quot;v2&quot;: $v2, &quot;v3&quot;: $v3, &quot;v4&quot;: $v4, &quot;v5&quot;: $v5 }
443</pre></div></div></li>
444</ul>
445
446<ul>
447
448<li>
449<p>The expected result is:</p>
450
451<div class="source">
452<div class="source">
453<pre>{ &quot;v1&quot;: 2013, &quot;v2&quot;: -4036, &quot;v3&quot;: 1.0d, &quot;v4&quot;: -2013.0f, &quot;v5&quot;: -2014.0d }
454</pre></div></div></li>
455</ul></div>
456<div class="section">
457<h3><a name="round-half-to-even"></a>round-half-to-even</h3>
458
459<ul>
460
461<li>
462<p>Syntax:</p>
463
464<div class="source">
465<div class="source">
466<pre>round-half-to-even(numeric_expression, [precision])
467</pre></div></div></li>
468
469<li>
470<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>
471
472<li>Arguments:
473
474<ul>
475
476<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>
477
478<li><tt>precision</tt>: An optional integer field representing the number of digits in the fraction of the the result</li>
479 </ul></li>
480
481<li>Return Value:
482
483<ul>
484
485<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>
486 </ul></li>
487
488<li>
489<p>Example:</p>
490
491<div class="source">
492<div class="source">
493<pre>let $v1 := round-half-to-even(2013)
494let $v2 := round-half-to-even(-4036)
495let $v3 := round-half-to-even(0.8)
496let $v4 := round-half-to-even(float(&quot;-2013.256&quot;))
497let $v5 := round-half-to-even(double(&quot;-2013.893823748327284&quot;))
498let $v6 := round-half-to-even(double(&quot;-2013.893823748327284&quot;), 2)
499let $v7 := round-half-to-even(2013, 4)
500let $v8 := round-half-to-even(float(&quot;-2013.256&quot;), 5)
501return { &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 }
502</pre></div></div></li>
503</ul>
504
505<ul>
506
507<li>
508<p>The expected result is:</p>
509
510<div class="source">
511<div class="source">
512<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 }
513</pre></div></div></li>
514</ul></div></div>
515<div class="section">
516<h2><a name="String_Functions_Back_to_TOC"></a><a name="StringFunctions" id="StringFunctions">String Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
517<div class="section">
518<h3><a name="string-to-codepoint"></a>string-to-codepoint</h3>
519
520<ul>
521
522<li>
523<p>Syntax:</p>
524
525<div class="source">
526<div class="source">
527<pre>string-to-codepoint(string_expression)
528</pre></div></div></li>
529
530<li>
531<p>Converts the string <tt>string_expression</tt> to its code-based representation.</p></li>
532
533<li>Arguments:
534
535<ul>
536
537<li><tt>string_expression</tt> : A <tt>string</tt> that will be converted.</li>
538 </ul></li>
539
540<li>Return Value:
541
542<ul>
543
544<li>An <tt>OrderedList</tt> of the code points for the string <tt>string_expression</tt>.</li>
545 </ul></li>
546</ul></div>
547<div class="section">
548<h3><a name="codepoint-to-string"></a>codepoint-to-string</h3>
549
550<ul>
551
552<li>
553<p>Syntax:</p>
554
555<div class="source">
556<div class="source">
557<pre>codepoint-to-string(list_expression)
558</pre></div></div></li>
559
560<li>
561<p>Converts the ordered code-based representation <tt>list_expression</tt> to the corresponding string.</p></li>
562
563<li>Arguments:
564
565<ul>
566
567<li><tt>list_expression</tt> : An <tt>OrderedList</tt> of code-points.</li>
568 </ul></li>
569
570<li>Return Value:
571
572<ul>
573
574<li>A <tt>string</tt> representation of <tt>list_expression</tt>.</li>
575 </ul></li>
576
577<li>
578<p>Example:</p>
579
580<div class="source">
581<div class="source">
582<pre>use dataverse TinySocial;
583
584let $s := &quot;Hello ASTERIX!&quot;
585let $l := string-to-codepoint($s)
586let $ss := codepoint-to-string($l)
587return {&quot;codes&quot;: $l, &quot;string&quot;: $ss}
588</pre></div></div></li>
589</ul>
590
591<ul>
592
593<li>
594<p>The expected result is:</p>
595
596<div class="source">
597<div class="source">
598<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; }
599</pre></div></div></li>
600</ul></div>
601<div class="section">
602<h3><a name="contains"></a>contains</h3>
603
604<ul>
605
606<li>
607<p>Syntax:</p>
608
609<div class="source">
610<div class="source">
611<pre>contains(string_expression, substring_to_contain)
612</pre></div></div></li>
613
614<li>
615<p>Checks whether the string <tt>string_expression</tt> contains the string <tt>substring_to_contain</tt></p></li>
616
617<li>Arguments:
618
619<ul>
620
621<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the given substring.</li>
622
623<li><tt>substring_to_contain</tt> : A target <tt>string</tt> that might be contained.</li>
624 </ul></li>
625
626<li>Return Value:
627
628<ul>
629
630<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>
631 </ul></li>
632
633<li>Note: An <a href="similarity.html#UsingIndexesToSupportSimilarityQueries">n-gram index</a> can be utilized for this function.</li>
634
635<li>
636<p>Example:</p>
637
638<div class="source">
639<div class="source">
640<pre>use dataverse TinySocial;
641
642for $i in dataset('FacebookMessages')
643where contains($i.message, &quot;phone&quot;)
644return {&quot;mid&quot;: $i.message-id, &quot;message&quot;: $i.message}
645</pre></div></div></li>
646</ul>
647
648<ul>
649
650<li>
651<p>The expected result is:</p>
652
653<div class="source">
654<div class="source">
655<pre>{ &quot;mid&quot;: 2, &quot;message&quot;: &quot; dislike iphone its touch-screen is horrible&quot; }
656{ &quot;mid&quot;: 13, &quot;message&quot;: &quot; dislike iphone the voice-command is bad:(&quot; }
657{ &quot;mid&quot;: 15, &quot;message&quot;: &quot; like iphone the voicemail-service is awesome&quot; }
658</pre></div></div></li>
659</ul></div>
660<div class="section">
661<h3><a name="like"></a>like</h3>
662
663<ul>
664
665<li>
666<p>Syntax:</p>
667
668<div class="source">
669<div class="source">
670<pre>like(string_expression, string_pattern)
671</pre></div></div></li>
672
673<li>
674<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>
675
676<li>Arguments:
677
678<ul>
679
680<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the pattern or <tt>null</tt>.</li>
681
682<li><tt>string_pattern</tt> : A pattern <tt>string</tt> that might be contained or <tt>null</tt>.</li>
683 </ul></li>
684
685<li>Return Value:
686
687<ul>
688
689<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>
690 </ul></li>
691
692<li>
693<p>Example:</p>
694
695<div class="source">
696<div class="source">
697<pre>use dataverse TinySocial;
698
699for $i in dataset('FacebookMessages')
700where like($i.message, &quot;%at&amp;t%&quot;)
701return $i.message
702</pre></div></div></li>
703</ul>
704
705<ul>
706
707<li>
708<p>The expected result is:</p>
709
710<div class="source">
711<div class="source">
712<pre>&quot; can't stand at&amp;t the network is horrible:(&quot;
713&quot; can't stand at&amp;t its plan is terrible&quot;
714&quot; love at&amp;t its 3G is good:)&quot;
715</pre></div></div></li>
716</ul></div>
717<div class="section">
718<h3><a name="starts-with"></a>starts-with</h3>
719
720<ul>
721
722<li>
723<p>Syntax:</p>
724
725<div class="source">
726<div class="source">
727<pre>starts-with(string_expression, substring_to_start_with)
728</pre></div></div></li>
729
730<li>
731<p>Checks whether the string <tt>string_expression</tt> starts with the string <tt>substring_to_start_with</tt>.</p></li>
732
733<li>Arguments:
734
735<ul>
736
737<li><tt>string_expression</tt> : A <tt>string</tt> that might start with the given string.</li>
738
739<li><tt>substring_to_start_with</tt> : A <tt>string</tt> that might be contained as the starting substring.</li>
740 </ul></li>
741
742<li>Return Value:
743
744<ul>
745
746<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>
747 </ul></li>
748
749<li>
750<p>Example:</p>
751
752<div class="source">
753<div class="source">
754<pre>use dataverse TinySocial;
755
756for $i in dataset('FacebookMessages')
757where starts-with($i.message, &quot; like&quot;)
758return $i.message
759</pre></div></div></li>
760</ul>
761
762<ul>
763
764<li>
765<p>The expected result is:</p>
766
767<div class="source">
768<div class="source">
769<pre>&quot; like samsung the plan is amazing&quot;
770&quot; like t-mobile its platform is mind-blowing&quot;
771&quot; like verizon the 3G is awesome:)&quot;
772&quot; like iphone the voicemail-service is awesome&quot;
773</pre></div></div></li>
774</ul></div>
775<div class="section">
776<h3><a name="ends-with"></a>ends-with</h3>
777
778<ul>
779
780<li>
781<p>Syntax:</p>
782
783<div class="source">
784<div class="source">
785<pre>ends-with(string_expression, substring_to_end_with)
786</pre></div></div></li>
787
788<li>
789<p>Checks whether the string <tt>string_expression</tt> ends with the string <tt>substring_to_end_with</tt>.</p></li>
790
791<li>Arguments:
792
793<ul>
794
795<li><tt>string_expression</tt> : A <tt>string</tt> that might end with the given string.</li>
796
797<li><tt>substring_to_end_with</tt> : A <tt>string</tt> that might be contained as the ending substring.</li>
798 </ul></li>
799
800<li>Return Value:
801
802<ul>
803
804<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>
805 </ul></li>
806
807<li>
808<p>Example:</p>
809
810<div class="source">
811<div class="source">
812<pre>use dataverse TinySocial;
813
814for $i in dataset('FacebookMessages')
815where ends-with($i.message, &quot;:)&quot;)
816return $i.message
817</pre></div></div></li>
818</ul>
819
820<ul>
821
822<li>
823<p>The expected result is:</p>
824
825<div class="source">
826<div class="source">
827<pre>&quot; love sprint its shortcut-menu is awesome:)&quot;
828&quot; like verizon the 3G is awesome:)&quot;
829&quot; love at&amp;t its 3G is good:)&quot;
830</pre></div></div></li>
831</ul></div>
832<div class="section">
833<h3><a name="string-concat"></a>string-concat</h3>
834
835<ul>
836
837<li>
838<p>Syntax:</p>
839
840<div class="source">
841<div class="source">
842<pre>string-concat(list_expression)
843</pre></div></div></li>
844
845<li>
846<p>Concatenates a list of strings <tt>list_expression</tt> into a single string.</p></li>
847
848<li>Arguments:
849
850<ul>
851
852<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>
853 </ul></li>
854
855<li>Return Value:
856
857<ul>
858
859<li>Returns the concatenated <tt>string</tt> value.</li>
860 </ul></li>
861
862<li>
863<p>Example:</p>
864
865<div class="source">
866<div class="source">
867<pre>let $i := &quot;ASTERIX&quot;
868let $j := &quot; &quot;
869let $k := &quot;ROCKS!&quot;
870return string-concat([$i, $j, $k])
871</pre></div></div></li>
872</ul>
873
874<ul>
875
876<li>
877<p>The expected result is:</p>
878
879<div class="source">
880<div class="source">
881<pre>&quot;ASTERIX ROCKS!&quot;
882</pre></div></div></li>
883</ul></div>
884<div class="section">
885<h3><a name="string-join"></a>string-join</h3>
886
887<ul>
888
889<li>
890<p>Syntax:</p>
891
892<div class="source">
893<div class="source">
894<pre>string-join(list_expression, string_expression)
895</pre></div></div></li>
896
897<li>
898<p>Joins a list of strings <tt>list_expression</tt> with the given separator <tt>string_expression</tt> into a single string.</p></li>
899
900<li>Arguments:
901
902<ul>
903
904<li><tt>list_expression</tt> : An <tt>OrderedList</tt> or <tt>UnorderedList</tt> of strings (could be <tt>null</tt>) to be joined.</li>
905
906<li><tt>string_expression</tt> : A <tt>string</tt> as the separator.</li>
907 </ul></li>
908
909<li>Return Value:
910
911<ul>
912
913<li>Returns the joined <tt>String</tt>.</li>
914 </ul></li>
915
916<li>
917<p>Example:</p>
918
919<div class="source">
920<div class="source">
921<pre>use dataverse TinySocial;
922
923let $i := [&quot;ASTERIX&quot;, &quot;ROCKS~&quot;]
924return string-join($i, &quot;!! &quot;)
925</pre></div></div></li>
926</ul>
927
928<ul>
929
930<li>
931<p>The expected result is:</p>
932
933<div class="source">
934<div class="source">
935<pre>&quot;ASTERIX!! ROCKS~&quot;
936</pre></div></div></li>
937</ul></div>
938<div class="section">
939<h3><a name="lowercase"></a>lowercase</h3>
940
941<ul>
942
943<li>
944<p>Syntax:</p>
945
946<div class="source">
947<div class="source">
948<pre>lowercase(string_expression)
949</pre></div></div></li>
950
951<li>
952<p>Converts a given string <tt>string_expression</tt> to its lowercase form.</p></li>
953
954<li>Arguments:
955
956<ul>
957
958<li><tt>string_expression</tt> : A <tt>string</tt> to be converted.</li>
959 </ul></li>
960
961<li>Return Value:
962
963<ul>
964
965<li>Returns a <tt>string</tt> as the lowercase form of the given <tt>string_expression</tt>.</li>
966 </ul></li>
967
968<li>
969<p>Example:</p>
970
971<div class="source">
972<div class="source">
973<pre>use dataverse TinySocial;
974
975let $i := &quot;ASTERIX&quot;
976return lowercase($i)
977</pre></div></div></li>
978</ul>
979
980<ul>
981
982<li>
983<p>The expected result is:</p>
984
985<div class="source">
986<div class="source">
987<pre>asterix
988</pre></div></div></li>
989</ul></div>
990<div class="section">
991<h3><a name="uppercase"></a>uppercase</h3>
992
993<ul>
994
995<li>Syntax:</li>
996</ul>
997<p>uppercase(string_expression)</p>
998
999<ul>
1000
1001<li>Converts a given string <tt>string_expression</tt> to its uppercase form.</li>
1002
1003<li>Arguments:
1004
1005<ul>
1006
1007<li><tt>string_expression</tt> : A <tt>string</tt> to be converted.</li>
1008 </ul></li>
1009
1010<li>Return Value:
1011
1012<ul>
1013
1014<li>Returns a <tt>string</tt> as the uppercase form of the given <tt>string_expression</tt>.</li>
1015 </ul></li>
1016
1017<li>
1018<p>Example:</p>
1019
1020<div class="source">
1021<div class="source">
1022<pre>use dataverse TinySocial;
1023
1024let $i := &quot;asterix&quot;
1025return uppercase($i)
1026</pre></div></div></li>
1027</ul>
1028
1029<ul>
1030
1031<li>
1032<p>The expected result is:</p>
1033
1034<div class="source">
1035<div class="source">
1036<pre>ASTERIX
1037</pre></div></div></li>
1038</ul></div>
1039<div class="section">
1040<h3><a name="uppercase"></a>uppercase</h3>
1041
1042<ul>
1043
1044<li>
1045<p>Syntax:</p>
1046
1047<div class="source">
1048<div class="source">
1049<pre>uppercase(string_expression)
1050</pre></div></div></li>
1051
1052<li>
1053<p>Converts a given string <tt>string_expression</tt> to its uppercase form.</p></li>
1054
1055<li>Arguments:
1056
1057<ul>
1058
1059<li><tt>string_expression</tt> : A <tt>string</tt> to be converted.</li>
1060 </ul></li>
1061
1062<li>Return Value:
1063
1064<ul>
1065
1066<li>Returns a <tt>string</tt> as the uppercase form of the given <tt>string_expression</tt>.</li>
1067 </ul></li>
1068
1069<li>
1070<p>Example:</p>
1071
1072<div class="source">
1073<div class="source">
1074<pre>use dataverse TinySocial;
1075
1076let $i := &quot;asterix&quot;
1077return uppercase($i)
1078</pre></div></div></li>
1079</ul>
1080
1081<ul>
1082
1083<li>
1084<p>The expected result is:</p>
1085
1086<div class="source">
1087<div class="source">
1088<pre>ASTERIX
1089</pre></div></div></li>
1090</ul></div>
1091<div class="section">
1092<h3><a name="matches"></a>matches</h3>
1093
1094<ul>
1095
1096<li>
1097<p>Syntax:</p>
1098
1099<div class="source">
1100<div class="source">
1101<pre>matches(string_expression, string_pattern)
1102</pre></div></div></li>
1103
1104<li>
1105<p>Checks whether the strings <tt>string_expression</tt> matches the given pattern <tt>string_pattern</tt> (A Java regular expression pattern).</p></li>
1106
1107<li>Arguments:
1108
1109<ul>
1110
1111<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the pattern.</li>
1112
1113<li><tt>string_pattern</tt> : A pattern <tt>string</tt> to be matched.</li>
1114 </ul></li>
1115
1116<li>Return Value:
1117
1118<ul>
1119
1120<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>
1121 </ul></li>
1122
1123<li>
1124<p>Example:</p>
1125
1126<div class="source">
1127<div class="source">
1128<pre>use dataverse TinySocial;
1129
1130for $i in dataset('FacebookMessages')
1131where matches($i.message, &quot;dislike iphone&quot;)
1132return $i.message
1133</pre></div></div></li>
1134</ul>
1135
1136<ul>
1137
1138<li>
1139<p>The expected result is:</p>
1140
1141<div class="source">
1142<div class="source">
1143<pre>&quot; dislike iphone its touch-screen is horrible&quot;
1144&quot; dislike iphone the voice-command is bad:(&quot;
1145</pre></div></div></li>
1146</ul></div>
1147<div class="section">
1148<h3><a name="replace"></a>replace</h3>
1149
1150<ul>
1151
1152<li>
1153<p>Syntax:</p>
1154
1155<div class="source">
1156<div class="source">
1157<pre>replace(string_expression, string_pattern, string_replacement[, string_flags])
1158</pre></div></div></li>
1159
1160<li>
1161<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>
1162
1163<li>Arguments:
1164
1165<ul>
1166
1167<li><tt>string_expression</tt> : A <tt>string</tt> that might contain the pattern.</li>
1168
1169<li><tt>string_pattern</tt> : A pattern <tt>string</tt> to be matched.</li>
1170
1171<li><tt>string_replacement</tt> : A pattern <tt>string</tt> to be used as the replacement.</li>
1172
1173<li><tt>string_flag</tt> : (Optional) A <tt>string</tt> with flags to be used during replace.</li>
1174
1175<li>The following modes are enabled with these flags: dotall (s), multiline (m), case-insenitive (i), and comments and whitespace (x).</li>
1176 </ul></li>
1177
1178<li>Return Value:
1179
1180<ul>
1181
1182<li>Returns a <tt>string</tt> that is obtained after the replacements.</li>
1183 </ul></li>
1184
1185<li>
1186<p>Example:</p>
1187
1188<div class="source">
1189<div class="source">
1190<pre>use dataverse TinySocial;
1191
1192for $i in dataset('FacebookMessages')
1193where matches($i.message, &quot; like iphone&quot;)
1194return replace($i.message, &quot; like iphone&quot;, &quot;like android&quot;)
1195</pre></div></div></li>
1196</ul>
1197
1198<ul>
1199
1200<li>
1201<p>The expected result is:</p>
1202
1203<div class="source">
1204<div class="source">
1205<pre>&quot;like android the voicemail-service is awesome&quot;
1206</pre></div></div></li>
1207</ul></div>
1208<div class="section">
1209<h3><a name="string-length"></a>string-length</h3>
1210
1211<ul>
1212
1213<li>
1214<p>Syntax:</p>
1215
1216<div class="source">
1217<div class="source">
1218<pre>string-length(string_expression)
1219</pre></div></div></li>
1220
1221<li>
1222<p>Returns the length of the string <tt>string_expression</tt>.</p></li>
1223
1224<li>Arguments:
1225
1226<ul>
1227
1228<li><tt>string_expression</tt> : A <tt>string</tt> or <tt>null</tt> that represents the string to be checked.</li>
1229 </ul></li>
1230
1231<li>Return Value:
1232
1233<ul>
1234
1235<li>An <tt>int64</tt> that represents the length of <tt>string_expression</tt>.</li>
1236 </ul></li>
1237
1238<li>
1239<p>Example:</p>
1240
1241<div class="source">
1242<div class="source">
1243<pre>use dataverse TinySocial;
1244
1245for $i in dataset('FacebookMessages')
1246return {&quot;mid&quot;: $i.message-id, &quot;message-len&quot;: string-length($i.message)}
1247</pre></div></div></li>
1248</ul>
1249
1250<ul>
1251
1252<li>
1253<p>The expected result is:</p>
1254
1255<div class="source">
1256<div class="source">
1257<pre>{ &quot;mid&quot;: 1, &quot;message-len&quot;: 43 }
1258{ &quot;mid&quot;: 2, &quot;message-len&quot;: 44 }
1259{ &quot;mid&quot;: 3, &quot;message-len&quot;: 33 }
1260{ &quot;mid&quot;: 4, &quot;message-len&quot;: 43 }
1261{ &quot;mid&quot;: 5, &quot;message-len&quot;: 46 }
1262{ &quot;mid&quot;: 6, &quot;message-len&quot;: 43 }
1263{ &quot;mid&quot;: 7, &quot;message-len&quot;: 37 }
1264{ &quot;mid&quot;: 8, &quot;message-len&quot;: 33 }
1265{ &quot;mid&quot;: 9, &quot;message-len&quot;: 34 }
1266{ &quot;mid&quot;: 10, &quot;message-len&quot;: 50 }
1267{ &quot;mid&quot;: 11, &quot;message-len&quot;: 38 }
1268{ &quot;mid&quot;: 12, &quot;message-len&quot;: 52 }
1269{ &quot;mid&quot;: 13, &quot;message-len&quot;: 42 }
1270{ &quot;mid&quot;: 14, &quot;message-len&quot;: 27 }
1271{ &quot;mid&quot;: 15, &quot;message-len&quot;: 45 }
1272</pre></div></div></li>
1273</ul></div>
1274<div class="section">
1275<h3><a name="substring"></a>substring</h3>
1276
1277<ul>
1278
1279<li>
1280<p>Syntax:</p>
1281
1282<div class="source">
1283<div class="source">
1284<pre>substring(string_expression, offset[, length])
1285</pre></div></div></li>
1286
1287<li>
1288<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>
1289
1290<li>Arguments:
1291
1292<ul>
1293
1294<li><tt>string_expression</tt> : A <tt>string</tt> to be extracted.</li>
1295
1296<li><tt>offset</tt> : An <tt>int64</tt> as the starting offset of the substring in <tt>string_expression</tt>.</li>
1297
1298<li><tt>length</tt> : (Optional) An <tt>int64</tt> as the length of the substring.</li>
1299 </ul></li>
1300
1301<li>Return Value:
1302
1303<ul>
1304
1305<li>A <tt>string</tt> that represents the substring.</li>
1306 </ul></li>
1307
1308<li>
1309<p>Example:</p>
1310
1311<div class="source">
1312<div class="source">
1313<pre>use dataverse TinySocial;
1314
1315for $i in dataset('FacebookMessages')
1316where string-length($i.message) &gt; 50
1317return substring($i.message, 50)
1318</pre></div></div></li>
1319</ul>
1320
1321<ul>
1322
1323<li>
1324<p>The expected result is:</p>
1325
1326<div class="source">
1327<div class="source">
1328<pre>&quot;G:(&quot;
1329</pre></div></div></li>
1330</ul></div>
1331<div class="section">
1332<h3><a name="substring-before"></a>substring-before</h3>
1333
1334<ul>
1335
1336<li>
1337<p>Syntax:</p>
1338
1339<div class="source">
1340<div class="source">
1341<pre>substring-before(string_expression, string_pattern)
1342</pre></div></div></li>
1343
1344<li>
1345<p>Returns the substring from the given string <tt>string_expression</tt> before the given pattern <tt>string_pattern</tt>.</p></li>
1346
1347<li>Arguments:
1348
1349<ul>
1350
1351<li><tt>string_expression</tt> : A <tt>string</tt> to be extracted.</li>
1352
1353<li><tt>string_pattern</tt> : A <tt>string</tt> pattern to be searched.</li>
1354 </ul></li>
1355
1356<li>Return Value:
1357
1358<ul>
1359
1360<li>A <tt>string</tt> that represents the substring.</li>
1361 </ul></li>
1362
1363<li>
1364<p>Example:</p>
1365
1366<div class="source">
1367<div class="source">
1368<pre>use dataverse TinySocial;
1369
1370for $i in dataset('FacebookMessages')
1371where contains($i.message, &quot;iphone&quot;)
1372return substring-before($i.message, &quot;iphone&quot;)
1373</pre></div></div></li>
1374</ul>
1375
1376<ul>
1377
1378<li>
1379<p>The expected result is:</p>
1380
1381<div class="source">
1382<div class="source">
1383<pre>&quot; dislike &quot;
1384&quot; dislike &quot;
1385&quot; like &quot;
1386</pre></div></div></li>
1387</ul></div>
1388<div class="section">
1389<h3><a name="substring-after"></a>substring-after</h3>
1390
1391<ul>
1392
1393<li>
1394<p>Syntax:</p>
1395
1396<div class="source">
1397<div class="source">
1398<pre>substring-after(string_expression, string_pattern)
1399</pre></div></div></li>
1400
1401<li>
1402<p>Returns the substring from the given string <tt>string_expression</tt> after the given pattern <tt>string_pattern</tt>.</p></li>
1403
1404<li>Arguments:
1405
1406<ul>
1407
1408<li><tt>string_expression</tt> : A <tt>string</tt> to be extracted.</li>
1409
1410<li><tt>string_pattern</tt> : A <tt>string</tt> pattern to be searched.</li>
1411 </ul></li>
1412
1413<li>Return Value:
1414
1415<ul>
1416
1417<li>A <tt>string</tt> that represents the substring.</li>
1418 </ul></li>
1419
1420<li>
1421<p>Example:</p>
1422
1423<div class="source">
1424<div class="source">
1425<pre>use dataverse TinySocial;
1426
1427for $i in dataset('FacebookMessages')
1428where contains($i.message, &quot;iphone&quot;)
1429return substring-after($i.message, &quot;iphone&quot;)
1430</pre></div></div></li>
1431</ul>
1432
1433<ul>
1434
1435<li>
1436<p>The expected result is:</p>
1437
1438<div class="source">
1439<div class="source">
1440<pre>&quot; its touch-screen is horrible&quot;
1441&quot; the voice-command is bad:(&quot;
1442&quot; the voicemail-service is awesome&quot;
1443</pre></div></div></li>
1444</ul></div></div>
1445<div class="section">
1446<h2><a name="Aggregate_Functions_Back_to_TOC"></a><a name="AggregateFunctions" id="AggregateFunctions">Aggregate Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
1447<div class="section">
1448<h3><a name="count"></a>count</h3>
1449
1450<ul>
1451
1452<li>
1453<p>Syntax:</p>
1454
1455<div class="source">
1456<div class="source">
1457<pre>count(list)
1458</pre></div></div></li>
1459
1460<li>
1461<p>Gets the number of items in the given list.</p></li>
1462
1463<li>Arguments:
1464
1465<ul>
1466
1467<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>
1468 </ul></li>
1469
1470<li>Return Value:
1471
1472<ul>
1473
1474<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>
1475 </ul></li>
1476
1477<li>
1478<p>Example:</p>
1479
1480<div class="source">
1481<div class="source">
1482<pre>use dataverse TinySocial;
1483
1484let $l1 := ['hello', 'world', 1, 2, 3]
1485let $l2 := for $i in dataset TwitterUsers return $i
1486return {&quot;count1&quot;: count($l1), &quot;count2&quot;: count($l2)}
1487</pre></div></div></li>
1488
1489<li>
1490<p>The expected result is:</p>
1491
1492<div class="source">
1493<div class="source">
1494<pre>{ &quot;count1&quot;: 5i64, &quot;count2&quot;: 4i64 }
1495</pre></div></div></li>
1496</ul></div>
1497<div class="section">
1498<h3><a name="avg"></a>avg</h3>
1499
1500<ul>
1501
1502<li>
1503<p>Syntax:</p>
1504
1505<div class="source">
1506<div class="source">
1507<pre>avg(num_list)
1508</pre></div></div></li>
1509
1510<li>
1511<p>Gets the average value of the items in the given list.</p></li>
1512
1513<li>Arguments:
1514
1515<ul>
1516
1517<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>
1518 </ul></li>
1519
1520<li>Return Value:
1521
1522<ul>
1523
1524<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>
1525 </ul></li>
1526
1527<li>
1528<p>Example:</p>
1529
1530<div class="source">
1531<div class="source">
1532<pre>use dataverse TinySocial;
1533
1534let $l := for $i in dataset TwitterUsers return $i.friends_count
1535return {&quot;avg_friend_count&quot;: avg($l)}
1536</pre></div></div></li>
1537
1538<li>
1539<p>The expected result is:</p>
1540
1541<div class="source">
1542<div class="source">
1543<pre>{ &quot;avg_friend_count&quot;: 191.5d }
1544</pre></div></div></li>
1545</ul></div>
1546<div class="section">
1547<h3><a name="sum"></a>sum</h3>
1548
1549<ul>
1550
1551<li>
1552<p>Syntax:</p>
1553
1554<div class="source">
1555<div class="source">
1556<pre>sum(num_list)
1557</pre></div></div></li>
1558
1559<li>
1560<p>Gets the sum of the items in the given list.</p></li>
1561
1562<li>Arguments:
1563
1564<ul>
1565
1566<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>
1567 </ul></li>
1568
1569<li>Return Value:
1570
1571<ul>
1572
1573<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>
1574 </ul></li>
1575
1576<li>
1577<p>Example:</p>
1578
1579<div class="source">
1580<div class="source">
1581<pre>use dataverse TinySocial;
1582
1583let $l := for $i in dataset TwitterUsers return $i.friends_count
1584return {&quot;sum_friend_count&quot;: sum($l)}
1585</pre></div></div></li>
1586
1587<li>
1588<p>The expected result is:</p>
1589
1590<div class="source">
1591<div class="source">
1592<pre>{ &quot;sum_friend_count&quot;: 766 }
1593</pre></div></div></li>
1594</ul></div>
1595<div class="section">
1596<h3><a name="minmax"></a>min/max</h3>
1597
1598<ul>
1599
1600<li>
1601<p>Syntax:</p>
1602
1603<div class="source">
1604<div class="source">
1605<pre>min(num_list), max(num_list)
1606</pre></div></div></li>
1607
1608<li>
1609<p>Gets the min/max value of numeric items in the given list.</p></li>
1610
1611<li>Arguments:
1612
1613<ul>
1614
1615<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>
1616 </ul></li>
1617
1618<li>Return Value:
1619
1620<ul>
1621
1622<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>
1623 </ul></li>
1624
1625<li>
1626<p>Example:</p>
1627
1628<div class="source">
1629<div class="source">
1630<pre>use dataverse TinySocial;
1631
1632let $l := for $i in dataset TwitterUsers return $i. friends_count
1633return {&quot;min_friend_count&quot;: min($l), &quot;max_friend_count&quot;: max($l)}
1634</pre></div></div></li>
1635
1636<li>
1637<p>The expected result is:</p>
1638
1639<div class="source">
1640<div class="source">
1641<pre>{ &quot;min_friend_count&quot;: 18, &quot;max_friend_count&quot;: 445 }
1642</pre></div></div></li>
1643</ul></div>
1644<div class="section">
1645<h3><a name="sql-count"></a>sql-count</h3>
1646
1647<ul>
1648
1649<li>
1650<p>Syntax:</p>
1651
1652<div class="source">
1653<div class="source">
1654<pre>sql-count(list)
1655</pre></div></div></li>
1656
1657<li>
1658<p>Gets the number of non-null items in the given list.</p></li>
1659
1660<li>Arguments:
1661
1662<ul>
1663
1664<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>
1665 </ul></li>
1666
1667<li>Return Value:
1668
1669<ul>
1670
1671<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>
1672 </ul></li>
1673
1674<li>
1675<p>Example:</p></li>
1676</ul>
1677
1678<div class="source">
1679<div class="source">
1680<pre> let $l1 := ['hello', 'world', 1, 2, 3, null]
1681 return {&quot;count&quot;: sql-count($l1)}
1682</pre></div></div>
1683
1684<ul>
1685
1686<li>
1687<p>The expected result is:</p>
1688
1689<div class="source">
1690<div class="source">
1691<pre>{ &quot;count&quot;: 5i64 }
1692</pre></div></div></li>
1693</ul></div>
1694<div class="section">
1695<h3><a name="sql-avg"></a>sql-avg</h3>
1696
1697<ul>
1698
1699<li>
1700<p>Syntax:</p>
1701
1702<div class="source">
1703<div class="source">
1704<pre>sql-avg(num_list)
1705</pre></div></div></li>
1706
1707<li>
1708<p>Gets the average value of the non-null items in the given list.</p></li>
1709
1710<li>Arguments:
1711
1712<ul>
1713
1714<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>
1715 </ul></li>
1716
1717<li>Return Value:
1718
1719<ul>
1720
1721<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>
1722 </ul></li>
1723
1724<li>
1725<p>Example:</p>
1726
1727<div class="source">
1728<div class="source">
1729<pre>let $l := [1.2, 2.3, 3.4, 0, null]
1730return {&quot;avg&quot;: sql-avg($l)}
1731</pre></div></div></li>
1732
1733<li>
1734<p>The expected result is:</p>
1735
1736<div class="source">
1737<div class="source">
1738<pre>{ &quot;avg&quot;: 1.725d }
1739</pre></div></div></li>
1740</ul></div>
1741<div class="section">
1742<h3><a name="sql-sum"></a>sql-sum</h3>
1743
1744<ul>
1745
1746<li>
1747<p>Syntax:</p>
1748
1749<div class="source">
1750<div class="source">
1751<pre>sql-sum(num_list)
1752</pre></div></div></li>
1753
1754<li>
1755<p>Gets the sum of the non-null items in the given list.</p></li>
1756
1757<li>Arguments:
1758
1759<ul>
1760
1761<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>
1762 </ul></li>
1763
1764<li>Return Value:
1765
1766<ul>
1767
1768<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>
1769 </ul></li>
1770
1771<li>
1772<p>Example:</p>
1773
1774<div class="source">
1775<div class="source">
1776<pre>let $l := [1.2, 2.3, 3.4, 0, null]
1777return {&quot;sum&quot;: sql-sum($l)}
1778</pre></div></div></li>
1779
1780<li>
1781<p>The expected result is:</p>
1782
1783<div class="source">
1784<div class="source">
1785<pre>{ &quot;sum&quot;: 6.9d }
1786</pre></div></div></li>
1787</ul></div>
1788<div class="section">
1789<h3><a name="sql-minmax"></a>sql-min/max</h3>
1790
1791<ul>
1792
1793<li>
1794<p>Syntax:</p>
1795
1796<div class="source">
1797<div class="source">
1798<pre>sql-min(num_list), sql-max(num_list)
1799</pre></div></div></li>
1800
1801<li>
1802<p>Gets the min/max value of the non-null numeric items in the given list.</p></li>
1803
1804<li>Arguments:
1805
1806<ul>
1807
1808<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>
1809 </ul></li>
1810
1811<li>Return Value:
1812
1813<ul>
1814
1815<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>
1816 </ul></li>
1817
1818<li>
1819<p>Example:</p>
1820
1821<div class="source">
1822<div class="source">
1823<pre>let $l := [1.2, 2.3, 3.4, 0, null]
1824return {&quot;min&quot;: sql-min($l), &quot;max&quot;: sql-max($l)}
1825</pre></div></div></li>
1826
1827<li>
1828<p>The expected result is:</p>
1829
1830<div class="source">
1831<div class="source">
1832<pre>{ &quot;min&quot;: 0.0d, &quot;max&quot;: 3.4d }
1833</pre></div></div></li>
1834</ul></div></div>
1835<div class="section">
1836<h2><a name="Spatial_Functions_Back_to_TOC"></a><a name="SpatialFunctions" id="SpatialFunctions">Spatial Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
1837<div class="section">
1838<h3><a name="create-point"></a>create-point</h3>
1839
1840<ul>
1841
1842<li>
1843<p>Syntax:</p>
1844
1845<div class="source">
1846<div class="source">
1847<pre>create-point(x, y)
1848</pre></div></div></li>
1849
1850<li>
1851<p>Creates the primitive type <tt>point</tt> using an <tt>x</tt> and <tt>y</tt> value.</p></li>
1852
1853<li>Arguments:</li>
1854
1855<li><tt>x</tt> : A <tt>double</tt> that represents the x-coordinate.</li>
1856
1857<li><tt>y</tt> : A <tt>double</tt> that represents the y-coordinate.</li>
1858
1859<li>Return Value:</li>
1860
1861<li>A <tt>point</tt> representing the ordered pair (<tt>x</tt>, <tt>y</tt>).</li>
1862
1863<li>
1864<p>Example:</p>
1865
1866<div class="source">
1867<div class="source">
1868<pre>use dataverse TinySocial;
1869
1870let $c := create-point(30.0,70.0)
1871return {&quot;point&quot;: $c}
1872</pre></div></div></li>
1873</ul>
1874
1875<ul>
1876
1877<li>
1878<p>The expected result is:</p>
1879
1880<div class="source">
1881<div class="source">
1882<pre>{ &quot;point&quot;: point(&quot;30.0,70.0&quot;) }
1883</pre></div></div></li>
1884</ul></div>
1885<div class="section">
1886<h3><a name="create-line"></a>create-line</h3>
1887
1888<ul>
1889
1890<li>
1891<p>Syntax:</p>
1892
1893<div class="source">
1894<div class="source">
1895<pre>create-line(point_expression1, point_expression2)
1896</pre></div></div></li>
1897
1898<li>
1899<p>Creates the primitive type <tt>line</tt> using <tt>point_expression1</tt> and <tt>point_expression2</tt>.</p></li>
1900
1901<li>Arguments:
1902
1903<ul>
1904
1905<li><tt>point_expression1</tt> : A <tt>point</tt> that represents the start point of the line.</li>
1906
1907<li><tt>point_expression2</tt> : A <tt>point</tt> that represents the end point of the line.</li>
1908 </ul></li>
1909
1910<li>Return Value:
1911
1912<ul>
1913
1914<li>A spatial <tt>line</tt> created using the points provided in <tt>point_expression1</tt> and <tt>point_expression2</tt>.</li>
1915 </ul></li>
1916
1917<li>
1918<p>Example:</p>
1919
1920<div class="source">
1921<div class="source">
1922<pre>use dataverse TinySocial;
1923
1924let $c := create-line(create-point(30.0,70.0), create-point(50.0,90.0))
1925return {&quot;line&quot;: $c}
1926</pre></div></div></li>
1927</ul>
1928
1929<ul>
1930
1931<li>
1932<p>The expected result is:</p>
1933
1934<div class="source">
1935<div class="source">
1936<pre>{ &quot;line&quot;: line(&quot;30.0,70.0 50.0,90.0&quot;) }
1937</pre></div></div></li>
1938</ul></div>
1939<div class="section">
1940<h3><a name="create-rectangle"></a>create-rectangle</h3>
1941
1942<ul>
1943
1944<li>
1945<p>Syntax:</p>
1946
1947<div class="source">
1948<div class="source">
1949<pre>create-rectangle(point_expression1, point_expression2)
1950</pre></div></div></li>
1951
1952<li>
1953<p>Creates the primitive type <tt>rectangle</tt> using <tt>point_expression1</tt> and <tt>point_expression2</tt>.</p></li>
1954
1955<li>Arguments:
1956
1957<ul>
1958
1959<li><tt>point_expression1</tt> : A <tt>point</tt> that represents the lower-left point of the rectangle.</li>
1960
1961<li><tt>point_expression2</tt> : A <tt>point</tt> that represents the upper-right point of the rectangle.</li>
1962 </ul></li>
1963
1964<li>Return Value:
1965
1966<ul>
1967
1968<li>A spatial <tt>rectangle</tt> created using the points provided in <tt>point_expression1</tt> and <tt>point_expression2</tt>.</li>
1969 </ul></li>
1970
1971<li>
1972<p>Example:</p>
1973
1974<div class="source">
1975<div class="source">
1976<pre>use dataverse TinySocial;
1977
1978let $c := create-rectangle(create-point(30.0,70.0), create-point(50.0,90.0))
1979return {&quot;rectangle&quot;: $c}
1980</pre></div></div></li>
1981</ul>
1982
1983<ul>
1984
1985<li>
1986<p>The expected result is:</p>
1987
1988<div class="source">
1989<div class="source">
1990<pre>{ &quot;rectangle&quot;: rectangle(&quot;30.0,70.0 50.0,90.0&quot;) }
1991</pre></div></div></li>
1992</ul></div>
1993<div class="section">
1994<h3><a name="create-circle"></a>create-circle</h3>
1995
1996<ul>
1997
1998<li>
1999<p>Syntax:</p>
2000
2001<div class="source">
2002<div class="source">
2003<pre>create-circle(point_expression, radius)
2004</pre></div></div></li>
2005
2006<li>
2007<p>Creates the primitive type <tt>circle</tt> using <tt>point_expression</tt> and <tt>radius</tt>.</p></li>
2008
2009<li>Arguments:
2010
2011<ul>
2012
2013<li><tt>point_expression</tt> : A <tt>point</tt> that represents the center of the circle.</li>
2014
2015<li><tt>radius</tt> : A <tt>double</tt> that represents the radius of the circle.</li>
2016 </ul></li>
2017
2018<li>Return Value:
2019
2020<ul>
2021
2022<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>
2023 </ul></li>
2024
2025<li>
2026<p>Example:</p>
2027
2028<div class="source">
2029<div class="source">
2030<pre>use dataverse TinySocial;
2031
2032let $c := create-circle(create-point(30.0,70.0), 5.0)
2033return {&quot;circle&quot;: $c}
2034</pre></div></div></li>
2035</ul>
2036
2037<ul>
2038
2039<li>
2040<p>The expected result is:</p>
2041
2042<div class="source">
2043<div class="source">
2044<pre>{ &quot;circle&quot;: circle(&quot;30.0,70.0 5.0&quot;) }
2045</pre></div></div></li>
2046</ul></div>
2047<div class="section">
2048<h3><a name="create-polygon"></a>create-polygon</h3>
2049
2050<ul>
2051
2052<li>
2053<p>Syntax:</p>
2054
2055<div class="source">
2056<div class="source">
2057<pre>create-polygon(list_expression)
2058</pre></div></div></li>
2059
2060<li>
2061<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>
2062
2063<li>Arguments:</li>
2064
2065<li><tt>list_expression</tt> : An OrderedList of doubles representing the points of the polygon.</li>
2066
2067<li>Return Value:</li>
2068
2069<li>A <tt>polygon</tt>, represents a spatial simple polygon created using the points provided in <tt>list_expression</tt>.</li>
2070
2071<li>
2072<p>Example:</p>
2073
2074<div class="source">
2075<div class="source">
2076<pre>use dataverse TinySocial;
2077
2078let $c := create-polygon([1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0])
2079return {&quot;polygon&quot;: $c}
2080</pre></div></div></li>
2081</ul>
2082
2083<ul>
2084
2085<li>
2086<p>The expected result is:</p>
2087
2088<div class="source">
2089<div class="source">
2090<pre>{ &quot;polygon&quot;: polygon(&quot;1.0,1.0 2.0,2.0 3.0,3.0 4.0,4.0&quot;) }
2091</pre></div></div></li>
2092</ul></div>
2093<div class="section">
2094<h3><a name="get-xget-y"></a>get-x/get-y</h3>
2095
2096<ul>
2097
2098<li>
2099<p>Syntax:</p>
2100
2101<div class="source">
2102<div class="source">
2103<pre>get-x(point_expression) or get-y(point_expression)
2104</pre></div></div></li>
2105
2106<li>
2107<p>Returns the x or y coordinates of a point <tt>point_expression</tt>.</p></li>
2108
2109<li>Arguments:
2110
2111<ul>
2112
2113<li><tt>point_expression</tt> : A <tt>point</tt>.</li>
2114 </ul></li>
2115
2116<li>Return Value:
2117
2118<ul>
2119
2120<li>A <tt>double</tt> representing the x or y coordinates of the point <tt>point_expression</tt>.</li>
2121 </ul></li>
2122
2123<li>
2124<p>Example:</p>
2125
2126<div class="source">
2127<div class="source">
2128<pre>use dataverse TinySocial;
2129
2130let $point := create-point(2.3,5.0)
2131return {&quot;x-coordinate&quot;: get-x($point), &quot;y-coordinate&quot;: get-y($point)}
2132</pre></div></div></li>
2133</ul>
2134
2135<ul>
2136
2137<li>
2138<p>The expected result is:</p>
2139
2140<div class="source">
2141<div class="source">
2142<pre>{ &quot;x-coordinate&quot;: 2.3d, &quot;y-coordinate&quot;: 5.0d }
2143</pre></div></div></li>
2144</ul></div>
2145<div class="section">
2146<h3><a name="get-points"></a>get-points</h3>
2147
2148<ul>
2149
2150<li>
2151<p>Syntax:</p>
2152
2153<div class="source">
2154<div class="source">
2155<pre>get-points(spatial_expression)
2156</pre></div></div></li>
2157
2158<li>
2159<p>Returns an ordered list of the points forming the spatial object <tt>spatial_expression</tt>.</p></li>
2160
2161<li>Arguments:
2162
2163<ul>
2164
2165<li><tt>spatial_expression</tt> : A <tt>point</tt>, <tt>line</tt>, <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
2166 </ul></li>
2167
2168<li>Return Value:
2169
2170<ul>
2171
2172<li>An <tt>OrderedList</tt> of the points forming the spatial object <tt>spatial_expression</tt>.</li>
2173 </ul></li>
2174
2175<li>
2176<p>Example:</p>
2177
2178<div class="source">
2179<div class="source">
2180<pre>use dataverse TinySocial;
2181
2182let $line := create-line(create-point(100.6,99.4), create-point(-72.0,-76.9))
2183let $rectangle := create-rectangle(create-point(9.2,49.0), create-point(77.8,111.1))
2184let $polygon := create-polygon([1.0,1.0,2.0,2.0,3.0,3.0,4.0,4.0])
2185let $line_list := get-points($line)
2186let $rectangle_list := get-points($rectangle)
2187let $polygon_list := get-points($polygon)
2188return {&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]}
2189</pre></div></div></li>
2190</ul>
2191
2192<ul>
2193
2194<li>
2195<p>The expected result is:</p>
2196
2197<div class="source">
2198<div class="source">
2199<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;) }
2200</pre></div></div></li>
2201</ul></div>
2202<div class="section">
2203<h3><a name="get-centerget-radius"></a>get-center/get-radius</h3>
2204
2205<ul>
2206
2207<li>
2208<p>Syntax:</p>
2209
2210<div class="source">
2211<div class="source">
2212<pre>get-center(circle_expression) or get-radius(circle_expression)
2213</pre></div></div></li>
2214
2215<li>
2216<p>Returns the center and the radius of a circle <tt>circle_expression</tt>, respectively.</p></li>
2217
2218<li>Arguments:
2219
2220<ul>
2221
2222<li><tt>circle_expression</tt> : A <tt>circle</tt>.</li>
2223 </ul></li>
2224
2225<li>Return Value:
2226
2227<ul>
2228
2229<li>A <tt>point</tt> or <tt>double</tt>, represent the center or radius of the circle <tt>circle_expression</tt>.</li>
2230 </ul></li>
2231
2232<li>
2233<p>Example:</p>
2234
2235<div class="source">
2236<div class="source">
2237<pre>use dataverse TinySocial;
2238
2239let $circle := create-circle(create-point(6.0,3.0), 1.0)
2240return {&quot;circle-radius&quot;: get-radius($circle), &quot;circle-center&quot;: get-center($circle)}
2241</pre></div></div></li>
2242</ul>
2243
2244<ul>
2245
2246<li>
2247<p>The expected result is:</p>
2248
2249<div class="source">
2250<div class="source">
2251<pre>{ &quot;circle-radius&quot;: 1.0d, &quot;circle-center&quot;: point(&quot;6.0,3.0&quot;) }
2252</pre></div></div></li>
2253</ul></div>
2254<div class="section">
2255<h3><a name="spatial-distance"></a>spatial-distance</h3>
2256
2257<ul>
2258
2259<li>
2260<p>Syntax:</p>
2261
2262<div class="source">
2263<div class="source">
2264<pre>spatial-distance(point_expression1, point_expression2)
2265</pre></div></div></li>
2266
2267<li>
2268<p>Returns the Euclidean distance between <tt>point_expression1</tt> and <tt>point_expression2</tt>.</p></li>
2269
2270<li>Arguments:
2271
2272<ul>
2273
2274<li><tt>point_expression1</tt> : A <tt>point</tt>.</li>
2275
2276<li><tt>point_expression2</tt> : A <tt>point</tt>.</li>
2277 </ul></li>
2278
2279<li>Return Value:
2280
2281<ul>
2282
2283<li>A <tt>double</tt> as the Euclidean distance between <tt>point_expression1</tt> and <tt>point_expression2</tt>.</li>
2284 </ul></li>
2285
2286<li>
2287<p>Example:</p>
2288
2289<div class="source">
2290<div class="source">
2291<pre>use dataverse TinySocial;
2292
2293for $t in dataset('TweetMessages')
2294let $d := spatial-distance($t.sender-location, create-point(30.0,70.0))
2295return {&quot;point&quot;: $t.sender-location, &quot;distance&quot;: $d}
2296</pre></div></div></li>
2297</ul>
2298
2299<ul>
2300
2301<li>
2302<p>The expected result is:</p>
2303
2304<div class="source">
2305<div class="source">
2306<pre>{ &quot;point&quot;: point(&quot;47.44,80.65&quot;), &quot;distance&quot;: 20.434678857275934d }
2307{ &quot;point&quot;: point(&quot;29.15,76.53&quot;), &quot;distance&quot;: 6.585089217315132d }
2308{ &quot;point&quot;: point(&quot;37.59,68.42&quot;), &quot;distance&quot;: 7.752709203884797d }
2309{ &quot;point&quot;: point(&quot;24.82,94.63&quot;), &quot;distance&quot;: 25.168816023007512d }
2310{ &quot;point&quot;: point(&quot;32.84,67.14&quot;), &quot;distance&quot;: 4.030533463451212d }
2311{ &quot;point&quot;: point(&quot;29.72,75.8&quot;), &quot;distance&quot;: 5.806754687430835d }
2312{ &quot;point&quot;: point(&quot;39.28,70.48&quot;), &quot;distance&quot;: 9.292405501268227d }
2313{ &quot;point&quot;: point(&quot;40.09,92.69&quot;), &quot;distance&quot;: 24.832321679617472d }
2314{ &quot;point&quot;: point(&quot;47.51,83.99&quot;), &quot;distance&quot;: 22.41250097601782d }
2315{ &quot;point&quot;: point(&quot;36.21,72.6&quot;), &quot;distance&quot;: 6.73231758015024d }
2316{ &quot;point&quot;: point(&quot;46.05,93.34&quot;), &quot;distance&quot;: 28.325926286707734d }
2317{ &quot;point&quot;: point(&quot;36.86,74.62&quot;), &quot;distance&quot;: 8.270671073135482d }
2318</pre></div></div></li>
2319</ul></div>
2320<div class="section">
2321<h3><a name="spatial-area"></a>spatial-area</h3>
2322
2323<ul>
2324
2325<li>
2326<p>Syntax:</p>
2327
2328<div class="source">
2329<div class="source">
2330<pre>spatial-area(spatial_2d_expression)
2331</pre></div></div></li>
2332
2333<li>
2334<p>Returns the spatial area of <tt>spatial_2d_expression</tt>.</p></li>
2335
2336<li>Arguments:
2337
2338<ul>
2339
2340<li><tt>spatial_2d_expression</tt> : A <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
2341 </ul></li>
2342
2343<li>Return Value:
2344
2345<ul>
2346
2347<li>A <tt>double</tt> representing the area of <tt>spatial_2d_expression</tt>.</li>
2348 </ul></li>
2349
2350<li>
2351<p>Example:</p>
2352
2353<div class="source">
2354<div class="source">
2355<pre>use dataverse TinySocial;
2356
2357let $circleArea := spatial-area(create-circle(create-point(0.0,0.0), 5.0))
2358return {&quot;Area&quot;:$circleArea}
2359</pre></div></div></li>
2360</ul>
2361
2362<ul>
2363
2364<li>
2365<p>The expected result is:</p>
2366
2367<div class="source">
2368<div class="source">
2369<pre>{ &quot;Area&quot;: 78.53981625d }
2370</pre></div></div></li>
2371</ul></div>
2372<div class="section">
2373<h3><a name="spatial-intersect"></a>spatial-intersect</h3>
2374
2375<ul>
2376
2377<li>
2378<p>Syntax:</p>
2379
2380<div class="source">
2381<div class="source">
2382<pre>spatial-intersect(spatial_expression1, spatial_expression2)
2383</pre></div></div></li>
2384
2385<li>
2386<p>Checks whether <tt>@arg1</tt> and <tt>@arg2</tt> spatially intersect each other.</p></li>
2387
2388<li>Arguments:
2389
2390<ul>
2391
2392<li><tt>spatial_expression1</tt> : A <tt>point</tt>, <tt>line</tt>, <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
2393
2394<li><tt>spatial_expression2</tt> : A <tt>point</tt>, <tt>line</tt>, <tt>rectangle</tt>, <tt>circle</tt>, or <tt>polygon</tt>.</li>
2395 </ul></li>
2396
2397<li>Return Value:
2398
2399<ul>
2400
2401<li>A <tt>boolean</tt> representing whether <tt>spatial_expression1</tt> and <tt>spatial_expression2</tt> spatially overlap with each other.</li>
2402 </ul></li>
2403
2404<li>
2405<p>Example:</p>
2406
2407<div class="source">
2408<div class="source">
2409<pre>use dataverse TinySocial;
2410
2411for $t in dataset('TweetMessages')
2412where spatial-intersect($t.sender-location, create-rectangle(create-point(30.0,70.0), create-point(40.0,80.0)))
2413return $t
2414</pre></div></div></li>
2415</ul>
2416
2417<ul>
2418
2419<li>
2420<p>The expected result is:</p>
2421
2422<div class="source">
2423<div class="source">
2424<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; }
2425{ &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; }
2426{ &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; }
2427</pre></div></div></li>
2428</ul></div>
2429<div class="section">
2430<h3><a name="spatial-cell"></a>spatial-cell</h3>
2431
2432<ul>
2433
2434<li>
2435<p>Syntax:</p>
2436
2437<div class="source">
2438<div class="source">
2439<pre>spatial-cell(point_expression1, point_expression2, x_increment, y_increment)
2440</pre></div></div></li>
2441
2442<li>
2443<p>Returns the grid cell that <tt>point_expression1</tt> belongs to.</p></li>
2444
2445<li>Arguments:
2446
2447<ul>
2448
2449<li><tt>point_expression1</tt> : A <tt>point</tt> representing the point of interest that its grid cell will be returned.</li>
2450
2451<li><tt>point_expression2</tt> : A <tt>point</tt> representing the origin of the grid.</li>
2452
2453<li><tt>x_increment</tt> : A <tt>double</tt>, represents X increments.</li>
2454
2455<li><tt>y_increment</tt> : A <tt>double</tt>, represents Y increments.</li>
2456 </ul></li>
2457
2458<li>Return Value:
2459
2460<ul>
2461
2462<li>A <tt>rectangle</tt> representing the grid cell that <tt>point_expression1</tt> belongs to.</li>
2463 </ul></li>
2464
2465<li>
2466<p>Example:</p>
2467
2468<div class="source">
2469<div class="source">
2470<pre>use dataverse TinySocial;
2471
2472for $t in dataset('TweetMessages')
2473group by $c := spatial-cell($t.sender-location, create-point(20.0,50.0), 5.5, 6.0) with $t
2474let $num := count($t)
2475return { &quot;cell&quot;: $c, &quot;count&quot;: $num}
2476</pre></div></div></li>
2477</ul>
2478
2479<ul>
2480
2481<li>
2482<p>The expected result is:</p>
2483
2484<div class="source">
2485<div class="source">
2486<pre>{ &quot;cell&quot;: rectangle(&quot;20.0,92.0 25.5,98.0&quot;), &quot;count&quot;: 1i64 }
2487{ &quot;cell&quot;: rectangle(&quot;25.5,74.0 31.0,80.0&quot;), &quot;count&quot;: 2i64 }
2488{ &quot;cell&quot;: rectangle(&quot;31.0,62.0 36.5,68.0&quot;), &quot;count&quot;: 1i64 }
2489{ &quot;cell&quot;: rectangle(&quot;31.0,68.0 36.5,74.0&quot;), &quot;count&quot;: 1i64 }
2490{ &quot;cell&quot;: rectangle(&quot;36.5,68.0 42.0,74.0&quot;), &quot;count&quot;: 2i64 }
2491{ &quot;cell&quot;: rectangle(&quot;36.5,74.0 42.0,80.0&quot;), &quot;count&quot;: 1i64 }
2492{ &quot;cell&quot;: rectangle(&quot;36.5,92.0 42.0,98.0&quot;), &quot;count&quot;: 1i64 }
2493{ &quot;cell&quot;: rectangle(&quot;42.0,80.0 47.5,86.0&quot;), &quot;count&quot;: 1i64 }
2494{ &quot;cell&quot;: rectangle(&quot;42.0,92.0 47.5,98.0&quot;), &quot;count&quot;: 1i64 }
2495{ &quot;cell&quot;: rectangle(&quot;47.5,80.0 53.0,86.0&quot;), &quot;count&quot;: 1i64 }
2496</pre></div></div></li>
2497</ul></div></div>
2498<div class="section">
2499<h2><a name="Similarity_Functions_Back_to_TOC"></a><a name="SimilarityFunctions" id="SimilarityFunctions">Similarity Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
2500<p>AsterixDB supports queries with different similarity functions, including <a class="externalLink" href="http://en.wikipedia.org/wiki/Levenshtein_distance">edit distance</a> and <a class="externalLink" href="https://en.wikipedia.org/wiki/Jaccard_index">Jaccard</a>.</p>
2501<div class="section">
2502<h3><a name="edit-distance"></a>edit-distance</h3>
2503
2504<ul>
2505
2506<li>
2507<p>Syntax:</p>
2508
2509<div class="source">
2510<div class="source">
2511<pre>edit-distance(expression1, expression2)
2512</pre></div></div></li>
2513
2514<li>
2515<p>Returns the edit distance of <tt>expression1</tt> and <tt>expression2</tt>.</p></li>
2516
2517<li>Arguments:
2518
2519<ul>
2520
2521<li><tt>expression1</tt> : A <tt>string</tt> or a homogeneous <tt>OrderedList</tt> of a comparable item type.</li>
2522
2523<li><tt>expression2</tt> : The same type as <tt>expression1</tt>.</li>
2524 </ul></li>
2525
2526<li>Return Value:
2527
2528<ul>
2529
2530<li>An <tt>int64</tt> that represents the edit distance between <tt>expression1</tt> and <tt>expression2</tt>.</li>
2531 </ul></li>
2532
2533<li>Note: An <a href="similarity.html#UsingIndexesToSupportSimilarityQueries">n-gram index</a> can be utilized for this function.</li>
2534
2535<li>
2536<p>Example:</p>
2537
2538<div class="source">
2539<div class="source">
2540<pre>use dataverse TinySocial;
2541
2542for $user in dataset('FacebookUsers')
2543let $ed := edit-distance($user.name, &quot;Suzanna Tilson&quot;)
2544where $ed &lt;= 2
2545return $user
2546</pre></div></div></li>
2547</ul>
2548
2549<ul>
2550
2551<li>
2552<p>The expected result is:</p>
2553
2554<div class="source">
2555<div class="source">
2556<pre>{
2557&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 }},
2558&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 } ]
2559}
2560</pre></div></div></li>
2561</ul></div>
2562<div class="section">
2563<h3><a name="edit-distance-check"></a>edit-distance-check</h3>
2564
2565<ul>
2566
2567<li>
2568<p>Syntax:</p>
2569
2570<div class="source">
2571<div class="source">
2572<pre>edit-distance-check(expression1, expression2, threshold)
2573</pre></div></div></li>
2574
2575<li>
2576<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>
2577
2578<li>
2579<p>Arguments:</p>
2580
2581<ul>
2582
2583<li><tt>expression1</tt> : A <tt>string</tt> or a homogeneous <tt>OrderedList</tt> of a comparable item type.</li>
2584
2585<li><tt>expression2</tt> : The same type as <tt>expression1</tt>.</li>
2586
2587<li><tt>threshold</tt> : An <tt>int64</tt> that represents the distance threshold.</li>
2588 </ul></li>
2589
2590<li>Return Value:
2591
2592<ul>
2593
2594<li>An <tt>OrderedList</tt> with two items:
2595
2596<ul>
2597
2598<li>The first item contains a <tt>boolean</tt> value representing whether <tt>expression1</tt> and <tt>expression2</tt> are similar.</li>
2599
2600<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>
2601 </ul></li>
2602 </ul></li>
2603
2604<li>Note: An <a href="similarity.html#UsingIndexesToSupportSimilarityQueries">n-gram index</a> can be utilized for this function.</li>
2605
2606<li>
2607<p>Example:</p>
2608
2609<div class="source">
2610<div class="source">
2611<pre>use dataverse TinySocial;
2612
2613for $user in dataset('FacebookUsers')
2614let $ed := edit-distance-check($user.name, &quot;Suzanna Tilson&quot;, 2)
2615where $ed[0]
2616return $ed[1]
2617</pre></div></div></li>
2618</ul>
2619
2620<ul>
2621
2622<li>
2623<p>The expected result is:</p>
2624
2625<div class="source">
2626<div class="source">
2627<pre>2
2628</pre></div></div></li>
2629</ul></div>
2630<div class="section">
2631<h3><a name="edit-distance-contains"></a>edit-distance-contains</h3>
2632
2633<ul>
2634
2635<li>Syntax:</li>
2636</ul>
2637<p>edit-distance-contains(expression1, expression2, threshold)</p>
2638
2639<ul>
2640
2641<li>
2642<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>
2643
2644<li>
2645<p>Arguments:</p>
2646
2647<ul>
2648
2649<li><tt>expression1</tt> : A <tt>string</tt> or a homogeneous <tt>OrderedList</tt> of a comparable item type.</li>
2650
2651<li><tt>expression2</tt> : The same type as <tt>expression1</tt>.</li>
2652
2653<li><tt>threshold</tt> : An <tt>int32</tt> that represents the distance threshold.</li>
2654 </ul></li>
2655
2656<li>Return Value:
2657
2658<ul>
2659
2660<li>An <tt>OrderedList</tt> with two items:
2661
2662<ul>
2663
2664<li>The first item contains a <tt>boolean</tt> value representing whether <tt>expression1</tt> can contain <tt>expression2</tt>.</li>
2665
2666<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>
2667 </ul></li>
2668 </ul></li>
2669
2670<li>Note: An <a href="similarity.html#UsingIndexesToSupportSimilarityQueries">n-gram index</a> can be utilized for this function.</li>
2671
2672<li>
2673<p>Example:</p>
2674
2675<div class="source">
2676<div class="source">
2677<pre>let $i := edit-distance-contains(&quot;happy&quot;,&quot;hapr&quot;,2)
2678return $i;
2679</pre></div></div></li>
2680</ul>
2681
2682<ul>
2683
2684<li>
2685<p>The expected result is:</p>
2686
2687<div class="source">
2688<div class="source">
2689<pre>[ true, 1 ]
2690</pre></div></div></li>
2691</ul></div>
2692<div class="section">
2693<h3><a name="similarity-jaccard"></a>similarity-jaccard</h3>
2694
2695<ul>
2696
2697<li>
2698<p>Syntax:</p>
2699
2700<div class="source">
2701<div class="source">
2702<pre>similarity-jaccard(list_expression1, list_expression2)
2703</pre></div></div></li>
2704
2705<li>
2706<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>
2707
2708<li>Arguments:
2709
2710<ul>
2711
2712<li><tt>list_expression1</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
2713
2714<li><tt>list_expression2</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
2715 </ul></li>
2716
2717<li>Return Value:
2718
2719<ul>
2720
2721<li>A <tt>float</tt> that represents the Jaccard similarity of <tt>list_expression1</tt> and <tt>list_expression2</tt>.</li>
2722 </ul></li>
2723
2724<li>Note: A <a href="similarity.html#UsingIndexesToSupportSimilarityQueries">keyword index</a> can be utilized for this function.</li>
2725
2726<li>
2727<p>Example:</p>
2728
2729<div class="source">
2730<div class="source">
2731<pre>use dataverse TinySocial;
2732
2733for $user in dataset('FacebookUsers')
2734let $sim := similarity-jaccard($user.friend-ids, [1,5,9,10])
2735where $sim &gt;= 0.6f
2736return $user
2737</pre></div></div></li>
2738</ul>
2739
2740<ul>
2741
2742<li>
2743<p>The expected result is:</p>
2744
2745<div class="source">
2746<div class="source">
2747<pre>{
2748&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 }},
2749&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;) } ]
2750}
2751{
2752&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 }},
2753&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;) } ]
2754}
2755</pre></div></div></li>
2756</ul></div>
2757<div class="section">
2758<h3><a name="similarity-jaccard-check"></a>similarity-jaccard-check</h3>
2759
2760<ul>
2761
2762<li>
2763<p>Syntax:</p>
2764
2765<div class="source">
2766<div class="source">
2767<pre>similarity-jaccard-check(list_expression1, list_expression2, threshold)
2768</pre></div></div></li>
2769
2770<li>
2771<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>
2772
2773<li>
2774<p>Arguments:</p>
2775
2776<ul>
2777
2778<li><tt>list_expression1</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
2779
2780<li><tt>list_expression2</tt> : An <tt>UnorderedList</tt> or <tt>OrderedList</tt>.</li>
2781
2782<li><tt>threshold</tt> : A <tt>float</tt> that represents the similarity threshold.</li>
2783 </ul></li>
2784
2785<li>Return Value:
2786
2787<ul>
2788
2789<li>An <tt>OrderedList</tt> with two items:</li>
2790
2791<li>The first item contains a <tt>boolean</tt> value representing whether <tt>list_expression1</tt> and <tt>list_expression2</tt> are similar.</li>
2792
2793<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>
2794 </ul></li>
2795
2796<li>Note: A <a href="similarity.html#UsingIndexesToSupportSimilarityQueries">keyword index</a> can be utilized for this function.</li>
2797
2798<li>
2799<p>Example:</p>
2800
2801<div class="source">
2802<div class="source">
2803<pre>use dataverse TinySocial;
2804
2805for $user in dataset('FacebookUsers')
2806let $sim := similarity-jaccard-check($user.friend-ids, [1,5,9,10], 0.6f)
2807where $sim[0]
2808return $sim[1]
2809</pre></div></div></li>
2810</ul>
2811
2812<ul>
2813
2814<li>
2815<p>The expected result is:</p>
2816
2817<div class="source">
2818<div class="source">
2819<pre>0.75f
28201.0f
2821</pre></div></div></li>
2822</ul></div>
2823<div class="section">
2824<h3><a name="Similarity_Operator_"></a>Similarity Operator ~=</h3>
2825
2826<ul>
2827
2828<li>&#x201c;<tt>~=</tt>&#x201d; is syntactic sugar for expressing a similarity condition with a given similarity threshold.</li>
2829
2830<li>The similarity function and threshold for &#x201c;<tt>~=</tt>&#x201d; are controlled via &#x201c;set&#x201d; directives.</li>
2831
2832<li>The &#x201c;<tt>~=</tt>&#x201d; operator returns a <tt>boolean</tt> value that represents whether the operands are similar.</li>
2833
2834<li>
2835<p>Example for Jaccard similarity:</p>
2836
2837<div class="source">
2838<div class="source">
2839<pre>use dataverse TinySocial;
2840
2841set simfunction &quot;jaccard&quot;;
2842set simthreshold &quot;0.6f&quot;;
2843
2844for $user in dataset('FacebookUsers')
2845where $user.friend-ids ~= [1,5,9,10]
2846return $user
2847</pre></div></div></li>
2848</ul>
2849
2850<ul>
2851
2852<li>
2853<p>The expected result is:</p>
2854
2855<div class="source">
2856<div class="source">
2857<pre>{
2858&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 }},
2859&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;) } ]
2860}
2861{
2862&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 }},
2863&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;) } ]
2864}
2865</pre></div></div></li>
2866</ul>
2867
2868<ul>
2869
2870<li>
2871<p>Example for edit-distance similarity:</p>
2872
2873<div class="source">
2874<div class="source">
2875<pre>use dataverse TinySocial;
2876
2877set simfunction &quot;edit-distance&quot;;
2878set simthreshold &quot;2&quot;;
2879
2880for $user in dataset('FacebookUsers')
2881where $user.name ~= &quot;Suzanna Tilson&quot;
2882return $user
2883</pre></div></div></li>
2884</ul>
2885
2886<ul>
2887
2888<li>
2889<p>The expected output is:</p>
2890
2891<div class="source">
2892<div class="source">
2893<pre>{
2894&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 }},
2895&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 } ]
2896}
2897</pre></div></div></li>
2898</ul></div></div>
2899<div class="section">
2900<h2><a name="Tokenizing_Functions_Back_to_TOC"></a><a name="TokenizingFunctions" id="TokenizingFunctions">Tokenizing Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
2901<div class="section">
2902<h3><a name="word-tokens"></a>word-tokens</h3>
2903
2904<ul>
2905
2906<li>
2907<p>Syntax:</p>
2908
2909<div class="source">
2910<div class="source">
2911<pre>word-tokens(string_expression)
2912</pre></div></div></li>
2913
2914<li>
2915<p>Returns a list of word tokens of <tt>string_expression</tt> using non-alphanumeric characters as delimiters.</p></li>
2916
2917<li>Arguments:
2918
2919<ul>
2920
2921<li><tt>string_expression</tt> : A <tt>string</tt> that will be tokenized.</li>
2922 </ul></li>
2923
2924<li>Return Value:
2925
2926<ul>
2927
2928<li>An <tt>OrderedList</tt> of <tt>string</tt> word tokens.</li>
2929 </ul></li>
2930
2931<li>
2932<p>Example:</p>
2933
2934<div class="source">
2935<div class="source">
2936<pre>use dataverse TinySocial;
2937
2938for $t in dataset('TweetMessages')
2939let $tokens := word-tokens($t.message-text)
2940where $t.send-time &gt;= datetime('2012-01-01T00:00:00')
2941return {
2942&quot;tweetid&quot;: $t.tweetid,
2943&quot;word-tokens&quot;: $tokens
2944}
2945</pre></div></div></li>
2946</ul>
2947
2948<ul>
2949
2950<li>
2951<p>The expected result is:</p>
2952
2953<div class="source">
2954<div class="source">
2955<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; ] }
2956</pre></div></div></li>
2957</ul>
2958<!-- ### hashed-word-tokens ###
2959 * Syntax:
2960
2961 hashed-word-tokens(string_expression)
2962
2963 * Returns a list of hashed word tokens of `string_expression`.
2964 * Arguments:
2965 * `string_expression` : A `string` that will be tokenized.
2966 * Return Value:
2967 * An `OrderedList` of `int32` hashed tokens.
2968
2969 * Example:
2970
2971 use dataverse TinySocial;
2972
2973 for $t in dataset('TweetMessages')
2974 let $tokens := hashed-word-tokens($t.message-text)
2975 where $t.send-time >= datetime('2012-01-01T00:00:00')
2976 return {
2977 "tweetid": $t.tweetid,
2978 "hashed-word-tokens": $tokens
2979 }
2980
2981
2982 * The expected result is:
2983
2984 { "tweetid": "9", "hashed-word-tokens": [ -1217719622, -447857469, -1884722688, -325178649, 210976949, 285049676, 1916743959 ] }
2985
2986
2987### counthashed-word-tokens ###
2988 * Syntax:
2989
2990 counthashed-word-tokens(string_expression)
2991
2992 * 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.
2993 * Arguments:
2994 * `string_expression` : A `String` that will be tokenized.
2995 * Return Value:
2996 * An `OrderedList` of `Int32` hashed tokens.
2997 * Example:
2998
2999 use dataverse TinySocial;
3000
3001 for $t in dataset('TweetMessages')
3002 let $tokens := counthashed-word-tokens($t.message-text)
3003 where $t.send-time >= datetime('2012-01-01T00:00:00')
3004 return {
3005 "tweetid": $t.tweetid,
3006 "counthashed-word-tokens": $tokens
3007 }
3008
3009
3010 * The expected result is:
3011
3012 { "tweetid": "9", "counthashed-word-tokens": [ -1217719622, -447857469, -1884722688, -325178649, 210976949, 285049676, 1916743959 ] }
3013
3014
3015### gram-tokens ###
3016 * Syntax:
3017
3018 gram-tokens(string_expression, gram_length, boolean_expression)
3019
3020 * 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.
3021 * Arguments:
3022 * `string_expression` : A `String` that will be tokenized.
3023 * `gram_length` : An `Int32` as the length of grams.
3024 * `boolean_expression` : A `Boolean` value to indicate whether to generate additional grams by pre- and postfixing `string_expression` with special characters.
3025 * Return Value:
3026 * An `OrderedList` of String gram tokens.
3027
3028 * Example:
3029
3030 use dataverse TinySocial;
3031
3032 for $t in dataset('TweetMessages')
3033 let $tokens := gram-tokens($t.message-text, 3, true)
3034 where $t.send-time >= datetime('2012-01-01T00:00:00')
3035 return {
3036 "tweetid": $t.tweetid,
3037 "gram-tokens": $tokens
3038 }
3039
3040
3041 * The expected result is:
3042
3043 {
3044 "tweetid": "9",
3045 "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",
3046 "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$$" ]
3047 }
3048
3049
3050### hashed-gram-tokens ###
3051 * Syntax:
3052
3053 hashed-gram-tokens(string_expression, gram_length, boolean_expression)
3054
3055 * Returns a list of hashed gram tokens of `string_expression`.
3056 * Arguments:
3057 * `string_expression` : A `String` that will be tokenized.
3058 * `gram_length` : An `Int32` as the length of grams.
3059 * `boolean_expression` : A `Boolean` to indicate whether to generate additional grams by pre- and postfixing `string_expression` with special characters.
3060 * Return Value:
3061 * An `OrderedList` of `Int32` hashed gram tokens.
3062
3063 * Example:
3064
3065 use dataverse TinySocial;
3066
3067 for $t in dataset('TweetMessages')
3068 let $tokens := hashed-gram-tokens($t.message-text, 3, true)
3069 where $t.send-time >= datetime('2012-01-01T00:00:00')
3070 return {
3071 "tweetid": $t.tweetid,
3072 "hashed-gram-tokens": $tokens
3073 }
3074
3075
3076 * The expected result is:
3077
3078 {
3079 "tweetid": "9",
3080 "hashed-gram-tokens": [ 40557178, -2002241593, 161665899, -856104603, -500544946, 693410611, 395674299, -1015235909, 1115608337, 1187999872, -31006095, -219180466, -1676061637,
3081 1040194153, -1339307841, -1527110163, -1884722688, -179148713, -431014627, -1789789823, -1209719926, 684519765, -486734513, 1734740619, -1971673751, -932421915, -2064668066,
3082 -937135958, -790946468, -69070309, 1561601454, 26169001, -160734571, 1330043462, -486734513, -18796768, -470303314, 113421364, 1615760212, 1688217556, 1223719184, 536568131,
3083 1682609873, 2935161, -414769471, -1027490137, 1602276102, 1050490461 ]
3084 }
3085
3086
3087### counthashed-gram-tokens ###
3088 * Syntax:
3089
3090 counthashed-gram-tokens(string_expression, gram_length, boolean_expression)
3091
3092 * 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.
3093 * Arguments:
3094 * `string_expression` : A `String` that will be tokenized.
3095 * `gram_length` : An `Int32`, length of grams to generate.
3096 * `boolean_expression` : A `Boolean`, whether to generate additional grams by pre- and postfixing `string_expression` with special characters.
3097 * Return Value:
3098 * An `OrderedList` of `Int32` hashed gram tokens.
3099
3100 * Example:
3101
3102 use dataverse TinySocial;
3103
3104 for $t in dataset('TweetMessages')
3105 let $tokens := counthashed-gram-tokens($t.message-text, 3, true)
3106 where $t.send-time >= datetime('2012-01-01T00:00:00')
3107 return {
3108 "tweetid": $t.tweetid,
3109 "counthashed-gram-tokens": $tokens
3110 }
3111
3112
3113 * The expected result is:
3114
3115 {
3116 "tweetid": "9",
3117 "counthashed-gram-tokens": [ 40557178, -2002241593, 161665899, -856104603, -500544946, 693410611, 395674299, -1015235909, 1115608337, 1187999872, -31006095, -219180466, -1676061637,
3118 1040194153, -1339307841, -1527110163, -1884722688, -179148713, -431014627, -1789789823, -1209719926, 684519765, -486734513, 1734740619, -1971673751, -932421915, -2064668066, -937135958,
3119 -790946468, -69070309, 1561601454, 26169001, -160734571, 1330043462, -486734512, -18796768, -470303314, 113421364, 1615760212, 1688217556, 1223719184, 536568131, 1682609873, 2935161,
3120 -414769471, -1027490137, 1602276102, 1050490461 ]
3121 } --></div></div>
3122<div class="section">
3123<h2><a name="Temporal_Functions_Back_to_TOC"></a><a name="TemporalFunctions" id="TemporalFunctions">Temporal Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
3124<div class="section">
3125<h3><a name="get-yearget-monthget-dayget-hourget-minuteget-secondget-millisecond"></a>get-year/get-month/get-day/get-hour/get-minute/get-second/get-millisecond</h3>
3126
3127<ul>
3128
3129<li>
3130<p>Syntax:</p>
3131
3132<div class="source">
3133<div class="source">
3134<pre>get-year/get-month/get-day/get-hour/get-minute/get-second/get-millisecond(temporal_expression)
3135</pre></div></div></li>
3136
3137<li>
3138<p>Accessors for accessing fields in a temporal value</p></li>
3139
3140<li>Arguments:
3141
3142<ul>
3143
3144<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>
3145 </ul></li>
3146
3147<li>Return Value:
3148
3149<ul>
3150
3151<li>An <tt>int64</tt> value representing the field to be extracted.</li>
3152 </ul></li>
3153
3154<li>
3155<p>Example:</p>
3156
3157<div class="source">
3158<div class="source">
3159<pre>let $c1 := date(&quot;2010-10-30&quot;)
3160let $c2 := datetime(&quot;1987-11-19T23:49:23.938&quot;)
3161let $c3 := time(&quot;12:23:34.930+07:00&quot;)
3162let $c4 := duration(&quot;P3Y73M632DT49H743M3948.94S&quot;)
3163
3164return {&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)}
3165</pre></div></div></li>
3166</ul>
3167
3168<ul>
3169
3170<li>
3171<p>The expected result is:</p>
3172
3173<div class="source">
3174<div class="source">
3175<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 }
3176</pre></div></div></li>
3177</ul></div>
3178<div class="section">
3179<h3><a name="adjust-datetime-for-timezone"></a>adjust-datetime-for-timezone</h3>
3180
3181<ul>
3182
3183<li>
3184<p>Syntax:</p>
3185
3186<div class="source">
3187<div class="source">
3188<pre>adjust-datetime-for-timezone(datetime_expression, string_expression)
3189</pre></div></div></li>
3190
3191<li>
3192<p>Adjusts the given datetime <tt>datetime_expression</tt> by applying the timezone information <tt>string_expression</tt>.</p></li>
3193
3194<li>Arguments:
3195
3196<ul>
3197
3198<li><tt>datetime_expression</tt> : A <tt>datetime</tt> value to be adjusted.</li>
3199
3200<li><tt>string_expression</tt> : A <tt>string</tt> representing the timezone information.</li>
3201 </ul></li>
3202
3203<li>Return Value:
3204
3205<ul>
3206
3207<li>A <tt>string</tt> value representing the new datetime after being adjusted by the timezone information.</li>
3208 </ul></li>
3209
3210<li>
3211<p>Example:</p>
3212
3213<div class="source">
3214<div class="source">
3215<pre>use dataverse TinySocial;
3216
3217for $i in dataset('TweetMessages')
3218return {&quot;adjusted-send-time&quot;: adjust-datetime-for-timezone($i.send-time, &quot;+08:00&quot;), &quot;message&quot;: $i.message-text}
3219</pre></div></div></li>
3220</ul>
3221
3222<ul>
3223
3224<li>
3225<p>The expected result is:</p>
3226
3227<div class="source">
3228<div class="source">
3229<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; }
3230{ &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; }
3231{ &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; }
3232{ &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; }
3233{ &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; }
3234{ &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; }
3235{ &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; }
3236{ &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; }
3237{ &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; }
3238{ &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; }
3239{ &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; }
3240{ &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; }
3241</pre></div></div></li>
3242</ul></div>
3243<div class="section">
3244<h3><a name="adjust-time-for-timezone"></a>adjust-time-for-timezone</h3>
3245
3246<ul>
3247
3248<li>
3249<p>Syntax:</p>
3250
3251<div class="source">
3252<div class="source">
3253<pre>adjust-time-for-timezone(time_expression, string_expression)
3254</pre></div></div></li>
3255
3256<li>
3257<p>Adjusts the given time <tt>time_expression</tt> by applying the timezone information <tt>string_expression</tt>.</p></li>
3258
3259<li>Arguments:
3260
3261<ul>
3262
3263<li><tt>time_expression</tt> : A <tt>time</tt> value to be adjusted.</li>
3264
3265<li><tt>string_expression</tt> : A <tt>string</tt> representing the timezone information.</li>
3266 </ul></li>
3267
3268<li>Return Value:
3269
3270<ul>
3271
3272<li>A <tt>string</tt> value representing the new time after being adjusted by the timezone information.</li>
3273 </ul></li>
3274
3275<li>
3276<p>Example:</p>
3277
3278<div class="source">
3279<div class="source">
3280<pre>use dataverse TinySocial;
3281
3282for $i in dataset('TweetMessages')
3283return {&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}
3284</pre></div></div></li>
3285</ul>
3286
3287<ul>
3288
3289<li>
3290<p>The expected result is:</p>
3291
3292<div class="source">
3293<div class="source">
3294<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; }
3295{ &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; }
3296{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like motorola the speed is good:)&quot; }
3297{ &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; }
3298{ &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; }
3299{ &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; }
3300{ &quot;adjusted-send-time&quot;: &quot;18:10:00.000+08:00&quot;, &quot;message&quot;: &quot; like samsung the platform is good&quot; }
3301{ &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; }
3302{ &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; }
3303{ &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; }
3304{ &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; }
3305{ &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; }
3306</pre></div></div></li>
3307</ul></div>
3308<div class="section">
3309<h3><a name="calendar-duration-from-datetime"></a>calendar-duration-from-datetime</h3>
3310
3311<ul>
3312
3313<li>
3314<p>Syntax:</p>
3315
3316<div class="source">
3317<div class="source">
3318<pre>calendar-duration-from-datetime(datetime_expression, duration_expression)
3319</pre></div></div></li>
3320
3321<li>
3322<p>Gets a user-friendly representation of the duration <tt>duration_expression</tt> based on the given datetime <tt>datetime_expression</tt>.</p></li>
3323
3324<li>Arguments:
3325
3326<ul>
3327
3328<li><tt>datetime_expression</tt> : A <tt>datetime</tt> value to be used as the reference time point.</li>
3329
3330<li><tt>duration_expression</tt> : A <tt>duration</tt> value to be converted.</li>
3331 </ul></li>
3332
3333<li>Return Value:
3334
3335<ul>
3336
3337<li>A <tt>duration</tt> value with the duration as <tt>duration_expression</tt> but with a user-friendly representation.</li>
3338 </ul></li>
3339
3340<li>
3341<p>Example:</p>
3342
3343<div class="source">
3344<div class="source">
3345<pre>use dataverse TinySocial;
3346
3347for $i in dataset('TweetMessages')
3348where $i.send-time &gt; datetime(&quot;2011-01-01T00:00:00&quot;)
3349return {&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;)))}
3350</pre></div></div></li>
3351</ul>
3352
3353<ul>
3354
3355<li>
3356<p>The expected result is:</p>
3357
3358<div class="source">
3359<div class="source">
3360<pre>{ &quot;since-2011&quot;: duration(&quot;P359DT10H10M&quot;), &quot;since-2011-user-friendly&quot;: duration(&quot;P11M23DT10H10M&quot;) }
3361{ &quot;since-2011&quot;: duration(&quot;P236DT10H10M&quot;), &quot;since-2011-user-friendly&quot;: duration(&quot;P7M23DT10H10M&quot;) }
3362{ &quot;since-2011&quot;: duration(&quot;P567DT10H10M&quot;), &quot;since-2011-user-friendly&quot;: duration(&quot;P1Y6M18DT10H10M&quot;) }
3363</pre></div></div></li>
3364</ul></div>
3365<div class="section">
3366<h3><a name="get-year-month-durationget-day-time-duration"></a>get-year-month-duration/get-day-time-duration</h3>
3367
3368<ul>
3369
3370<li>
3371<p>Syntax:</p>
3372
3373<div class="source">
3374<div class="source">
3375<pre>get-year-month-duration/get-day-time-duration(duration_expression)
3376</pre></div></div></li>
3377
3378<li>
3379<p>Extracts the correct <tt>duration</tt> subtype from <tt>duration_expression</tt>.</p></li>
3380
3381<li>Arguments:
3382
3383<ul>
3384
3385<li><tt>duration_expression</tt> : A <tt>duration</tt> value to be converted.</li>
3386 </ul></li>
3387
3388<li>Return Value:
3389
3390<ul>
3391
3392<li>A <tt>year-month-duration</tt> value or a <tt>day-time-duration</tt> value.</li>
3393 </ul></li>
3394
3395<li>
3396<p>Example:</p>
3397
3398<div class="source">
3399<div class="source">
3400<pre>let $i := get-year-month-duration(duration(&quot;P12M50DT10H&quot;))
3401return $i;
3402</pre></div></div></li>
3403</ul>
3404
3405<ul>
3406
3407<li>
3408<p>The expected result is:</p>
3409
3410<div class="source">
3411<div class="source">
3412<pre>year-month-duration(&quot;P1Y&quot;)
3413</pre></div></div></li>
3414</ul></div>
3415<div class="section">
3416<h3><a name="months-from-year-month-durationmilliseconds-from-day-time-duration"></a>months-from-year-month-duration/milliseconds-from-day-time-duration</h3>
3417
3418<ul>
3419
3420<li>
3421<p>Syntax:</p>
3422
3423<div class="source">
3424<div class="source">
3425<pre>months-from-year-month-duration/milliseconds-from-day-time-duration(duration_expression)
3426</pre></div></div></li>
3427
3428<li>
3429<p>Extracts the number of months or the number of milliseconds from the <tt>duration</tt> subtype.</p></li>
3430
3431<li>Arguments:
3432
3433<ul>
3434
3435<li><tt>duration_expression</tt> : A <tt>duration</tt> of the correct subtype.</li>
3436 </ul></li>
3437
3438<li>Return Value:
3439
3440<ul>
3441
3442<li>An <tt>int64</tt> representing the number or months/milliseconds.</li>
3443 </ul></li>
3444
3445<li>
3446<p>Example:</p>
3447
3448<div class="source">
3449<div class="source">
3450<pre>let $i := months-from-year-month-duration(get-year-month-duration(duration(&quot;P5Y7MT50M&quot;)))
3451return $i;
3452</pre></div></div></li>
3453</ul>
3454
3455<ul>
3456
3457<li>
3458<p>The expected result is:</p>
3459
3460<div class="source">
3461<div class="source">
3462<pre>67
3463</pre></div></div></li>
3464</ul></div>
3465<div class="section">
3466<h3><a name="duration-from-monthsduration-from-ms"></a>duration-from-months/duration-from-ms</h3>
3467
3468<ul>
3469
3470<li>
3471<p>Syntax:</p>
3472
3473<div class="source">
3474<div class="source">
3475<pre>duration-from-months/duration-from-ms(number_expression)
3476</pre></div></div></li>
3477
3478<li>
3479<p>Creates a <tt>duration</tt> from <tt>number_expression</tt>.</p></li>
3480
3481<li>Arguments:
3482
3483<ul>
3484
3485<li><tt>number_expression</tt> : An <tt>int64</tt> representing the number of months/milliseconds</li>
3486 </ul></li>
3487
3488<li>Return Value:
3489
3490<ul>
3491
3492<li>A <tt>duration</tt> containing <tt>number_expression</tt> value for months/milliseconds</li>
3493 </ul></li>
3494
3495<li>
3496<p>Example:</p>
3497
3498<div class="source">
3499<div class="source">
3500<pre>let $i := duration-from-months(8)
3501return $i;
3502</pre></div></div></li>
3503
3504<li>
3505<p>The expected result is:</p>
3506
3507<div class="source">
3508<div class="source">
3509<pre>duration(&quot;P8M&quot;)
3510</pre></div></div></li>
3511</ul></div>
3512<div class="section">
3513<h3><a name="duration-from-interval"></a>duration-from-interval</h3>
3514
3515<ul>
3516
3517<li>
3518<p>Syntax:</p>
3519
3520<div class="source">
3521<div class="source">
3522<pre>duration-from-interval(interval_expression)
3523</pre></div></div></li>
3524
3525<li>
3526<p>Creates a <tt>duration</tt> from <tt>interval_expression</tt>.</p></li>
3527
3528<li>Arguments:
3529
3530<ul>
3531
3532<li><tt>interval_expression</tt> : An <tt>interval</tt> value</li>
3533 </ul></li>
3534
3535<li>Return Value:
3536
3537<ul>
3538
3539<li>A <tt>duration</tt> repesenting the time in the <tt>interval_expression</tt></li>
3540 </ul></li>
3541
3542<li>
3543<p>Example:</p>
3544
3545<div class="source">
3546<div class="source">
3547<pre>let $itv1 := interval-from-date(&quot;2010-10-30&quot;, &quot;2010-12-21&quot;)
3548let $itv2 := interval-from-datetime(&quot;2012-06-26T01:01:01.111&quot;, &quot;2012-07-27T02:02:02.222&quot;)
3549let $itv3 := interval-from-time(&quot;12:32:38&quot;, &quot;20:29:20&quot;)
3550
3551return { &quot;dr1&quot; : duration-from-interval($itv1),
3552 &quot;dr2&quot; : duration-from-interval($itv2),
3553 &quot;dr3&quot; : duration-from-interval($itv3),
3554 &quot;dr4&quot; : duration-from-interval(null) }
3555</pre></div></div></li>
3556
3557<li>
3558<p>The expected result is:</p>
3559
3560<div class="source">
3561<div class="source">
3562<pre>{ &quot;dr1&quot;: day-time-duration(&quot;P52D&quot;),
3563 &quot;dr2&quot;: day-time-duration(&quot;P31DT1H1M1.111S&quot;),
3564 &quot;dr3&quot;: day-time-duration(&quot;PT7H56M42S&quot;),
3565 &quot;dr4&quot;: null }
3566</pre></div></div></li>
3567</ul></div>
3568<div class="section">
3569<h3><a name="current-date"></a>current-date</h3>
3570
3571<ul>
3572
3573<li>
3574<p>Syntax:</p>
3575
3576<div class="source">
3577<div class="source">
3578<pre>current-date()
3579</pre></div></div></li>
3580
3581<li>
3582<p>Gets the current date.</p></li>
3583
3584<li>Arguments: None</li>
3585
3586<li>Return Value:
3587
3588<ul>
3589
3590<li>A <tt>date</tt> value of the date when the function is called.</li>
3591 </ul></li>
3592</ul></div>
3593<div class="section">
3594<h3><a name="current-time"></a>current-time</h3>
3595
3596<ul>
3597
3598<li>
3599<p>Syntax:</p>
3600
3601<div class="source">
3602<div class="source">
3603<pre>current-time()
3604</pre></div></div></li>
3605
3606<li>
3607<p>Get the current time</p></li>
3608
3609<li>Arguments: None</li>
3610
3611<li>Return Value:
3612
3613<ul>
3614
3615<li>A <tt>time</tt> value of the time when the function is called.</li>
3616 </ul></li>
3617</ul></div>
3618<div class="section">
3619<h3><a name="current-datetime"></a>current-datetime</h3>
3620
3621<ul>
3622
3623<li>
3624<p>Syntax:</p>
3625
3626<div class="source">
3627<div class="source">
3628<pre>current-datetime()
3629</pre></div></div></li>
3630
3631<li>
3632<p>Get the current datetime</p></li>
3633
3634<li>Arguments: None</li>
3635
3636<li>Return Value:
3637
3638<ul>
3639
3640<li>A <tt>datetime</tt> value of the datetime when the function is called.</li>
3641 </ul></li>
3642
3643<li>
3644<p>Example:</p>
3645
3646<div class="source">
3647<div class="source">
3648<pre>{&quot;current-date&quot;: current-date(),
3649&quot;current-time&quot;: current-time(),
3650&quot;current-datetime&quot;: current-datetime()}
3651</pre></div></div></li>
3652</ul>
3653
3654<ul>
3655
3656<li>
3657<p>The expected result is:</p>
3658
3659<div class="source">
3660<div class="source">
3661<pre>{ &quot;current-date&quot;: date(&quot;2013-04-06&quot;),
3662&quot;current-time&quot;: time(&quot;00:48:44.093Z&quot;),
3663&quot;current-datetime&quot;: datetime(&quot;2013-04-06T00:48:44.093Z&quot;) }
3664</pre></div></div></li>
3665</ul></div>
3666<div class="section">
3667<h3><a name="get-date-from-datetime"></a>get-date-from-datetime</h3>
3668
3669<ul>
3670
3671<li>
3672<p>Syntax:</p>
3673
3674<div class="source">
3675<div class="source">
3676<pre>get-date-from-datetime(datetime_expression)
3677</pre></div></div></li>
3678
3679<li>
3680<p>Gets the date value from the given datetime value <tt>datetime_expression</tt>.</p></li>
3681
3682<li>Arguments:
3683
3684<ul>
3685
3686<li><tt>datetime_expression</tt>: A <tt>datetime</tt> value to be extracted from.</li>
3687 </ul></li>
3688
3689<li>Return Value:
3690
3691<ul>
3692
3693<li>A <tt>date</tt> value from the datetime.</li>
3694 </ul></li>
3695</ul></div>
3696<div class="section">
3697<h3><a name="get-time-from-datetime"></a>get-time-from-datetime</h3>
3698
3699<ul>
3700
3701<li>
3702<p>Syntax:</p>
3703
3704<div class="source">
3705<div class="source">
3706<pre>get-time-from-datetime(datetime_expression)
3707</pre></div></div></li>
3708
3709<li>
3710<p>Get the time value from the given datetime value <tt>datetime_expression</tt></p></li>
3711
3712<li>Arguments:
3713
3714<ul>
3715
3716<li><tt>datetime_expression</tt>: A <tt>datetime</tt> value to be extracted from</li>
3717 </ul></li>
3718
3719<li>Return Value:
3720
3721<ul>
3722
3723<li>A <tt>time</tt> value from the datetime.</li>
3724 </ul></li>
3725
3726<li>
3727<p>Example:</p>
3728
3729<div class="source">
3730<div class="source">
3731<pre>use dataverse TinySocial;
3732
3733for $i in dataset('TweetMessages')
3734where $i.send-time &gt; datetime(&quot;2011-01-01T00:00:00&quot;)
3735return {&quot;send-date&quot;: get-date-from-datetime($i.send-time), &quot;send-time&quot;: get-time-from-datetime($i.send-time)}
3736</pre></div></div></li>
3737</ul>
3738
3739<ul>
3740
3741<li>
3742<p>The expected result is:</p>
3743
3744<div class="source">
3745<div class="source">
3746<pre>{ &quot;send-date&quot;: date(&quot;2011-12-26&quot;), &quot;send-time&quot;: time(&quot;10:10:00.000Z&quot;) }
3747{ &quot;send-date&quot;: date(&quot;2011-08-25&quot;), &quot;send-time&quot;: time(&quot;10:10:00.000Z&quot;) }
3748{ &quot;send-date&quot;: date(&quot;2012-07-21&quot;), &quot;send-time&quot;: time(&quot;10:10:00.000Z&quot;) }
3749</pre></div></div></li>
3750</ul></div>
3751<div class="section">
3752<h3><a name="day-of-week"></a>day-of-week</h3>
3753
3754<ul>
3755
3756<li>
3757<p>Syntax:</p>
3758
3759<div class="source">
3760<div class="source">
3761<pre>day-of-week(date_expression)
3762</pre></div></div></li>
3763
3764<li>
3765<p>Finds the day of the week for a given date (1-7)</p></li>
3766
3767<li>Arguments:
3768
3769<ul>
3770
3771<li><tt>date_expression</tt>: A <tt>date</tt> value (Can also be a <tt>datetime</tt>)</li>
3772 </ul></li>
3773
3774<li>Return Value:
3775
3776<ul>
3777
3778<li>An <tt>int8</tt> representing the day of the week (1-7)</li>
3779 </ul></li>
3780
3781<li>
3782<p>Example:</p>
3783
3784<div class="source">
3785<div class="source">
3786<pre>let $i := day-of-week( datetime(&quot;2012-12-30T12:12:12.039Z&quot;))
3787return $i;
3788</pre></div></div></li>
3789</ul>
3790
3791<ul>
3792
3793<li>
3794<p>The expected result is:</p>
3795
3796<div class="source">
3797<div class="source">
3798<pre>7
3799</pre></div></div></li>
3800</ul></div>
3801<div class="section">
3802<h3><a name="date-from-unix-time-in-days"></a>date-from-unix-time-in-days</h3>
3803
3804<ul>
3805
3806<li>
3807<p>Syntax:</p>
3808
3809<div class="source">
3810<div class="source">
3811<pre>date-from-unix-time-in-days(numeric_expression)
3812</pre></div></div></li>
3813
3814<li>
3815<p>Gets a date representing the time after <tt>numeric_expression</tt> days since 1970-01-01.</p></li>
3816
3817<li>Arguments:
3818
3819<ul>
3820
3821<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>
3822 </ul></li>
3823
3824<li>Return Value:
3825
3826<ul>
3827
3828<li>A <tt>date</tt> value as the time after <tt>numeric_expression</tt> days since 1970-01-01.</li>
3829 </ul></li>
3830</ul></div>
3831<div class="section">
3832<h3><a name="datetime-from-unix-time-in-ms"></a>datetime-from-unix-time-in-ms</h3>
3833
3834<ul>
3835
3836<li>
3837<p>Syntax:</p>
3838
3839<div class="source">
3840<div class="source">
3841<pre>datetime-from-unix-time-in-ms(numeric_expression)
3842</pre></div></div></li>
3843
3844<li>
3845<p>Gets a datetime representing the time after <tt>numeric_expression</tt> milliseconds since 1970-01-01T00:00:00Z.</p></li>
3846
3847<li>Arguments:
3848
3849<ul>
3850
3851<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>
3852 </ul></li>
3853
3854<li>Return Value:
3855
3856<ul>
3857
3858<li>A <tt>datetime</tt> value as the time after <tt>numeric_expression</tt> milliseconds since 1970-01-01T00:00:00Z.</li>
3859 </ul></li>
3860</ul></div>
3861<div class="section">
3862<h3><a name="datetime-from-unix-time-in-secs"></a>datetime-from-unix-time-in-secs</h3>
3863
3864<ul>
3865
3866<li>
3867<p>Syntax:</p>
3868
3869<div class="source">
3870<div class="source">
3871<pre>datetime-from-unix-time-in-secs(numeric_expression)
3872</pre></div></div></li>
3873
3874<li>
3875<p>Gets a datetime representing the time after <tt>numeric_expression</tt> seconds since 1970-01-01T00:00:00Z.</p></li>
3876
3877<li>Arguments:
3878
3879<ul>
3880
3881<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>
3882 </ul></li>
3883
3884<li>Return Value:
3885
3886<ul>
3887
3888<li>A <tt>datetime</tt> value as the time after <tt>numeric_expression</tt> seconds since 1970-01-01T00:00:00Z.</li>
3889 </ul></li>
3890</ul></div>
3891<div class="section">
3892<h3><a name="datetime-from-date-time"></a>datetime-from-date-time</h3>
3893
3894<ul>
3895
3896<li>Syntax:</li>
3897</ul>
3898<p>datetime-from-date-time(date_expression,time_expression)</p>
3899
3900<ul>
3901
3902<li>Gets a datetime representing the combination of <tt>date_expression</tt> and <tt>time_expression</tt>
3903
3904<ul>
3905
3906<li>Arguments:</li>
3907
3908<li><tt>date_expression</tt>: A <tt>date</tt> value</li>
3909
3910<li><tt>time_expression</tt> A <tt>time</tt> value</li>
3911 </ul></li>
3912
3913<li>Return Value:
3914
3915<ul>
3916
3917<li>A <tt>datetime</tt> value by combining <tt>date_expression</tt> and <tt>time_expression</tt></li>
3918 </ul></li>
3919</ul></div>
3920<div class="section">
3921<h3><a name="time-from-unix-time-in-ms"></a>time-from-unix-time-in-ms</h3>
3922
3923<ul>
3924
3925<li>
3926<p>Syntax:</p>
3927
3928<div class="source">
3929<div class="source">
3930<pre>time-from-unix-time-in-ms(numeric_expression)
3931</pre></div></div></li>
3932
3933<li>
3934<p>Gets a time representing the time after <tt>numeric_expression</tt> milliseconds since 00:00:00.000Z.</p></li>
3935
3936<li>Arguments:
3937
3938<ul>
3939
3940<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>
3941 </ul></li>
3942
3943<li>Return Value:
3944
3945<ul>
3946
3947<li>A <tt>time</tt> value as the time after <tt>numeric_expression</tt> milliseconds since 00:00:00.000Z.</li>
3948 </ul></li>
3949
3950<li>
3951<p>Example:</p>
3952
3953<div class="source">
3954<div class="source">
3955<pre>use dataverse TinySocial;
3956
3957let $d := date-from-unix-time-in-days(15800)
3958let $dt := datetime-from-unix-time-in-ms(1365139700000)
3959let $t := time-from-unix-time-in-ms(3748)
3960return {&quot;date&quot;: $d, &quot;datetime&quot;: $dt, &quot;time&quot;: $t}
3961</pre></div></div></li>
3962</ul>
3963
3964<ul>
3965
3966<li>
3967<p>The expected result is:</p>
3968
3969<div class="source">
3970<div class="source">
3971<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;) }
3972</pre></div></div></li>
3973</ul></div>
3974<div class="section">
3975<h3><a name="parse-dateparse-timeparse-datetime"></a>parse-date/parse-time/parse-datetime</h3>
3976
3977<ul>
3978
3979<li>Syntax:</li>
3980</ul>
3981<p>parse-date/parse-time/parse-datetime(date_expression,formatting_expression)</p>
3982
3983<ul>
3984
3985<li>Creates a <tt>date/time/date-time</tt> value by treating <tt>date_expression</tt> with formatting <tt>formatting_expression</tt></li>
3986
3987<li>Arguments:
3988
3989<ul>
3990
3991<li><tt>date_expression</tt>: A <tt>string</tt> value representing the <tt>date/time/datetime</tt>.</li>
3992
3993<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>
3994
3995<li><tt>h</tt> hours</li>
3996
3997<li><tt>m</tt> minutes</li>
3998
3999<li><tt>s</tt> seconds</li>
4000
4001<li><tt>n</tt> milliseconds</li>
4002
4003<li><tt>a</tt> am/pm</li>
4004
4005<li><tt>z</tt> timezone</li>
4006
4007<li><tt>Y</tt> year</li>
4008
4009<li><tt>M</tt> month</li>
4010
4011<li><tt>D</tt> day</li>
4012
4013<li><tt>W</tt> weekday</li>
4014
4015<li><tt>-</tt>, <tt>'</tt>, <tt>/</tt>, <tt>.</tt>, <tt>,</tt>, <tt>T</tt> seperators for both time and date</li>
4016 </ul></li>
4017
4018<li>Return Value:
4019
4020<ul>
4021
4022<li>A <tt>date/time/date-time</tt> value corresponding to <tt>date_expression</tt></li>
4023 </ul></li>
4024
4025<li>
4026<p>Example:</p>
4027
4028<div class="source">
4029<div class="source">
4030<pre>let $i := parse-time(&quot;30:30&quot;,&quot;m:s&quot;)
4031return $i;
4032</pre></div></div></li>
4033
4034<li>
4035<p>The expected result is:</p>
4036
4037<div class="source">
4038<div class="source">
4039<pre>time(&quot;00:30:30.000Z&quot;)
4040</pre></div></div></li>
4041</ul></div>
4042<div class="section">
4043<h3><a name="print-dateprint-timeprint-datetime"></a>print-date/print-time/print-datetime</h3>
4044
4045<ul>
4046
4047<li>Syntax:</li>
4048</ul>
4049<p>print-date/print-time/print-datetime(date_expression,formatting_expression)</p>
4050
4051<ul>
4052
4053<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>
4054
4055<li>Arguments:
4056
4057<ul>
4058
4059<li><tt>date_expression</tt>: A <tt>date/time/datetime</tt> value.</li>
4060
4061<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>
4062
4063<li><tt>h</tt> hours</li>
4064
4065<li><tt>m</tt> minutes</li>
4066
4067<li><tt>s</tt> seconds</li>
4068
4069<li><tt>n</tt> milliseconds</li>
4070
4071<li><tt>a</tt> am/pm</li>
4072
4073<li><tt>z</tt> timezone</li>
4074
4075<li><tt>Y</tt> year</li>
4076
4077<li><tt>M</tt> month</li>
4078
4079<li><tt>D</tt> day</li>
4080
4081<li><tt>W</tt> weekday</li>
4082
4083<li><tt>-</tt>, <tt>'</tt>, <tt>/</tt>, <tt>.</tt>, <tt>,</tt>, <tt>T</tt> seperators for both time and date</li>
4084 </ul></li>
4085
4086<li>Return Value:
4087
4088<ul>
4089
4090<li>A <tt>string</tt> value corresponding to <tt>date_expression</tt></li>
4091 </ul></li>
4092
4093<li>
4094<p>Example:</p>
4095
4096<div class="source">
4097<div class="source">
4098<pre>let $i := print-time(time(&quot;00:30:30.000Z&quot;),&quot;m:s&quot;)
4099return $i;
4100</pre></div></div></li>
4101
4102<li>
4103<p>The expected result is:</p>
4104
4105<div class="source">
4106<div class="source">
4107<pre>&quot;30:30&quot;
4108</pre></div></div></li>
4109</ul></div>
4110<div class="section">
4111<h3><a name="get-interval-start_get-interval-end"></a>get-interval-start, get-interval-end</h3>
4112
4113<ul>
4114
4115<li>
4116<p>Syntax:</p>
4117
4118<div class="source">
4119<div class="source">
4120<pre>get-interval-start/get-interval-end(interval)
4121</pre></div></div></li>
4122
4123<li>
4124<p>Gets the start/end of the given interval.</p></li>
4125
4126<li>Arguments:
4127
4128<ul>
4129
4130<li><tt>interval</tt>: the interval to be accessed.</li>
4131 </ul></li>
4132
4133<li>Return Value:
4134
4135<ul>
4136
4137<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>
4138 </ul></li>
4139
4140<li>
4141<p>Example:</p>
4142
4143<div class="source">
4144<div class="source">
4145<pre>let $itv := interval-start-from-date(&quot;1984-01-01&quot;, &quot;P1Y&quot;)
4146return {&quot;start&quot;: get-interval-start($itv), &quot;end&quot;: get-interval-end($itv)}
4147</pre></div></div></li>
4148</ul>
4149
4150<ul>
4151
4152<li>
4153<p>The expected result is:</p>
4154
4155<div class="source">
4156<div class="source">
4157<pre>{ &quot;start&quot;: date(&quot;1984-01-01&quot;), &quot;end&quot;: date(&quot;1985-01-01&quot;) }
4158</pre></div></div></li>
4159</ul></div>
4160<div class="section">
4161<h3><a name="get-interval-start-dateget-interval-start-datetimeget-interval-start-time_get-interval-end-dateget-interval-end-datetimeget-interval-end-time"></a>get-interval-start-date/get-interval-start-datetimeget-interval-start-time, get-interval-end-date/get-interval-end-datetime/get-interval-end-time</h3>
4162
4163<ul>
4164
4165<li>
4166<p>Syntax:</p>
4167
4168<div class="source">
4169<div class="source">
4170<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)
4171</pre></div></div></li>
4172
4173<li>
4174<p>Gets the start/end of the given interval for the specific date/datetime/time type.</p></li>
4175
4176<li>Arguments:
4177
4178<ul>
4179
4180<li><tt>interval</tt>: the interval to be accessed.</li>
4181 </ul></li>
4182
4183<li>Return Value:
4184
4185<ul>
4186
4187<li>A <tt>time</tt>, <tt>date</tt>, or <tt>datetime</tt> (depending on the function) representing the starting or ending time.</li>
4188 </ul></li>
4189
4190<li>
4191<p>Example:</p>
4192
4193<div class="source">
4194<div class="source">
4195<pre>let $itv1 := interval-start-from-date(&quot;1984-01-01&quot;, &quot;P1Y&quot;)
4196let $itv2 := interval-start-from-datetime(&quot;1984-01-01T08:30:00.000&quot;, &quot;P1Y1H&quot;)
4197let $itv3 := interval-start-from-time(&quot;08:30:00.000&quot;, &quot;P1H&quot;)
4198return {&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)}
4199</pre></div></div></li>
4200</ul>
4201
4202<ul>
4203
4204<li>
4205<p>The expected result is:</p>
4206
4207<div class="source">
4208<div class="source">
4209<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;) }
4210</pre></div></div></li>
4211</ul></div>
4212<div class="section">
4213<h3><a name="get-overlapping-interval"></a>get-overlapping-interval</h3>
4214
4215<ul>
4216
4217<li>
4218<p>Syntax:</p>
4219
4220<div class="source">
4221<div class="source">
4222<pre>get-overlapping-interval(interval_expression_1, interval_expression_2)
4223</pre></div></div></li>
4224
4225<li>
4226<p>Gets the start/end of the given interval for the specific date/datetime/time type.</p></li>
4227
4228<li>Arguments:
4229
4230<ul>
4231
4232<li><tt>interval_expression_1</tt>: an <tt>interval</tt> value</li>
4233
4234<li><tt>interval_expression_2</tt>: an <tt>interval</tt> value</li>
4235 </ul></li>
4236
4237<li>Return Value:
4238
4239<ul>
4240
4241<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>
4242 </ul></li>
4243
4244<li>
4245<p>Example:</p>
4246
4247<div class="source">
4248<div class="source">
4249<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;))),
4250 &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;))),
4251 &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;))),
4252 &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;))),
4253 &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;))),
4254 &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;))) }
4255</pre></div></div></li>
4256
4257<li>
4258<p>The expected result is:</p>
4259
4260<div class="source">
4261<div class="source">
4262<pre>{ &quot;overlap1&quot;: interval-time(&quot;12:23:39.000Z, 18:27:19.000Z&quot;),
4263 &quot;overlap2&quot;: null,
4264 &quot;overlap3&quot;: null,
4265 &quot;overlap4&quot;: interval-date(&quot;2013-01-01, 2014-01-01&quot;),
4266 &quot;overlap5&quot;: interval-datetime(&quot;1989-03-04T12:23:39.000Z, 2000-10-30T18:27:19.000Z&quot;),
4267 &quot;overlap6&quot;: null }
4268</pre></div></div></li>
4269</ul></div>
4270<div class="section">
4271<h3><a name="interval-beforeinterval-afterinterval-meetsinterval-met-byinterval-overlapsinterval-overlapped-byinterval-overlappinginterval-startsinterval-started-byinterval-coversinterval-covered-byinterval-endsinterval-ended-by"></a>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</h3>
4272<p>See the <a href="allens.html">Allen&#x2019;s Relations</a>.</p></div>
4273<div class="section">
4274<h3><a name="interval-bin"></a>interval-bin</h3>
4275
4276<ul>
4277
4278<li>
4279<p>Syntax:</p>
4280
4281<div class="source">
4282<div class="source">
4283<pre>interval-bin(time-to-bin, time-bin-anchor, duration-bin-size)
4284</pre></div></div></li>
4285
4286<li>
4287<p>Return the <tt>interval</tt> value representing the bin containing the <tt>time-to-bin</tt> value.</p></li>
4288
4289<li>Arguments:
4290
4291<ul>
4292
4293<li><tt>time-to-bin</tt>: a date/time/datetime value representing the time to be binned.</li>
4294
4295<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>
4296
4297<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:
4298
4299<ul>
4300
4301<li>datetime +|- year-month-duration</li>
4302
4303<li>datetime +|- day-time-duration</li>
4304
4305<li>date +|- year-month-duration</li>
4306
4307<li>date +|- day-time-duration</li>
4308
4309<li>time +|- day-time-duration</li>
4310 </ul></li>
4311 </ul></li>
4312
4313<li>Return Value:
4314
4315<ul>
4316
4317<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>
4318 </ul></li>
4319
4320<li>
4321<p>Example:</p>
4322
4323<div class="source">
4324<div class="source">
4325<pre>let $c1 := date(&quot;2010-10-30&quot;)
4326let $c2 := datetime(&quot;-1987-11-19T23:49:23.938&quot;)
4327let $c3 := time(&quot;12:23:34.930+07:00&quot;)
4328
4329return { &quot;bin1&quot;: interval-bin($c1, date(&quot;1990-01-01&quot;), year-month-duration(&quot;P1Y&quot;)),
4330 &quot;bin2&quot;: interval-bin($c2, datetime(&quot;1990-01-01T00:00:00.000Z&quot;), year-month-duration(&quot;P6M&quot;)),
4331 &quot;bin3&quot;: interval-bin($c3, time(&quot;00:00:00&quot;), day-time-duration(&quot;PD1M&quot;)),
4332 &quot;bin4&quot;: interval-bin($c2, datetime(&quot;2013-01-01T00:00:00.000&quot;), day-time-duration(&quot;PT24H&quot;))
4333</pre></div></div> }</li>
4334
4335<li>
4336<p>The expected result is:</p>
4337
4338<div class="source">
4339<div class="source">
4340<pre>{ &quot;bin1&quot;: interval-date(&quot;2010-01-01, 2011-01-01&quot;),
4341 &quot;bin2&quot;: interval-datetime(&quot;-1987-07-01T00:00:00.000Z, -1986-01-01T00:00:00.000Z&quot;),
4342 &quot;bin3&quot;: interval-time(&quot;05:23:00.000Z, 05:24:00.000Z&quot;),
4343 &quot;bin4&quot;: interval-datetime(&quot;-1987-11-19T00:00:00.000Z, -1987-11-20T00:00:00.000Z&quot;)}
4344</pre></div></div></li>
4345</ul></div>
4346<div class="section">
4347<h3><a name="interval-from-date"></a>interval-from-date</h3>
4348
4349<ul>
4350
4351<li>
4352<p>Syntax:</p>
4353
4354<div class="source">
4355<div class="source">
4356<pre>interval-from-date(string_expression1, string_expression2)
4357</pre></div></div></li>
4358
4359<li>
4360<p>Constructor function for the <tt>interval</tt> type by parsing two date strings.</p></li>
4361
4362<li>Arguments:
4363
4364<ul>
4365
4366<li><tt>string_expression1</tt> : The <tt>string</tt> value representing the starting date.</li>
4367
4368<li><tt>string_expression2</tt> : The <tt>string</tt> value representing the ending date.</li>
4369 </ul></li>
4370
4371<li>Return Value:
4372
4373<ul>
4374
4375<li>An <tt>interval</tt> value between the two dates.</li>
4376 </ul></li>
4377
4378<li>
4379<p>Example:</p>
4380
4381<div class="source">
4382<div class="source">
4383<pre>{&quot;date-interval&quot;: interval-from-date(&quot;2012-01-01&quot;, &quot;2013-04-01&quot;)}
4384</pre></div></div></li>
4385</ul>
4386
4387<ul>
4388
4389<li>
4390<p>The expected result is:</p>
4391
4392<div class="source">
4393<div class="source">
4394<pre>{ &quot;date-interval&quot;: interval-date(&quot;2012-01-01, 2013-04-01&quot;) }
4395</pre></div></div></li>
4396</ul></div>
4397<div class="section">
4398<h3><a name="interval-from-time"></a>interval-from-time</h3>
4399
4400<ul>
4401
4402<li>
4403<p>Syntax:</p>
4404
4405<div class="source">
4406<div class="source">
4407<pre>interval-from-time(string_expression1, string_expression2)
4408</pre></div></div></li>
4409
4410<li>
4411<p>Constructor function for the <tt>interval</tt> type by parsing two time strings.</p></li>
4412
4413<li>Arguments:
4414
4415<ul>
4416
4417<li><tt>string_expression1</tt> : The <tt>string</tt> value representing the starting time.</li>
4418
4419<li><tt>string_expression2</tt> : The <tt>string</tt> value representing the ending time.</li>
4420 </ul></li>
4421
4422<li>Return Value:
4423
4424<ul>
4425
4426<li>An <tt>interval</tt> value between the two times.</li>
4427 </ul></li>
4428
4429<li>
4430<p>Example:</p>
4431
4432<div class="source">
4433<div class="source">
4434<pre>{&quot;time-interval&quot;: interval-from-time(&quot;12:23:34.456Z&quot;, &quot;233445567+0800&quot;)}
4435</pre></div></div></li>
4436</ul>
4437
4438<ul>
4439
4440<li>
4441<p>The expected result is:</p>
4442
4443<div class="source">
4444<div class="source">
4445<pre>{ &quot;time-interval&quot;: interval-time(&quot;12:23:34.456Z, 15:34:45.567Z&quot;) }
4446</pre></div></div></li>
4447</ul></div>
4448<div class="section">
4449<h3><a name="interval-from-datetime"></a>interval-from-datetime</h3>
4450
4451<ul>
4452
4453<li>
4454<p>Syntax:</p>
4455
4456<div class="source">
4457<div class="source">
4458<pre>interval-from-datetime(string_expression1, string_expression2)
4459</pre></div></div></li>
4460
4461<li>
4462<p>Constructor function for <tt>interval</tt> type by parsing two datetime strings.</p></li>
4463
4464<li>Arguments:
4465
4466<ul>
4467
4468<li><tt>string_expression1</tt> : The <tt>string</tt> value representing the starting datetime.</li>
4469
4470<li><tt>string_expression2</tt> : The <tt>string</tt> value representing the ending datetime.</li>
4471 </ul></li>
4472
4473<li>Return Value:
4474
4475<ul>
4476
4477<li>An <tt>interval</tt> value between the two datetimes.</li>
4478 </ul></li>
4479
4480<li>
4481<p>Example:</p>
4482
4483<div class="source">
4484<div class="source">
4485<pre>{&quot;datetime-interval&quot;: interval-from-datetime(&quot;2012-01-01T12:23:34.456+08:00&quot;, &quot;20130401T153445567Z&quot;)}
4486</pre></div></div></li>
4487</ul>
4488
4489<ul>
4490
4491<li>
4492<p>The expected result is:</p>
4493
4494<div class="source">
4495<div class="source">
4496<pre>{ &quot;datetime-interval&quot;: interval-datetime(&quot;2012-01-01T04:23:34.456Z, 2013-04-01T15:34:45.567Z&quot;) }
4497</pre></div></div></li>
4498</ul></div>
4499<div class="section">
4500<h3><a name="interval-start-from-datetimedatetime"></a>interval-start-from-date/time/datetime</h3>
4501
4502<ul>
4503
4504<li>
4505<p>Syntax:</p>
4506
4507<div class="source">
4508<div class="source">
4509<pre>interval-start-from-date/time/datetime(date/time/datetime, duration)
4510</pre></div></div></li>
4511
4512<li>
4513<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>
4514
4515<li>Arguments:
4516
4517<ul>
4518
4519<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>
4520
4521<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>
4522 </ul></li>
4523
4524<li>Return Value:
4525
4526<ul>
4527
4528<li>An <tt>interval</tt> value representing the interval starting from the given time point with the length of duration.</li>
4529 </ul></li>
4530
4531<li>
4532<p>Example:</p>
4533
4534<div class="source">
4535<div class="source">
4536<pre>let $itv1 := interval-start-from-date(&quot;1984-01-01&quot;, &quot;P1Y&quot;)
4537let $itv2 := interval-start-from-time(time(&quot;02:23:28.394&quot;), &quot;PT3H24M&quot;)
4538let $itv3 := interval-start-from-datetime(&quot;1999-09-09T09:09:09.999&quot;, duration(&quot;P2M30D&quot;))
4539return {&quot;interval1&quot;: $itv1, &quot;interval2&quot;: $itv2, &quot;interval3&quot;: $itv3}
4540</pre></div></div></li>
4541
4542<li>
4543<p>The expectecd result is:</p>
4544
4545<div class="source">
4546<div class="source">
4547<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;) }
4548</pre></div></div></li>
4549</ul></div>
4550<div class="section">
4551<h3><a name="overlap-bins"></a>overlap-bins</h3>
4552
4553<ul>
4554
4555<li>
4556<p>Return Value:</p>
4557
4558<ul>
4559
4560<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>
4561 </ul></li>
4562
4563<li>
4564<p>Syntax:</p>
4565
4566<div class="source">
4567<div class="source">
4568<pre>overlap-bins(interval_expression, time-bin-anchor, duration-bin-size)
4569</pre></div></div></li>
4570
4571<li>
4572<p>Returns an ordered list of <tt>interval</tt> values representing each bin that is overlapping the <tt>interval_expression</tt>.</p></li>
4573
4574<li>Arguments:
4575
4576<ul>
4577
4578<li><tt>interval_expression</tt>: an <tt>interval</tt> value</li>
4579
4580<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>
4581
4582<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:
4583
4584<ul>
4585
4586<li>datetime +|- year-month-duration</li>
4587
4588<li>datetime +|- day-time-duration</li>
4589
4590<li>date +|- year-month-duration</li>
4591
4592<li>date +|- day-time-duration</li>
4593
4594<li>time +|- day-time-duration</li>
4595 </ul></li>
4596 </ul></li>
4597
4598<li>Return Value:
4599
4600<ul>
4601
4602<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>
4603 </ul></li>
4604
4605<li>
4606<p>Example:</p>
4607
4608<div class="source">
4609<div class="source">
4610<pre>let $itv1 := interval-from-time(time(&quot;17:23:37&quot;), time(&quot;18:30:21&quot;))
4611let $itv2 := interval-from-date(date(&quot;1984-03-17&quot;), date(&quot;2013-08-22&quot;))
4612let $itv3 := interval-from-datetime(datetime(&quot;1800-01-01T23:59:48.938&quot;), datetime(&quot;2015-07-26T13:28:30.218&quot;))
4613return { &quot;timebins&quot;: overlap-bins($itv1, time(&quot;00:00:00&quot;), day-time-duration(&quot;PT30M&quot;)),
4614 &quot;datebins&quot;: overlap-bins($itv2, date(&quot;1990-01-01&quot;), year-month-duration(&quot;P20Y&quot;)),
4615 &quot;datetimebins&quot;: overlap-bins($itv3, datetime(&quot;1900-01-01T00:00:00.000&quot;), year-month-duration(&quot;P100Y&quot;)) }
4616</pre></div></div></li>
4617
4618<li>
4619<p>The expected result is:</p>
4620
4621<div class="source">
4622<div class="source">
4623<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;) ],
4624 &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;) ],
4625 &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;) ] }
4626</pre></div></div></li>
4627</ul></div></div>
4628<div class="section">
4629<h2><a name="Record_Functions_Back_to_TOC"></a><a name="RecordFunctions" id="RecordFunctions">Record Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
4630<div class="section">
4631<h3><a name="get-record-fields"></a>get-record-fields</h3>
4632
4633<ul>
4634
4635<li>
4636<p>Syntax:</p>
4637
4638<div class="source">
4639<div class="source">
4640<pre>get-record-fields(record_expression)
4641</pre></div></div></li>
4642
4643<li>
4644<p>Access the record field names, type and open status for a given record.</p></li>
4645
4646<li>Arguments:
4647
4648<ul>
4649
4650<li><tt>record_expression</tt> : a record value.</li>
4651 </ul></li>
4652
4653<li>Return Value:
4654
4655<ul>
4656
4657<li>An order list of <tt>record</tt> values that include the field-name <tt>string</tt>, field-type <tt>string</tt>, is-open <tt>boolean</tt> and optional nested <tt>orderedList</tt> for the values of a nested record.</li>
4658 </ul></li>
4659
4660<li>
4661<p>Example:</p>
4662
4663<div class="source">
4664<div class="source">
4665<pre>let $r1 := {&quot;id&quot;: 1,
4666 &quot;project&quot;: &quot;AsterixDB&quot;,
4667 &quot;address&quot;: {&quot;city&quot;: &quot;Irvine&quot;, &quot;state&quot;: &quot;CA&quot;},
4668 &quot;related&quot;: [&quot;Hivestrix&quot;, &quot;Preglix&quot;, &quot;Apache VXQuery&quot;] }
4669return get-record-fields($r1)
4670</pre></div></div></li>
4671
4672<li>
4673<p>The expected result is:</p>
4674
4675<div class="source">
4676<div class="source">
4677<pre>[ { &quot;field-name&quot;: &quot;id&quot;, &quot;field-type&quot;: &quot;INT64&quot;, &quot;is-open&quot;: false },
4678 { &quot;field-name&quot;: &quot;project&quot;, &quot;field-type&quot;: &quot;STRING&quot;, &quot;is-open&quot;: false },
4679 { &quot;field-name&quot;: &quot;address&quot;, &quot;field-type&quot;: &quot;RECORD&quot;, &quot;is-open&quot;: false, &quot;nested&quot;: [
4680 { &quot;field-name&quot;: &quot;city&quot;, &quot;field-type&quot;: &quot;STRING&quot;, &quot;is-open&quot;: false },
4681 { &quot;field-name&quot;: &quot;state&quot;, &quot;field-type&quot;: &quot;STRING&quot;, &quot;is-open&quot;: false } ] },
4682 { &quot;field-name&quot;: &quot;related&quot;, &quot;field-type&quot;: &quot;ORDEREDLIST&quot;, &quot;is-open&quot;: false, &quot;list&quot;: [
4683 { &quot;field-type&quot;: &quot;STRING&quot; },
4684 { &quot;field-type&quot;: &quot;STRING&quot; },
4685 { &quot;field-type&quot;: &quot;STRING&quot; } ] } ]
4686</pre></div></div></li>
4687</ul>
4688<p>]</p></div>
4689<div class="section">
4690<h3><a name="get-record-field-value"></a>get-record-field-value</h3>
4691
4692<ul>
4693
4694<li>
4695<p>Syntax:</p>
4696
4697<div class="source">
4698<div class="source">
4699<pre>get-record-field-value(record_expression, string_expression)
4700</pre></div></div></li>
4701
4702<li>
4703<p>Access the field name given in the <tt>string_expression</tt> from the <tt>record_expression</tt>.</p></li>
4704
4705<li>Arguments:
4706
4707<ul>
4708
4709<li><tt>record_expression</tt> : A <tt>record</tt> value.</li>
4710
4711<li><tt>string_expression</tt> : A <tt>string</tt> representing the top level field name.</li>
4712 </ul></li>
4713
4714<li>Return Value:
4715
4716<ul>
4717
4718<li>An <tt>any</tt> value saved in the designated field of the record.</li>
4719 </ul></li>
4720
4721<li>
4722<p>Example:</p>
4723
4724<div class="source">
4725<div class="source">
4726<pre>let $r1 := {&quot;id&quot;: 1,
4727 &quot;project&quot;: &quot;AsterixDB&quot;,
4728 &quot;address&quot;: {&quot;city&quot;: &quot;Irvine&quot;, &quot;state&quot;: &quot;CA&quot;},
4729 &quot;related&quot;: [&quot;Hivestrix&quot;, &quot;Preglix&quot;, &quot;Apache VXQuery&quot;] }
4730return get-record-field-value($r1, &quot;project&quot;)
4731</pre></div></div></li>
4732
4733<li>
4734<p>The expected result is:</p>
4735
4736<div class="source">
4737<div class="source">
4738<pre>&quot;AsterixDB&quot;
4739</pre></div></div></li>
4740</ul></div></div>
4741<div class="section">
4742<h2><a name="Other_Functions_Back_to_TOC"></a><a name="OtherFunctions" id="OtherFunctions">Other Functions</a> <font size="4"><a href="#toc">[Back to TOC]</a></font></h2>
4743<div class="section">
4744<h3><a name="create-uuid"></a>create-uuid</h3>
4745
4746<ul>
4747
4748<li>
4749<p>Syntax:</p>
4750
4751<div class="source">
4752<div class="source">
4753<pre>create-uuid()
4754</pre></div></div></li>
4755
4756<li>
4757<p>Generates a <tt>uuid</tt>.</p></li>
4758
4759<li>Arguments:
4760
4761<ul>
4762
4763<li>none</li>
4764 </ul></li>
4765
4766<li>Return Value:
4767
4768<ul>
4769
4770<li>A generated <tt>uuid</tt>.</li>
4771 </ul></li>
4772</ul></div>
4773<div class="section">
4774<h3><a name="is-null"></a>is-null</h3>
4775
4776<ul>
4777
4778<li>
4779<p>Syntax:</p>
4780
4781<div class="source">
4782<div class="source">
4783<pre>is-null(var)
4784</pre></div></div></li>
4785
4786<li>
4787<p>Checks whether the given variable is a <tt>null</tt> value.</p></li>
4788
4789<li>Arguments:
4790
4791<ul>
4792
4793<li><tt>var</tt> : A variable (any type is allowed).</li>
4794 </ul></li>
4795
4796<li>Return Value:
4797
4798<ul>
4799
4800<li>A <tt>boolean</tt> on whether the variable is a <tt>null</tt> or not.</li>
4801 </ul></li>
4802
4803<li>
4804<p>Example:</p>
4805
4806<div class="source">
4807<div class="source">
4808<pre>for $m in ['hello', 'world', null]
4809where not(is-null($m))
4810return $m
4811</pre></div></div></li>
4812</ul>
4813
4814<ul>
4815
4816<li>
4817<p>The expected result is:</p>
4818
4819<div class="source">
4820<div class="source">
4821<pre>&quot;hello&quot;
4822&quot;world&quot;
4823</pre></div></div></li>
4824</ul></div>
4825<div class="section">
4826<h3><a name="is-system-null"></a>is-system-null</h3>
4827
4828<ul>
4829
4830<li>
4831<p>Syntax:</p>
4832
4833<div class="source">
4834<div class="source">
4835<pre>is-system-null(var)
4836</pre></div></div></li>
4837
4838<li>
4839<p>Checks whether the given variable is a <tt>system null</tt> value.</p></li>
4840
4841<li>Arguments:
4842
4843<ul>
4844
4845<li><tt>var</tt> : A variable (any type is allowed).</li>
4846 </ul></li>
4847
4848<li>Return Value:
4849
4850<ul>
4851
4852<li>A <tt>boolean</tt> on whether the variable is a <tt>system null</tt> or not.</li>
4853 </ul></li>
4854</ul></div>
4855<div class="section">
4856<h3><a name="len"></a>len</h3>
4857
4858<ul>
4859
4860<li>
4861<p>Syntax:</p>
4862<p>len(list_expression)</p></li>
4863
4864<li>
4865<p>Returns the length of the list list_expression.</p></li>
4866
4867<li>Arguments:
4868
4869<ul>
4870
4871<li><tt>list_expression</tt> : An <tt>OrderedList</tt>, <tt>UnorderedList</tt> or <tt>null</tt>, represents the list need to be checked.</li>
4872 </ul></li>
4873
4874<li>Return Value:
4875
4876<ul>
4877
4878<li>An <tt>Int32</tt> that represents the length of list_expression.</li>
4879 </ul></li>
4880
4881<li>
4882<p>Example:</p>
4883
4884<div class="source">
4885<div class="source">
4886<pre>use dataverse TinySocial;
4887
4888let $l := [&quot;ASTERIX&quot;, &quot;Hyracks&quot;]
4889return len($l)
4890</pre></div></div></li>
4891</ul>
4892
4893<ul>
4894
4895<li>
4896<p>The expected result is:</p>
4897
4898<div class="source">
4899<div class="source">
4900<pre>2
4901</pre></div></div></li>
4902</ul></div>
4903<div class="section">
4904<h3><a name="not"></a>not</h3>
4905
4906<ul>
4907
4908<li>
4909<p>Syntax:</p>
4910
4911<div class="source">
4912<div class="source">
4913<pre>not(var)
4914</pre></div></div></li>
4915
4916<li>
4917<p>Inverts a <tt>boolean</tt> value</p></li>
4918
4919<li>Arguments:
4920
4921<ul>
4922
4923<li><tt>var</tt> : A <tt>boolean</tt> (or <tt>null</tt>)</li>
4924 </ul></li>
4925
4926<li>Return Value:
4927
4928<ul>
4929
4930<li>A <tt>boolean</tt>, the inverse of <tt>var</tt>. returns <tt>null</tt> if <tt>var</tt> is null</li>
4931 </ul></li>
4932
4933<li>
4934<p>Example:</p>
4935
4936<div class="source">
4937<div class="source">
4938<pre>for $m in ['hello', 'world', null]
4939where not(is-null($m))
4940return $m
4941</pre></div></div></li>
4942
4943<li>
4944<p>The expected result is:</p>
4945
4946<div class="source">
4947<div class="source">
4948<pre>&quot;hello&quot;
4949&quot;world&quot;
4950</pre></div></div></li>
4951</ul></div>
4952<div class="section">
4953<h3><a name="range"></a>range</h3>
4954
4955<ul>
4956
4957<li>
4958<p>Syntax:</p>
4959
4960<div class="source">
4961<div class="source">
4962<pre>range(start_numeric_expression, end_numeric_expression)
4963</pre></div></div></li>
4964
4965<li>
4966<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>
4967
4968<li>Arguments:</li>
4969
4970<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>
4971
4972<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>
4973
4974<li>Return Value:
4975
4976<ul>
4977
4978<li>A generated <tt>uuid</tt>.</li>
4979 </ul></li>
4980
4981<li>
4982<p>Example:</p>
4983
4984<div class="source">
4985<div class="source">
4986<pre>for $i in range(0, 3)
4987return $i;
4988</pre></div></div></li>
4989
4990<li>
4991<p>The expected result is:</p>
4992
4993<div class="source">
4994<div class="source">
4995<pre>[ 0
4996, 1
4997, 2
4998, 3
4999]
5000</pre></div></div></li>
5001</ul></div>
5002<div class="section">
5003<h3><a name="switch-case"></a>switch-case</h3>
5004
5005<ul>
5006
5007<li>
5008<p>Syntax:</p>
5009
5010<div class="source">
5011<div class="source">
5012<pre>switch-case(condition,
5013 case1, case1-result,
5014 case2, case2-result,
5015 ...,
5016 default, default-result
5017)
5018</pre></div></div></li>
5019
5020<li>
5021<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>
5022
5023<li>Arguments:
5024
5025<ul>
5026
5027<li><tt>condition</tt>: A variable (any type is allowed).</li>
5028
5029<li><tt>caseI/default</tt>: A variable (any type is allowed).</li>
5030
5031<li><tt>caseI/default-result</tt>: A variable (any type is allowed).</li>
5032 </ul></li>
5033
5034<li>Return Value:
5035
5036<ul>
5037
5038<li>Returns <tt>caseI-result</tt> if <tt>condition</tt> matches <tt>caseI</tt>, otherwise <tt>default-result</tt>.</li>
5039 </ul></li>
5040
5041<li>
5042<p>Example 1:</p>
5043
5044<div class="source">
5045<div class="source">
5046<pre>switch-case(&quot;a&quot;,
5047 &quot;a&quot;, 0,
5048 &quot;x&quot;, 1,
5049 &quot;y&quot;, 2,
5050 &quot;z&quot;, 3
5051)
5052</pre></div></div></li>
5053</ul>
5054
5055<ul>
5056
5057<li>
5058<p>The expected result is:</p>
5059
5060<div class="source">
5061<div class="source">
5062<pre>0
5063</pre></div></div></li>
5064
5065<li>
5066<p>Example 2:</p>
5067
5068<div class="source">
5069<div class="source">
5070<pre>switch-case(&quot;a&quot;,
5071 &quot;x&quot;, 1,
5072 &quot;y&quot;, 2,
5073 &quot;z&quot;, 3
5074)
5075</pre></div></div></li>
5076
5077<li>
5078<p>The expected result is:</p>
5079
5080<div class="source">
5081<div class="source">
5082<pre>3
5083</pre></div></div></li>
5084</ul></div></div>
5085 </div>
5086 </div>
5087 </div>
5088
5089 <hr/>
5090
5091 <footer>
5092 <div class="container-fluid">
5093 <div class="row span12">Copyright &copy; 2015
5094 <a href="http://www.apache.org/">The Apache Software Foundation</a>.
5095 All Rights Reserved.
5096
5097 </div>
5098
5099 <?xml version="1.0" encoding="UTF-8"?>
5100<div class="row-fluid">Apache AsterixDB, AsterixDB, Apache, the Apache
5101 feather logo, and the Apache AsterixDB project logo are either
5102 registered trademarks or trademarks of The Apache Software
5103 Foundation in the United States and other countries.
5104 All other marks mentioned may be trademarks or registered
5105 trademarks of their respective owners.</div>
5106
5107
5108 </div>
5109 </footer>
5110 </body>
5111</html>