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