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