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