Source

htsql-sqlascii-patch / test / regress / input / library.yaml

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#
# Copyright (c) 2006-2011, Prometheus Research, LLC
# Authors: Clark C. Evans <cce@clarkevans.com>,
#          Kirill Simonov <xi@resolvent.net>
#

title: Standard Data Types, Functions, and Operations
id: library
tests:

########################################################################

- title: Literals
  tests:

  # Untyped literals, implicitly converted to string
  - uri: /{null(), '', 'HTSQL'}

  # Boolean values
  - uri: /{true(), false()}
  - uri: /{boolean('true'), boolean('false')}
  # Invalid Boolean literals
  - uri: /boolean('')
    expect: 400
  - uri: /boolean('yes')
    expect: 400

  # String values
  - uri: /{'', 'HTSQL', 'O''Reilly',
           '%ce%bb%cf%8c%ce%b3%ce%bf%cf%82',
           '$-b \pm \sqrt{b^2 - 4ac} \over 2a$'}
    ifndef: mssql
  # The regression database for MS SQL Server uses Latin1 locale and therefore
  # is unable to represent greek characters.
  - uri: /{'', 'HTSQL', 'O''Reilly', 'zo%c3%b6logy',
           '$-b \pm \sqrt{b^2 - 4ac} \over 2a$'}
    ifdef: mssql
  - uri: /{string('832040')}

  # Integer values
  - uri: /{0, 7, -97, 3571}
  - uri: /{integer('4862'), integer('-9694845')}
  # 64-bit signed integers
  - uri: /{integer('-9223372036854775808'),
           integer('9223372036854775807')}
  # Invalid integer literal
  - uri: /{integer('2.5e1')}
    expect: 400
  # Out of range
  - uri: /{18446744073709551616}
    expect: 400

  # Decimal values
  - uri: /{1.0, -2.5, 0.875}
  - uri: /{decimal('1E-10')}
  # Arbitrary length
  - uri: /{4154781481226426191177580544000000.808017424794512875886459904961710757005754368000000000}
    ifndef: mssql
  # Invalid decimal literals
  - uri: /{decimal('vingt-cinq')}
    expect: 400

  # Float values
  - uri: /{0e0, -57721e-5, 36288e2}
  - uri: /{float('2147483647')}
  # Invalid float literal
  - uri: /float('vingt-cinq')
    expect: 400
  # Infinity
  - uri: /{1e1024}
    expect: 400
  - uri: /{float('inf')}
    expect: 400

  # Date values
  - uri: /{date('2010-04-15')}
  # Invalid date
  - uri: /date('2010-13-07')
    expect: 400

########################################################################

- title: Logical and Comparison Operators
  tests:

  # Boolean literals
  - uri: /{true(), false()}
  # Boolean conversion
  - uri: /{boolean(null()), boolean('true'), boolean('false')}
  - uri: /{boolean(integer(null())), boolean(0.0), boolean(1e0)}
  - uri: /{boolean(string(null())),
           boolean(string('')),
           boolean(string('FALSE'))}
  - uri: /{boolean(date(null())), boolean(date('2010-04-15'))}
  # AND, OR, NOT
  - uri: /{true()&true(), true()&false(), false()&true(), false()&false()}
  - uri: /{true()|true(), true()|false(), false()|true(), false()|false()}
  - uri: /{!true(), !false()}
  - uri: /{null()&true(), null()&false(), null()&null()}
  - uri: /{null()|true(), null()|false(), null()|null()}
  - uri: /{!null()}
  # Is NULL
  - uri: /{is_null(null()), is_null('NULL'), is_null(0)}

  # Equality
  - uri: /{true()=true(), 1=1, 'HTSQL'='HTSQL',
           date('2010-04-15')=date('2010-04-15')}
  - uri: /{true()!=false(), 1!=0, 'HTSQL'!='PITA',
           date('2010-04-15')!=date('1991-08-20')}
  - uri: /{true()!=true(), 1!=1, 'HTSQL'!='HTSQL',
           date('2010-04-15')!=date('2010-04-15')}
  - uri: /{true()=false(), 1=0, 'HTSQL'='PITA',
           date('2010-04-15')=date('1991-08-20')}
  # IN
  - uri: /{5={2,3,5,7}, 'HTSQL'!={'ISBL','SQUARE','QUEL'}}
  - uri: /{5!={2,3,5,7}, 'HTSQL'={'ISBL','SQUARE','QUEL'}}
  # NULL and Total Equality
  - uri: /{1=null(), 1!=null(), null()=null(), null()!=null()}
  - uri: /{false()={false(),null()}, true()={false(),null()},
           false()!={false(),null()}, false()!={true(),null()}}
  - uri: /{null()={true(),false()}, null()!={true(),false()}}
  - uri: /{1==1, 1!==0, 1==null(), 1!==null(),
           null()==null(), null()!==null()}
  # Coercion
  - uri: /{7=0.7e1, '13'=13.0, '13'!=='13.0'}
  # Inadmissible operands
  - uri: /{true()=1}
    expect: 400
  - uri: /{'cinq'!=4.9}
    expect: 400
  - uri: /{date('2010-04-15')==1991}
    expect: 400

  # Comparison
  - uri: /{1<10, 7.0<=7.0, 'omega'>'alpha',
           date('2010-04-15')>=date('1991-08-20')}
  - uri: /{1>=10, 7.0>7.0, 'omega'<='alpha',
           date('2010-04-15')<date('1991-08-20')}
  # NULL
  - uri: /{0<null(), ''>null(), null()>=null()}
  # Coercion
  - uri: /{175e-2>'875e-3', '2010-04-15'>=date('1991-08-20')}
  # Inadmissible operands
  - uri: /{false()<true()}
    expect: 400
  - uri: /{'cinq'>4.9}
    expect: 400
  - uri: /{date('2010-04-15')>=1991}
    expect: 400

  # If NULL and NULL If
  - uri: /{if_null('Victor', 'William'),
           if_null(null(), 'William'),
           if_null('Victor', null()),
           if_null(null(), null())}
  - uri: /{null_if('George', 'George'),
           null_if('George', 'Harry'),
           null_if(null(),  'Harry'),
           null_if('George', null()),
           null_if(null(), null())}
  # Coercion
  - uri: /{if_null(1, 0.1e1), null_if(1, 0.1e1)}
  # Inadmissible operands
  - uri: /{if_null('cinq', 5)}
    expect: 400
  - uri: /{null_if('cinq', 5)}
    expect: 400
  - uri: /{if_null(date('2010-04-15'),1991)}
    expect: 400
  - uri: /{null_if(date('2010-04-15'),1991)}
    expect: 400

  # If and Switch
  - uri: /{if(true(), 'then'),
           if(false(), 'then'),
           if(null(), 'then')}
  - uri: /{if(true(), 'then', 'else'),
           if(false(), 'then', 'else'),
           if(null(), 'then', 'else')}
  - uri: /{if(7=0, 'none', 7=1, 'one', 7=2, 'two', 'many')}
  - uri: /{switch(1, 1, 'George', 2, 'Harry'),
           switch(2, 1, 'George', 2, 'Harry'),
           switch(3, 1, 'George', 2, 'Harry')}
  - uri: /{switch(1, 1, 'George', 2, 'Harry', 'Edward'),
           switch(2, 1, 'George', 2, 'Harry', 'Edward'),
           switch(3, 1, 'George', 2, 'Harry', 'Edward')}
  # Coercion
  - uri: /{if(true(), 1, 0e0)}
  - uri: /{switch(date('2010-04-15'),
                  '1991-08-20', 'WWW',
                  '2010-04-15', 'HTSQL')}
  # Inadmissible operands
  - uri: /{if('', 'then', 'else')}
    expect: 400
  - uri: /{switch(1, date('2010-04-15'), 1, date('1991-08-20'), 2)}
    expect: 400
  - uri: /{switch(1, 1, 'George', 2, false())}
    expect: 400

########################################################################

- title: Numeric Functions and Operators
  tests:

  # Conversion
  - uri: /{integer(null()), integer('60'), integer(60)}
  - uri: /{decimal(null()), decimal('2.125'), decimal(2.125)}
  - uri: /{float(null()), float('271828e-5'), float('271828e-5')}
  - uri: /{integer(2.125), integer(271828e-5)}
  - uri: /{decimal(60), decimal(271828e-5)}
  - uri: /{float(60), float(2.125)}
  - uri: /{integer(string('60'))}
  - uri: /{decimal(string('2.125'))}
  - uri: /{float(string('271828e-5'))}
  # Inadmissible operand
  - uri: /{integer('cinq')}
    expect: 400
  - uri: /{decimal(true())}
    expect: 400
  - uri: /{float(date('2010-04-15'))}
    expect: 400
  # Not a number
  - uri: /{integer(string('zero'))}
    ifdef: [sqlite, mysql]
  - uri: /{float(string('zero'))}
    ifdef: [sqlite, mysql]
  - uri: /{integer(string('cinq'))}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  # Integer overflow
  - uri: /{integer(4294967296.0)}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{integer(1.8446744073709552e+19)}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{integer(4294967296.0),
           integer(1.8446744073709552e+19)}
    ifdef: [sqlite, mysql]

  # Arithmetics
  - uri: /{+7, -7, +2.125, -2.125, +271828e-5, -271828e-5}
  - uri: /{7920+9504, 7.25+0.875, 120205e-5+57721e-5}
  - uri: /{7920-9504, 7.25-0.875, 120205e-5-57721e-5}
  - uri: /{7920*9504, 7.25*0.875, 120205e-5*57721e-5}
  - uri: /{7920/9504, 7.25/0.875, 120205e-5/57721e-5}
  # Coercion
  - uri: /{7+2.125, 7+271828e-5, 2.125+271828e-5}
  - uri: /{7-2.125, 7-271828e-5, 2.125-271828e-5}
  - uri: /{7*2.125, 7*271828e-5, 2.125*271828e-5}
  - uri: /{7/2.125, 7/271828e-5, 2.125/271828e-5}
  # Inadmissible operands
  - uri: /{'cinq'+7}
    expect: 400
  - uri: /{2.125-date('2010-04-15')}
    expect: 400
  - uri: /{true()/271828e-5}
    expect: 400
  # Integer overflow
  - uri: /{7*2147483647}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{9223372036854775807+1}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{7*2147483647, 9223372036854775807+1}
    ifdef: [sqlite, mysql]
  # Division by zero
  - uri: /{7/0}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{7/0.0}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{7/0e0}
    expect: 409
    ignore: true
    ifdef: [pgsql, mssql]
  - uri: /{7/0, 7/0.0, 7/0e0}
    ifdef: [sqlite, mysql]

  # Rounding
  - uri: /{round(3272.78125,2)}
  - uri: /{round(3272.78125,-2)}
    ifndef: sqlite
  - uri: /{round(3272.78125), round(271828e-5)}
  # Coercion
  - uri: /{round(9973)}
  # Bug in MSSQL 2008R2, see
  # https://connect.microsoft.com/SQLServer/feedback/details/646516/bad-example-for-round
  - uri: /{round(9973,-2)}
    ifndef: [sqlite, mssql]
  # Inadmissible operand
  - uri: /{round(271828e-5,2)}
    expect: 400
    ifndef: sqlite

########################################################################

- title: String Functions and Operators
  tests:

  # Conversion
  - uri: /{string(null()), string('OMGWTFBBQ')}
  - uri: /{string(true()), string(false())}
  - uri: /{string(60), string(2.125), string(-57721e-5)}
  - uri: /{string(date('2010-04-15'))}

  # Length
  - uri: /{length(''), length('OMGWTFBBQ')}
  - uri: /{length(null())}
  # Inadmissible operand
  - uri: /{length(date(2010-04-15))}
    expect: 400

  # Concatenation
  - uri: /{'OMG'+'WTF'+'BBQ'}
  - uri: /{null()+'LOL', 'LOL'+null(),
           string(null())+string(null())}
  # Inadmissible operands
  - uri: /{string('LOL')+7}
    expect: 400

  # Contains
  - uri: /{'OMGWTFBBQ'~'wtf', 'OMGWTFBBQ'!~'LOL'}
  - uri: /{'OMGWTFBBQ'!~'wtf', 'OMGWTFBBQ'~'LOL'}
  # Bug in MSSQL 2005, `SELECT (CASE WHEN ('LOL' LIKE NULL) THEN 1 END)`
  # generates [<1>].
  - uri: /{null()~'LOL', 'LOL'~null(), null()~null()}
    ifndef: mssql
  - uri: /{null()~'LOL', null()~null()}
    ifdef: mssql
  - uri: /this(){true()}?'LOL'~null()
    ifdef: mssql

  # Slicing
  - uri: /{head('OMGWTFBBQ'), head('OMGWTFBBQ',3), head('OMGWTFBBQ',-3)}
  - uri: /{tail('OMGWTFBBQ'), tail('OMGWTFBBQ',3), tail('OMGWTFBBQ',-3)}
  - uri: /{head('OMGWTFBBQ',0), tail('OMGWTFBBQ',0)}
  - uri: /{head(null()), tail(null()),
           head('OMGWTFBBQ',null()), tail('OMGWTFBBQ',null())}
  - uri: /{slice('OMGWTFBBQ',3,6), slice('OMGWTFBBQ',3,-3),
           slice('OMGWTFBBQ',-6,6), slice('OMGWTFBBQ',-6,-3)}
  - uri: /{slice('OMGWTFBBQ',0,0), slice('OMGWTFBBQ',6,3),
           slice('OMGWTFBBQ',10,13), slice('OMGWTFBBQ',-3,-6)}
  - uri: /{slice(null(),3,-3), slice('OMGWTGBBQ',null(),null()),
           slice('OMGWTFBBQ',-3,null()), slice('OMGWTFBBQ',null(),3)}
  - uri: /{at('OMGWTFBBQ',0), at('OMGWTFBBQ',3), at('OMGWTFBBQ',-3)}
  - uri: /{at('OMGWTFBBQ',3,3), at('OMGWTFBBQ',6,-3),
           at('OMGWTFBBQ',-3,3), at('OMGWTFBBQ',-12,6)}
  - uri: /{at('OMGWTFBBQ',10), at('OMGWTFBBQ',0,-3)}
  - uri: /{at(null(),3), at('OMGWTFBBQ',null(),3), at('OMGWTFBBQ',3,null())}

  # Transformations
  - uri: /{upper('lol'), lower('LOL')}
  - uri: /{trim('  LOL  '), ltrim('  LOL  '), rtrim('  LOL  ')}
  - uri: /{replace('OMGWTFBBQ','WTF','LOL')}
  - uri: /{replace('OMGWTFBBQ','wtf','LOL'),
           replace('OMGWTFBBQ','WTF','lol')}
    ifndef: mssql
  # `REPLACE` in MSSQL respects the database collation, which is
  # case-insensitive for the regression database.
  - uri: /{replace('OMGWTFBBQ','wtf','LOL')}
    ifdef: mssql
  - uri: /{replace('OMGWTFBBQ','WTF','lol')}
    ifdef: mssql
  - uri: /{replace('floccinaucinihilipilification','ili','LOL')}
  - uri: /{replace('OMGWTFBBQ','','LOL'),
           replace('OMGWTFBBQ','WTF','')}
  - uri: /{replace(null(),'WTF','LOL'),
           replace('OMGWTFBBQ',null(),'LOL'),
           replace('OMGWTFBBQ','WTF',null())}

########################################################################

- title: Date Functions and Operators
  tests:

  # Conversion
  - uri: /{date(null()), date('2010-04-15')}
  # Inadmissible operand
  - uri: /{date('2010-13-07')}
    expect: 400
  - uri: /{date(true())}
    expect: 400
  - uri: /{date(7)}
    expect: 400
  # Not a date
  - uri: /{date(string('birthday'))}
    expect: 409
    ignore: true
    ifdef: pgsql
  - uri: /{date(string('2010-13-07'))}
    expect: 409
    ignore: true
    ifdef: pgsql
  - uri: /{date(string('birthday')),
           date(string('2010-13-07'))}
    ifdef: [sqlite, mysql]

  # Construction
  - uri: /{today()}
    ignore: true
  - uri: /{date(2010,4,15), date(2010,3,46), date(2011,-8,15)}

  # Components
  - uri: /{year(date('2010-04-15')),
           month(date('2010-04-15')),
           day(date('2010-04-15'))}

  # Arithmetics
  - uri: /{date('1991-08-20')+6813,
           date('2010-04-15')-6813,
           date('2010-04-15')-date('1991-08-20')}

########################################################################

- title: Aggregate functions
  tests:

  # Exists, Every, Count
  - uri: /course?department='lang'
  - uri: /{exists(course?department='lang'),
           every(course?department='lang'),
           count(course?department='lang')}
  # Applied to an empty set
  - uri: /course?department='str'
  - uri: /{exists(course?department='str'),
           every(course?department='str'),
           count(course?department='str')}
  # Applied to all-TRUE, all-FALSE, mixed sets
  - uri: /course{department,no,credits,credits>3}
                ?department={'me','mth','phys'}
  - uri: /{exists(course{credits>3}?department='me'),
           every(course{credits>3}?department='me'),
           count(course{credits>3}?department='me')}
  - uri: /{exists(course{credits>3}?department='mth'),
           every(course{credits>3}?department='mth'),
           count(course{credits>3}?department='mth')}
  - uri: /{exists(course{credits>3}?department='phys'),
           every(course{credits>3}?department='phys'),
           count(course{credits>3}?department='phys')}
  # Coercion
  - uri: /department{code,school,boolean(school)}
  - uri: /{exists(department{school}),
           every(department{school}),
           count(department{school})}
  # Singular operand
  - uri: /{exists(true())}
    expect: 400
  - uri: /{every(true())}
    expect: 400
  - uri: /{count(true())}
    expect: 400

  # Min, Max
  - uri: /course{no,credits}?department='be'
  - uri: /{min(course{credits}?department='be'),
           max(course{credits}?department='be')}
  # Applied to an empty set
  - uri: /course?department='str'
  - uri: /{min(course{credits}?department='str'),
           max(course{credits}?department='str')}
  # Non-numeric operands
  - uri: /{min(student.dob), max(student.dob)}
  - uri: /{min(student.name), max(student.name)}
  # Inadmissible operand
  - uri: /{min(student.is_active), max(student.is_active)}
    expect: 400

  # Sum, Avg
  - uri: /{sum(course{credits}?department='be'),
           count(course{credits}?department='be'),
           avg(course{credits}?department='be')}
  # Applied to an empty set
  - uri: /{sum(course{credits}?department='str'),
           count(course{credits}?department='str'),
           avg(course{credits}?department='str')}
  # Inadmissible operands
  - uri: /{sum(student.dob)}
    expect: 400
  - uri: /{avg(student.name)}
    expect: 400

########################################################################

- title: Table functions and operators
  tests:

  # Joining
  # 1 - N
  - uri: /school.program
  - uri: /school.department
  # N - 1
  - uri: /program.school
  - uri: /department.school
  # 1 - 1
  - uri: /instructor.confidential
  - uri: /confidential.instructor
  # Cross join
  - uri: /school.fiber(school)
  # Fiber join
  - uri: /department.fiber(program,school)
  - uri: /classification.fiber(classification,code,part_of)
            {part_of, code}
  # Context
  - uri: /school.fiber(school){root().school.code, this().code}
  # Invalid link
  - uri: /student.instructor
    expect: 400

  # Filtering
  - uri: /school?code='mus'
  - uri: /student?!is_active
  # Coercion
  - uri: /department?school

  # Sorting
  - uri: /department.sort(name)
  - uri: /department.sort(name+)
  - uri: /department.sort(name-)
  # NULL
  - uri: /department.sort(school+)
  - uri: /department.sort(school-)
  # Combined with joining
  - uri: /school.department.sort(code+)
  - uri: /school.sort(code+).department.sort(code+)
  # Multiple arguments
  - uri: /course.sort(credits-,no+)?department='stdart'

  # Limiting
  - uri: /course.limit(9)
  - uri: /course.limit(3,6)
  # Combined with sort
  - uri: /course.sort(credits+).limit(9)
  - uri: /course.limit(9).sort(credits+)
  - uri: /course.sort(credits-).limit(9).sort(no-)

  # Selecting
  - uri: /school{name}
  - uri: /department{school.name, name}
  - uri: /school{*}
  - uri: /department{school.*, *}

########################################################################

- title: Decorators
  tests:

  # AS decorator
  - uri: /(school :as 'List of Schools')
  - uri: /school{name :as Name}
  - uri: /(school :as 'List of Schools')
            {name :as Name, count(department) :as '# of Departments'}

  # Direction decorator
  - uri: /school{name+}
  - uri: /course{credits-, no+, title}?department='stdart'