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