apache-ignite

Форк
0
/
numeric-functions.adoc 
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
----
21
ABS (expression)
22
----
23

24
=== Parameters
25
- `expression` - may be a column name, a result of another function, or a math operation.
26

27
=== Description
28
Returns the absolute value of an expression.
29

30
[discrete]
31
=== Example
32
Calculate an absolute value:
33

34
[source,sql]
35
----
36
SELECT transfer_id, ABS (price) from Transfers;
37
----
38

39

40
== ACOS
41

42
[source,sql]
43
----
44
ACOS (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
52
Calculates the arc cosine. This method returns a `double`.
53

54
[discrete]
55
=== Example
56
Get arc cos value:
57

58

59
[source,sql]
60
----
61
SELECT acos(angle) FROM Triangles;
62
----
63

64

65
== ASIN
66

67
[source,sql]
68
----
69
ASIN (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
77
Calculates the arc sine. This method returns a `double`.
78

79
[discrete]
80
=== Example
81
Calculate an arc sine:
82

83

84
[source,sql]
85
----
86
SELECT asin(angle) FROM Triangles;
87
----
88

89

90
== ATAN
91

92
[source,sql]
93
----
94
ATAN (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
102
Calculates the arc tangent. This method returns a `double`.
103

104
[discrete]
105
=== Example
106
Get an arc tangent:
107

108

109
[source,sql]
110
----
111
SELECT atan(angle) FROM Triangles;
112
----
113

114

115
== COS
116

117
[source,sql]
118
----
119
COS (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
127
Calculates the trigonometric cosine. This method returns a `double`.
128

129
[discrete]
130
=== Example
131
Get a cosine:
132

133

134
[source,sql]
135
----
136
SELECT COS(angle) FROM Triangles;
137
----
138

139

140
== COSH
141

142
[source,sql]
143
----
144
COSH (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
152
Calculates the hyperbolic cosine. This method returns a `double`.
153

154
[discrete]
155
=== Example
156
Get an hyperbolic cosine:
157

158

159
[source,sql]
160
----
161
SELECT HCOS(angle) FROM Triangles;
162
----
163

164

165
== COT
166

167
[source,sql]
168
----
169
COT (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
177
Calculates the trigonometric cotangent (1/TAN(ANGLE)). This method returns a `double`.
178

179
[discrete]
180
=== Example
181
Gets a​ trigonometric cotangent:
182

183

184
[source,sql]
185
----
186
SELECT COT(angle) FROM Triangles;
187
----
188

189

190
== SIN
191

192
[source,sql]
193
----
194
SIN (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
202
Calculates the trigonometric sine. This method returns a `double`.
203

204
[discrete]
205
=== Example
206
Get a trigonometric sine:
207

208

209
[source,sql]
210
----
211
SELECT SIN(angle) FROM Triangles;
212
----
213

214

215
== SINH
216

217
[source,sql]
218
----
219
SINH (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
227
Calculates the hyperbolic sine. This method returns a `double`.
228

229
[discrete]
230
=== Example
231
Get a hyperbolic sine:
232

233

234
[source,sql]
235
----
236
SELECT SINH(angle) FROM Triangles;
237
----
238

239

240
== TAN
241

242
[source,sql]
243
----
244
TAN (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
252
Calculates the trigonometric tangent. This method returns a `double`.
253

254
[discrete]
255
=== Example
256
Get a trigonometric tangent:
257

258

259
[source,sql]
260
----
261
SELECT TAN(angle) FROM Triangles;
262
----
263

264

265
== TANH
266

267
[source,sql]
268
----
269
TANH (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
277
Calculates the hyperbolic tangent. This method returns a `double`.
278

279
[discrete]
280
=== Example
281
Get a hyperbolic tangent:
282

283

284
[source,sql]
285
----
286
SELECT TANH(angle) FROM Triangles;
287
----
288

289

290
== ATAN2
291

292
[source,sql]
293
----
294
ATAN2 (y, x)
295
----
296

297

298
=== Parameters
299
- `x and y` - the arguments.
300

301
=== Description
302
Calculates the angle when converting the rectangular coordinates to polar coordinates. This method returns a `double`.
303

304
[discrete]
305
=== Example
306
Get a hyperbolic tangent:
307

308

309
[source,sql]
310
----
311
SELECT ATAN2(X, Y) FROM Triangles;
312
----
313

314

315
== BITAND
316

317
[source,sql]
318
----
319
BITAND (y, x)
320
----
321

322

323
=== Parameters
324
- `x and y` - the arguments.
325

326
=== Description
327
The bitwise AND operation. This method returns a `long`.
328

329
[discrete]
330
=== Example
331

332
[source,sql]
333
----
334
SELECT BITAND(X, Y) FROM Triangles;
335
----
336

337

338
== BITGET
339

340
[source,sql]
341
----
342
BITGET (y, x)
343
----
344

345

346
=== Parameters
347
- `x and y` - the arguments.
348

349
=== Description
350
Returns 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
354
Check that 3rd bit is 1:
355

356

357
[source,sql]
358
----
359
SELECT BITGET(X, 3) from Triangles;
360
----
361

362

363
== BITOR
364

365
[source,sql]
366
----
367
BITOR (y, x)
368
----
369

370

371
=== Parameters
372
- `x and y` - the arguments.
373

374
=== Description
375
The bitwise OR operation. This method returns a `long`.
376

377
[discrete]
378
=== Example
379
Calculate OR between two fields:
380

381

382
[source,sql]
383
----
384
SELECT BITGET(X, Y) from Triangles;
385
----
386

387

388
== BITXOR
389

390
[source,sql]
391
----
392
BITXOR (y, x)
393
----
394

395

396
=== Parameters
397
- `x and y` - the arguments.
398

399
=== Description
400
The bitwise XOR operation. This method returns a `long`.
401

402
[discrete]
403
=== Example
404
Calculate XOR between two fields:
405

406

407
[source,sql]
408
----
409
SELECT BITXOR(X, Y) FROM Triangles;
410
----
411

412

413
== MOD
414

415
[source,sql]
416
----
417
MOD (y, x)
418
----
419

420

421
=== Parameters
422
- `x and y` - the arguments.
423

424
=== Description
425
The modulo operation. This method returns a `long`.
426

427
[discrete]
428
=== Example
429
Calculate MOD between two fields:
430

431

432
[source,sql]
433
----
434
SELECT BITXOR(X, Y) FROM Triangles;
435
----
436

437

438
== CEILING
439

440
[source,sql]
441
----
442
CEIL (expression)
443
CEILING (expression)
444
----
445

446

447
=== Parameters
448
- `expression` - any valid numeric expression.
449

450
=== Description
451
See also Java Math.ceil. This method returns a `double`.
452

453
[discrete]
454
=== Example
455
Calculate a ceiling price for items:
456

457

458
[source,sql]
459
----
460
SELECT item_id, CEILING(price) FROM Items;
461
----
462

463

464
== DEGREES
465

466

467
[source,sql]
468
----
469
DEGREES (expression)
470
----
471

472

473
=== Parameters
474
- `expression` - any valid numeric expression.
475

476
=== Description
477
See also `Java Math.toDegrees`. This method returns a `double`.
478

479
[discrete]
480
=== Example
481
Converts the argument value to degrees:
482

483

484
[source,sql]
485
----
486
SELECT DEGREES(X) FROM Triangles;
487
----
488

489

490
== EXP
491

492
[source,sql]
493
----
494
EXP (expression)
495
----
496

497

498
=== Parameters
499
- `expression` - any valid numeric expression.
500

501
=== Description
502
See also `Java Math.exp`. This method returns a `double`.
503

504
[discrete]
505
=== Example
506
Calculates exp:
507

508

509
[source,sql]
510
----
511
SELECT EXP(X) FROM Triangles;
512
----
513

514

515
== FLOOR
516

517
[source,sql]
518
----
519
FLOOR (expression)
520
----
521

522

523
=== Parameters
524
- `expression` - any valid numeric expression.
525

526
=== Description
527
See also `Java Math.floor`. This method returns a `double`.
528

529
[discrete]
530
=== Example
531
Calculates floor price:
532

533

534
[source,sql]
535
----
536
SELECT FLOOR(X) FROM Items;
537
----
538

539

540
== LOG
541

542
[source,sql]
543
----
544
LOG (expression)
545
LN (expression)
546
----
547

548

549
=== Parameters
550
- `expression` - any valid numeric expression.
551

552
=== Description
553
See also `Java Math.log`. This method returns a `double`.
554

555
[discrete]
556
=== Example
557
Calculates LOG:
558

559

560
[source,sql]
561
----
562
SELECT LOG(X) from Items;
563
----
564

565

566
== LOG10
567

568
[source,sql]
569
----
570
LOG10 (expression)
571
----
572

573

574
=== Parameters
575
- `expression` - any valid numeric expression.
576

577
=== Description
578
See also `Java Math.log10` (in Java 5). This method returns a `double`.
579

580
[discrete]
581
=== Example
582
Calculate LOG10:
583

584

585
[source,sql]
586
----
587
SELECT LOG(X) FROM Items;
588
----
589

590

591
== RADIANS
592

593
[source,sql]
594
----
595
RADIANS (expression)
596
----
597

598

599
=== Parameters
600
- `expression` - any valid numeric expression.
601

602
=== Description
603
See also Java Math.toRadians. This method returns a double.
604

605
[discrete]
606
=== Example
607
Calculates RADIANS:
608

609

610
[source,sql]
611
----
612
SELECT RADIANS(X) FROM Items;
613
----
614

615

616
== SQRT
617

618
[source,sql]
619
----
620
SQRT (expression)
621
----
622

623

624
=== Parameters
625
- `expression` - any valid numeric expression.
626

627
=== Description
628
See also `Java Math.sqrt`. This method returns a `double`.
629

630
[discrete]
631
=== Example
632
Calculates SQRT:
633

634

635
[source,sql]
636
----
637
SELECT SQRT(X) FROM Items;
638
----
639

640

641
== PI
642

643

644
[source,sql]
645
----
646
PI (expression)
647
----
648

649

650
=== Parameters
651
- `expression` - any valid numeric expression.
652

653
=== Description
654
See also `Java Math.PI`. This method returns a `double`.
655

656
[discrete]
657
=== Example
658
Calculates PI:
659

660

661
[source,sql]
662
----
663
SELECT PI(X) FROM Items;
664
----
665

666

667
== POWER
668

669

670
[source,sql]
671
----
672
POWER (X, Y)
673
----
674

675

676
=== Parameters
677
- `expression` - any valid numeric expression.
678

679
=== Description
680
See also `Java Math.pow`. This method returns a `double`.
681

682
[discrete]
683
=== Example
684
Calculate the ​power of 2:
685

686

687
[source,sql]
688
----
689
SELECT 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
705
Calling 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
709
Gets a random number for every play:
710

711

712
[source,sql]
713
----
714
SELECT random() FROM Play;
715
----
716

717

718
== RANDOM_UUID
719

720
[source,sql]
721
----
722
{RANDOM_UUID | UUID} ()
723
----
724

725

726
=== Description
727
Returns a new UUID with 122 pseudo random bits.
728

729
[discrete]
730
=== Example
731
Gets random number for every Player:
732

733

734
[source,sql]
735
----
736
SELECT UUID(),name FROM Player;
737
----
738

739

740
== ROUND
741

742
[source,sql]
743
----
744
ROUND ( 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
753
Rounds 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
757
Convert every Player's age to an integer number:
758

759

760
[source,sql]
761
----
762
SELECT name, ROUND(age) FROM Player;
763
----
764

765

766
== ROUNDMAGIC
767

768
[source,sql]
769
----
770
ROUNDMAGIC (expression)
771
----
772

773

774
=== Parameters
775
- `expression` - any valid numeric expression.
776

777
=== Description
778
This 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
782
Round every Player's age:
783

784

785
[source,sql]
786
----
787
SELECT name, ROUNDMAGIC(AGE/3*3) FROM Player;
788
----
789

790

791
== SECURE_RAND
792

793
[source,sql]
794
----
795
SECURE_RAND (int)
796
----
797

798

799
=== Parameters
800
- `int` - specifies the number​ of digits.
801

802
=== Description
803
Generate a number of cryptographically secure random numbers. This method returns `bytes`.
804

805
[discrete]
806
=== Example
807
Get a truly random number:
808

809

810
[source,sql]
811
----
812
SELECT name, SECURE_RAND(10) FROM Player;
813
----
814

815

816
== SIGN
817

818
[source,sql]
819
----
820
SIGN (expression)
821
----
822

823

824
=== Parameters
825
- `expression` - any valid numeric expression.
826

827
=== Description
828
Return -1 if the value is smaller 0, 0 if zero, and otherwise 1.
829

830
[discrete]
831
=== Example
832
Get a sign for every value:
833

834

835
[source,sql]
836
----
837
SELECT name, SIGN(VALUE) FROM Player;
838
----
839

840

841
== ENCRYPT
842

843
[source,sql]
844
----
845
ENCRYPT (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
855
Encrypt data using a key. The supported algorithm is AES. The block size is 16 bytes. This method returns `bytes`.
856

857
[discrete]
858
=== Example
859
Encrypt players name:
860

861

862
[source,sql]
863
----
864
SELECT ENCRYPT('AES', '00', STRINGTOUTF8(Name)) FROM Player;
865
----
866

867

868
== DECRYPT
869

870
[source,sql]
871
----
872
DECRYPT (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
882
Decrypts data using a key. The supported algorithm is AES. The block size is 16 bytes. This method returns bytes.
883

884
[discrete]
885
=== Example
886
Decrypt Players' names:
887

888

889
[source,sql]
890
----
891
SELECT 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
905
Truncates 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
----
912
TRUNCATE(VALUE, 2);
913
----
914

915

916
== COMPRESS
917

918
[source,sql]
919
----
920
COMPRESS(dataBytes [, algorithmString])
921
----
922

923

924
=== Parameters
925
- `dataBytes` - data to compress.
926
- `algorithmString` - an algorithm to use for compression.
927

928
=== Description
929
Compress 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
----
936
COMPRESS(STRINGTOUTF8('Test'))
937
----
938

939

940
== EXPAND
941

942
[source,sql]
943
----
944
EXPAND(dataBytes)
945
----
946

947

948
=== Parameters
949
- `dataBytes` - data to expand.
950

951
=== Description
952
Expand data that was compressed using the COMPRESS function. This method returns `bytes`.
953

954
[discrete]
955
=== Example
956

957
[source,sql]
958
----
959
UTF8TOSTRING(EXPAND(COMPRESS(STRINGTOUTF8('Test'))))
960
----
961

962

963
== ZERO
964

965
[source,sql]
966
----
967
ZERO()
968
----
969

970

971
=== Description
972
Return the value 0. This function can be used even if numeric literals are disabled.
973

974
[discrete]
975
=== Example
976

977
[source,sql]
978
----
979
ZERO()
980
----
981

982

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.