apache-ignite
980 строк · 14.5 Кб
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15= Numeric Functions
16
17== ABS
18
19[source,sql]
20----
21ABS (expression)
22----
23
24=== Parameters
25- `expression` - may be a column name, a result of another function, or a math operation.
26
27=== Description
28Returns the absolute value of an expression.
29
30[discrete]
31=== Example
32Calculate an absolute value:
33
34[source,sql]
35----
36SELECT transfer_id, ABS (price) from Transfers;
37----
38
39
40== ACOS
41
42[source,sql]
43----
44ACOS (expression)
45----
46
47
48=== Parameters
49- `expression` - may be a column name, a result of another function, or a math operation.
50
51=== Description
52Calculates the arc cosine. This method returns a `double`.
53
54[discrete]
55=== Example
56Get arc cos value:
57
58
59[source,sql]
60----
61SELECT acos(angle) FROM Triangles;
62----
63
64
65== ASIN
66
67[source,sql]
68----
69ASIN (expression)
70----
71
72
73=== Parameters
74- `expression` - may be a column name, a result of another function, or a math operation.
75
76=== Description
77Calculates the arc sine. This method returns a `double`.
78
79[discrete]
80=== Example
81Calculate an arc sine:
82
83
84[source,sql]
85----
86SELECT asin(angle) FROM Triangles;
87----
88
89
90== ATAN
91
92[source,sql]
93----
94ATAN (expression)
95----
96
97
98=== Parameters
99- `expression` - may be a column name, a result of another function, or a math operation.
100
101=== Description
102Calculates the arc tangent. This method returns a `double`.
103
104[discrete]
105=== Example
106Get an arc tangent:
107
108
109[source,sql]
110----
111SELECT atan(angle) FROM Triangles;
112----
113
114
115== COS
116
117[source,sql]
118----
119COS (expression)
120----
121
122
123=== Parameters
124- `expression` - may be a column name, a result of another function, or a math operation.
125
126=== Description
127Calculates the trigonometric cosine. This method returns a `double`.
128
129[discrete]
130=== Example
131Get a cosine:
132
133
134[source,sql]
135----
136SELECT COS(angle) FROM Triangles;
137----
138
139
140== COSH
141
142[source,sql]
143----
144COSH (expression)
145----
146
147
148=== Parameters
149- `expression` - may be a column name, a result of another function, or a math operation.
150
151=== Description
152Calculates the hyperbolic cosine. This method returns a `double`.
153
154[discrete]
155=== Example
156Get an hyperbolic cosine:
157
158
159[source,sql]
160----
161SELECT HCOS(angle) FROM Triangles;
162----
163
164
165== COT
166
167[source,sql]
168----
169COT (expression)
170----
171
172
173=== Parameters
174- `expression` - may be a column name, a result of another function, or a math operation.
175
176=== Description
177Calculates the trigonometric cotangent (1/TAN(ANGLE)). This method returns a `double`.
178
179[discrete]
180=== Example
181Gets a trigonometric cotangent:
182
183
184[source,sql]
185----
186SELECT COT(angle) FROM Triangles;
187----
188
189
190== SIN
191
192[source,sql]
193----
194SIN (expression)
195----
196
197
198=== Parameters
199- `expression` - may be a column name, a result of another function, or a math operation.
200
201=== Description
202Calculates the trigonometric sine. This method returns a `double`.
203
204[discrete]
205=== Example
206Get a trigonometric sine:
207
208
209[source,sql]
210----
211SELECT SIN(angle) FROM Triangles;
212----
213
214
215== SINH
216
217[source,sql]
218----
219SINH (expression)
220----
221
222
223=== Parameters
224- `expression` - may be a column name, a result of another function, or a math operation.
225
226=== Description
227Calculates the hyperbolic sine. This method returns a `double`.
228
229[discrete]
230=== Example
231Get a hyperbolic sine:
232
233
234[source,sql]
235----
236SELECT SINH(angle) FROM Triangles;
237----
238
239
240== TAN
241
242[source,sql]
243----
244TAN (expression)
245----
246
247
248=== Parameters
249- `expression` - may be a column name, a result of another function, or a math operation.
250
251=== Description
252Calculates the trigonometric tangent. This method returns a `double`.
253
254[discrete]
255=== Example
256Get a trigonometric tangent:
257
258
259[source,sql]
260----
261SELECT TAN(angle) FROM Triangles;
262----
263
264
265== TANH
266
267[source,sql]
268----
269TANH (expression)
270----
271
272
273=== Parameters
274- `expression` - may be a column name, a result of another function, or a math operation.
275
276=== Description
277Calculates the hyperbolic tangent. This method returns a `double`.
278
279[discrete]
280=== Example
281Get a hyperbolic tangent:
282
283
284[source,sql]
285----
286SELECT TANH(angle) FROM Triangles;
287----
288
289
290== ATAN2
291
292[source,sql]
293----
294ATAN2 (y, x)
295----
296
297
298=== Parameters
299- `x and y` - the arguments.
300
301=== Description
302Calculates the angle when converting the rectangular coordinates to polar coordinates. This method returns a `double`.
303
304[discrete]
305=== Example
306Get a hyperbolic tangent:
307
308
309[source,sql]
310----
311SELECT ATAN2(X, Y) FROM Triangles;
312----
313
314
315== BITAND
316
317[source,sql]
318----
319BITAND (y, x)
320----
321
322
323=== Parameters
324- `x and y` - the arguments.
325
326=== Description
327The bitwise AND operation. This method returns a `long`.
328
329[discrete]
330=== Example
331
332[source,sql]
333----
334SELECT BITAND(X, Y) FROM Triangles;
335----
336
337
338== BITGET
339
340[source,sql]
341----
342BITGET (y, x)
343----
344
345
346=== Parameters
347- `x and y` - the arguments.
348
349=== Description
350Returns true if and only if the first parameter has a bit set in the position specified by the second parameter. This method returns a `boolean`. The second parameter is zero-indexed; the least significant bit has position 0.
351
352[discrete]
353=== Example
354Check that 3rd bit is 1:
355
356
357[source,sql]
358----
359SELECT BITGET(X, 3) from Triangles;
360----
361
362
363== BITOR
364
365[source,sql]
366----
367BITOR (y, x)
368----
369
370
371=== Parameters
372- `x and y` - the arguments.
373
374=== Description
375The bitwise OR operation. This method returns a `long`.
376
377[discrete]
378=== Example
379Calculate OR between two fields:
380
381
382[source,sql]
383----
384SELECT BITGET(X, Y) from Triangles;
385----
386
387
388== BITXOR
389
390[source,sql]
391----
392BITXOR (y, x)
393----
394
395
396=== Parameters
397- `x and y` - the arguments.
398
399=== Description
400The bitwise XOR operation. This method returns a `long`.
401
402[discrete]
403=== Example
404Calculate XOR between two fields:
405
406
407[source,sql]
408----
409SELECT BITXOR(X, Y) FROM Triangles;
410----
411
412
413== MOD
414
415[source,sql]
416----
417MOD (y, x)
418----
419
420
421=== Parameters
422- `x and y` - the arguments.
423
424=== Description
425The modulo operation. This method returns a `long`.
426
427[discrete]
428=== Example
429Calculate MOD between two fields:
430
431
432[source,sql]
433----
434SELECT BITXOR(X, Y) FROM Triangles;
435----
436
437
438== CEILING
439
440[source,sql]
441----
442CEIL (expression)
443CEILING (expression)
444----
445
446
447=== Parameters
448- `expression` - any valid numeric expression.
449
450=== Description
451See also Java Math.ceil. This method returns a `double`.
452
453[discrete]
454=== Example
455Calculate a ceiling price for items:
456
457
458[source,sql]
459----
460SELECT item_id, CEILING(price) FROM Items;
461----
462
463
464== DEGREES
465
466
467[source,sql]
468----
469DEGREES (expression)
470----
471
472
473=== Parameters
474- `expression` - any valid numeric expression.
475
476=== Description
477See also `Java Math.toDegrees`. This method returns a `double`.
478
479[discrete]
480=== Example
481Converts the argument value to degrees:
482
483
484[source,sql]
485----
486SELECT DEGREES(X) FROM Triangles;
487----
488
489
490== EXP
491
492[source,sql]
493----
494EXP (expression)
495----
496
497
498=== Parameters
499- `expression` - any valid numeric expression.
500
501=== Description
502See also `Java Math.exp`. This method returns a `double`.
503
504[discrete]
505=== Example
506Calculates exp:
507
508
509[source,sql]
510----
511SELECT EXP(X) FROM Triangles;
512----
513
514
515== FLOOR
516
517[source,sql]
518----
519FLOOR (expression)
520----
521
522
523=== Parameters
524- `expression` - any valid numeric expression.
525
526=== Description
527See also `Java Math.floor`. This method returns a `double`.
528
529[discrete]
530=== Example
531Calculates floor price:
532
533
534[source,sql]
535----
536SELECT FLOOR(X) FROM Items;
537----
538
539
540== LOG
541
542[source,sql]
543----
544LOG (expression)
545LN (expression)
546----
547
548
549=== Parameters
550- `expression` - any valid numeric expression.
551
552=== Description
553See also `Java Math.log`. This method returns a `double`.
554
555[discrete]
556=== Example
557Calculates LOG:
558
559
560[source,sql]
561----
562SELECT LOG(X) from Items;
563----
564
565
566== LOG10
567
568[source,sql]
569----
570LOG10 (expression)
571----
572
573
574=== Parameters
575- `expression` - any valid numeric expression.
576
577=== Description
578See also `Java Math.log10` (in Java 5). This method returns a `double`.
579
580[discrete]
581=== Example
582Calculate LOG10:
583
584
585[source,sql]
586----
587SELECT LOG(X) FROM Items;
588----
589
590
591== RADIANS
592
593[source,sql]
594----
595RADIANS (expression)
596----
597
598
599=== Parameters
600- `expression` - any valid numeric expression.
601
602=== Description
603See also Java Math.toRadians. This method returns a double.
604
605[discrete]
606=== Example
607Calculates RADIANS:
608
609
610[source,sql]
611----
612SELECT RADIANS(X) FROM Items;
613----
614
615
616== SQRT
617
618[source,sql]
619----
620SQRT (expression)
621----
622
623
624=== Parameters
625- `expression` - any valid numeric expression.
626
627=== Description
628See also `Java Math.sqrt`. This method returns a `double`.
629
630[discrete]
631=== Example
632Calculates SQRT:
633
634
635[source,sql]
636----
637SELECT SQRT(X) FROM Items;
638----
639
640
641== PI
642
643
644[source,sql]
645----
646PI (expression)
647----
648
649
650=== Parameters
651- `expression` - any valid numeric expression.
652
653=== Description
654See also `Java Math.PI`. This method returns a `double`.
655
656[discrete]
657=== Example
658Calculates PI:
659
660
661[source,sql]
662----
663SELECT PI(X) FROM Items;
664----
665
666
667== POWER
668
669
670[source,sql]
671----
672POWER (X, Y)
673----
674
675
676=== Parameters
677- `expression` - any valid numeric expression.
678
679=== Description
680See also `Java Math.pow`. This method returns a `double`.
681
682[discrete]
683=== Example
684Calculate the power of 2:
685
686
687[source,sql]
688----
689SELECT pow(2, n) FROM Rows;
690----
691
692
693== RAND
694
695[source,sql]
696----
697{RAND | RANDOM} ([expression])
698----
699
700
701=== Parameters
702- `expression` - any valid numeric expression seeds the session's random number generator.
703
704=== Description
705Calling the function without a parameter returns the next a pseudo random number. Calling it with a parameter seeds the session's random number generator. This method returns a `double` between 0 (including) and 1 (excluding).
706
707[discrete]
708=== Example
709Gets a random number for every play:
710
711
712[source,sql]
713----
714SELECT random() FROM Play;
715----
716
717
718== RANDOM_UUID
719
720[source,sql]
721----
722{RANDOM_UUID | UUID} ()
723----
724
725
726=== Description
727Returns a new UUID with 122 pseudo random bits.
728
729[discrete]
730=== Example
731Gets random number for every Player:
732
733
734[source,sql]
735----
736SELECT UUID(),name FROM Player;
737----
738
739
740== ROUND
741
742[source,sql]
743----
744ROUND ( expression [, precision] )
745----
746
747
748=== Parameters
749- `expression` - any valid numeric expression.
750- `precision` - the number of digits after the decimal to round to. Rounds to the nearest long if the number of digits if not set.
751
752=== Description
753Rounds to a number of digits, or to the nearest long if the number of digits if not set. This method returns a `numeric` (the same type as the input).
754
755[discrete]
756=== Example
757Convert every Player's age to an integer number:
758
759
760[source,sql]
761----
762SELECT name, ROUND(age) FROM Player;
763----
764
765
766== ROUNDMAGIC
767
768[source,sql]
769----
770ROUNDMAGIC (expression)
771----
772
773
774=== Parameters
775- `expression` - any valid numeric expression.
776
777=== Description
778This function is good for rounding numbers, but it can be slow. It has special handling for numbers around 0. Only numbers smaller than or equal to `+/-1000000000000` are supported. The value is converted to a String internally, and then the last 4 characters are checked. '000x' becomes '0000' and '999x' becomes '999999', which is rounded automatically. This method returns a `double`.
779
780[discrete]
781=== Example
782Round every Player's age:
783
784
785[source,sql]
786----
787SELECT name, ROUNDMAGIC(AGE/3*3) FROM Player;
788----
789
790
791== SECURE_RAND
792
793[source,sql]
794----
795SECURE_RAND (int)
796----
797
798
799=== Parameters
800- `int` - specifies the number of digits.
801
802=== Description
803Generate a number of cryptographically secure random numbers. This method returns `bytes`.
804
805[discrete]
806=== Example
807Get a truly random number:
808
809
810[source,sql]
811----
812SELECT name, SECURE_RAND(10) FROM Player;
813----
814
815
816== SIGN
817
818[source,sql]
819----
820SIGN (expression)
821----
822
823
824=== Parameters
825- `expression` - any valid numeric expression.
826
827=== Description
828Return -1 if the value is smaller 0, 0 if zero, and otherwise 1.
829
830[discrete]
831=== Example
832Get a sign for every value:
833
834
835[source,sql]
836----
837SELECT name, SIGN(VALUE) FROM Player;
838----
839
840
841== ENCRYPT
842
843[source,sql]
844----
845ENCRYPT (algorithmString , keyBytes , dataBytes)
846----
847
848
849=== Parameters
850- `algorithmString` - sets a supported AES algorithm.
851- `keyBytes` - sets a key.
852- `dataBytes` - sets data.
853
854=== Description
855Encrypt data using a key. The supported algorithm is AES. The block size is 16 bytes. This method returns `bytes`.
856
857[discrete]
858=== Example
859Encrypt players name:
860
861
862[source,sql]
863----
864SELECT ENCRYPT('AES', '00', STRINGTOUTF8(Name)) FROM Player;
865----
866
867
868== DECRYPT
869
870[source,sql]
871----
872DECRYPT (algorithmString , keyBytes , dataBytes)
873----
874
875
876=== Parameters
877- `algorithmString` - sets a supported AES algorithm.
878- `keyBytes` - sets a key.
879- `dataBytes` - sets data.
880
881=== Description
882Decrypts data using a key. The supported algorithm is AES. The block size is 16 bytes. This method returns bytes.
883
884[discrete]
885=== Example
886Decrypt Players' names:
887
888
889[source,sql]
890----
891SELECT DECRYPT('AES', '00', '3fabb4de8f1ee2e97d7793bab2db1116'))) FROM Player;
892----
893
894
895== TRUNCATE
896
897
898[source,sql]
899----
900{TRUNC | TRUNCATE} (\{\{numeric, digitsInt} | timestamp | date | timestampString})
901----
902
903
904=== Description
905Truncates to a number of digits (to the next value closer to 0). This method returns a `double`. When used with a timestamp, truncates a timestamp to a date (day) value. When used with a date, truncates a date to a date (day) value less time part. When used with a timestamp as string, truncates a timestamp to a date (day) value.
906
907[discrete]
908=== Example
909
910[source,sql]
911----
912TRUNCATE(VALUE, 2);
913----
914
915
916== COMPRESS
917
918[source,sql]
919----
920COMPRESS(dataBytes [, algorithmString])
921----
922
923
924=== Parameters
925- `dataBytes` - data to compress.
926- `algorithmString` - an algorithm to use for compression.
927
928=== Description
929Compress the data using the specified compression algorithm. Supported algorithms are: LZF (faster but lower compression; default), and DEFLATE (higher compression). Compression does not always reduce size. Very small objects and objects with little redundancy may get larger. This method returns `bytes`.
930
931[discrete]
932=== Example
933
934[source,sql]
935----
936COMPRESS(STRINGTOUTF8('Test'))
937----
938
939
940== EXPAND
941
942[source,sql]
943----
944EXPAND(dataBytes)
945----
946
947
948=== Parameters
949- `dataBytes` - data to expand.
950
951=== Description
952Expand data that was compressed using the COMPRESS function. This method returns `bytes`.
953
954[discrete]
955=== Example
956
957[source,sql]
958----
959UTF8TOSTRING(EXPAND(COMPRESS(STRINGTOUTF8('Test'))))
960----
961
962
963== ZERO
964
965[source,sql]
966----
967ZERO()
968----
969
970
971=== Description
972Return the value 0. This function can be used even if numeric literals are disabled.
973
974[discrete]
975=== Example
976
977[source,sql]
978----
979ZERO()
980----
981
982