File: sql_code_sparql_init.c

package info (click to toggle)
virtuoso-opensource 6.1.6+dfsg2-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 260,992 kB
  • ctags: 125,220
  • sloc: ansic: 652,748; sql: 458,419; xml: 282,834; java: 61,031; sh: 40,031; cpp: 36,890; cs: 25,240; php: 12,692; yacc: 9,523; lex: 7,018; makefile: 6,157; jsp: 4,484; awk: 1,643; perl: 1,013; ruby: 1,003; python: 326
file content (1462 lines) | stat: -rw-r--r-- 45,076 bytes parent folder | download | duplicates (2)
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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
/* This file is automatically generated by sql_to_c.awk */

#include "sqlnode.h"
#include "sqlfn.h"
#include "sqltype.h"

/* useraggr.sql */

static const char *proc0 = 
"#line 24 \"[executable]/useraggr.sql\"\n"
" create procedure STD_COUNT (in _env varchar)\n"
"{\n"
"return aref (deserialize(_env), 0);\n"
"}\n"
"--src useraggr.sql:22\n";

static const char *proc1 = 
"#line 31 \"[executable]/useraggr.sql\"\n"
" create procedure STD11_INIT (inout _env varchar)\n"
"{\n"
"_env := serialize (vector (0, 0.0));\n"
"}\n"
"--src useraggr.sql:29\n";

static const char *proc2 = 
"#line 38 \"[executable]/useraggr.sql\"\n"
" create procedure STD12_INIT (inout _env varchar)\n"
"{\n"
"_env := serialize (vector (0, 0.0,0.0));\n"
"}\n"
"--src useraggr.sql:36\n";

static const char *proc3 = 
"#line 45 \"[executable]/useraggr.sql\"\n"
" create procedure STD13_INIT (inout _env varchar)\n"
"{\n"
"_env := serialize (vector (0, 0.0,0.0, 0.0));\n"
"}\n"
"--src useraggr.sql:43\n";

static const char *proc4 = 
"#line 52 \"[executable]/useraggr.sql\"\n"
" create procedure VAR_ACC (inout _env varchar, in val numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if (val is null)\n"
"return;\n"
"declare ctx any;\n"
"ctx := deserialize (_env);\n"
"\n"
"aset( ctx, 1, aref (ctx, 1) + val);\n"
"aset( ctx, 2, aref (ctx, 2) + val*val);\n"
"aset( ctx, 0, aref (ctx, 0) + 1);\n"
"_env := serialize (ctx);\n"
"}\n"
"--src useraggr.sql:50\n";

static const char *proc5 = 
"#line 69 \"[executable]/useraggr.sql\"\n"
" create procedure VAR_POP_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"declare _env any;\n"
"_env := deserialize (_ctx);\n"
"declare c integer;\n"
"c := aref (_env, 0);\n"
"if (c = 0)\n"
"return null;\n"
"return  (aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / c;\n"
"}\n"
"--src useraggr.sql:67\n";

static const char *proc6 = 
"#line 84 \"[executable]/useraggr.sql\"\n"
" create procedure VAR_SAMP_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"declare _env any;\n"
"_env := deserialize (_ctx);\n"
"declare c integer;\n"
"c := aref (_env, 0);\n"
"if (c = 0)\n"
"return null;\n"
"if (c = 1)\n"
"return 0.0;\n"
"return  (aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / (c - 1);\n"
"}\n"
"--src useraggr.sql:82\n";

static const char *proc7 = 
"#line 101 \"[executable]/useraggr.sql\"\n"
" create procedure VAR_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"if (STD_COUNT (_ctx) = 1)\n"
"return null;\n"
"return VAR_SAMP_FIN (_ctx);\n"
"}\n"
"--src useraggr.sql:99\n";

static const char *proc8 = 
"#line 112 \"[executable]/useraggr.sql\"\n"
" create procedure STDDEV_POP_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"declare c integer;\n"
"declare _env any;\n"
"_env := deserialize (_ctx);\n"
"c := aref (_env, 0);\n"
"if (c = 0)\n"
"return null;\n"
"\n"
"return  sqrt ((aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / c) ;\n"
"}\n"
"--src useraggr.sql:110\n";

static const char *proc9 = 
"#line 128 \"[executable]/useraggr.sql\"\n"
" create procedure STDDEV_SAMP_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"declare c integer;\n"
"declare _env any;\n"
"_env := deserialize (_ctx);\n"
"c := aref (_env, 0);\n"
"if (c = 0)\n"
"return null;\n"
"if (c = 1)\n"
"return 0.0;\n"
"return  sqrt ((aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / ( c - 1));\n"
"}\n"
"--src useraggr.sql:126\n";

static const char *proc10 = 
"#line 145 \"[executable]/useraggr.sql\"\n"
" create procedure STDDEV_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"if (STD_COUNT (_ctx) = 1)\n"
"return null;\n"
"return STDDEV_SAMP_FIN (_ctx);\n"
"}\n"
"--src useraggr.sql:143\n";

static const char *proc11 = 
"#line 156 \"[executable]/useraggr.sql\"\n"
" create procedure COVAR_ACC (inout _ctx any,\n"
"in expr1 numeric,\n"
"in expr2 numeric)\n"
"{\n"
"if (_ctx is null)\n"
"return;\n"
"if (expr1 is null or expr2 is null)\n"
"return;\n"
"\n"
"declare _env any;\n"
"\n"
"_env := deserialize (_ctx);\n"
"\n"
"aset (_env, 1, aref (_env,1)+expr1);\n"
"aset (_env, 2, aref (_env,2)+expr2);\n"
"aset (_env, 3, aref (_env,3)+expr2*expr1);\n"
"aset (_env, 0, aref (_env,0)+1);\n"
"\n"
"_ctx := serialize (_env);\n"
"}\n"
"--src useraggr.sql:154\n";

static const char *proc12 = 
"#line 179 \"[executable]/useraggr.sql\"\n"
" create procedure COVAR_SAMP_FIN (inout _ctx any)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"declare _env any;\n"
"_env := deserialize (_ctx);\n"
"if (aref (_env, 0) = 0)\n"
"return null;\n"
"if (aref (_env, 0) = 1)\n"
"return 0.0;\n"
"\n"
"return (aref (_env, 3) - aref(_env,2) * aref (_env,1) / aref (_env, 0)) / ( aref (_env, 0) - 1);\n"
"}\n"
"--src useraggr.sql:177\n";

static const char *proc13 = 
"#line 195 \"[executable]/useraggr.sql\"\n"
" create procedure COVAR_POP_FIN (inout _ctx any)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"declare _env any;\n"
"_env := deserialize (_ctx);\n"
"if (aref (_env, 0) = 0)\n"
"return null;\n"
"if (aref (_env, 0) = 1)\n"
"return 0.0;\n"
"\n"
"return (aref (_env, 3) - aref(_env,2) * aref (_env,1) / aref (_env, 0))/ aref (_env,0);\n"
"}\n"
"--src useraggr.sql:193\n";

static const char *proc14 = 
"#line 211 \"[executable]/useraggr.sql\"\n"
" create procedure COVAR_FIN (inout _ctx varchar)\n"
"{\n"
"if (_ctx is null)\n"
"return null;\n"
"if (STD_COUNT (_ctx) = 1)\n"
"return null;\n"
"return COVAR_SAMP_FIN (_ctx);\n"
"}\n"
"--src useraggr.sql:209\n";

static const char *other0 = 
"create aggregate DB.DBA.VAR_POP (in val numeric) returns numeric from\n"
"STD12_INIT, VAR_ACC, VAR_POP_FIN\n";

static const char *other1 = 
"create aggregate DB.DBA.VAR_SAMP (in val numeric) returns numeric from\n"
"STD12_INIT, VAR_ACC, VAR_SAMP_FIN\n";

static const char *other2 = 
"create aggregate DB.DBA.VAR (in val numeric) returns numeric from\n"
"STD12_INIT, VAR_ACC, VAR_FIN\n";

static const char *other3 = 
"create aggregate DB.DBA.STDDEV_POP (in val numeric) returns numeric from\n"
"STD12_INIT, VAR_ACC, STDDEV_POP_FIN\n";

static const char *other4 = 
"create aggregate DB.DBA.STDDEV_SAMP (in val numeric) returns numeric from\n"
"STD12_INIT, VAR_ACC, STDDEV_SAMP_FIN\n";

static const char *other5 = 
"create aggregate DB.DBA.STDDEV (in val numeric) returns numeric from\n"
"STD12_INIT, VAR_ACC, STDDEV_FIN\n";

static const char *other6 = 
"create aggregate DB.DBA.COVAR_SAMP (in expr1 numeric, in expr2 numeric) returns numeric from\n"
"STD13_INIT, COVAR_ACC, COVAR_SAMP_FIN\n";

static const char *other7 = 
"create aggregate DB.DBA.COVAR_POP (in expr1 numeric, in expr2 numeric) returns numeric from\n"
"STD13_INIT, COVAR_ACC, COVAR_POP_FIN\n";

static const char *other8 = 
"create aggregate DB.DBA.COVAR (in expr1 numeric, in expr2 numeric) returns numeric from\n"
"STD13_INIT, COVAR_ACC, COVAR_FIN\n";

static const char *proc15 = 
"#line 250 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SLOPE_INIT (inout _env varchar)\n"
"{\n"
"declare _ctx1 varchar;\n"
"declare _ctx2 varchar;\n"
"\n"
"STD13_INIT (_ctx1);\n"
"STD12_INIT (_ctx2);\n"
"\n"
"_env := serialize (vector (0, _ctx1, _ctx2));\n"
"}\n"
"--src useraggr.sql:248\n";

static const char *proc16 = 
"#line 263 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SLOPE_ACC (inout _env varchar, in expr1 numeric, in expr2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if ( (expr1 is null) or (expr2 is null))\n"
"return;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _ctx1 varchar;\n"
"declare _ctx2 varchar;\n"
"\n"
"_ctx1 := aref (_ctx, 1);\n"
"_ctx2 := aref (_ctx, 2);\n"
"\n"
"aset (_ctx, 0, aref (_ctx,0) + 1);\n"
"COVAR_ACC (_ctx1, expr1, expr2);\n"
"VAR_ACC (_ctx2, expr2);\n"
"\n"
"aset (_ctx, 1, _ctx1);\n"
"aset (_ctx, 2, _ctx2);\n"
"\n"
"_env := serialize (_ctx);\n"
"}\n"
"--src useraggr.sql:261\n";

static const char *proc17 = 
"#line 290 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SLOPE_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"declare c integer;\n"
"\n"
"_ctx := deserialize (_env);\n"
"\n"
"c := aref (_ctx, 0);\n"
"if (c = 0)\n"
"return 0;\n"
"if (c = 1)\n"
"return null;\n"
"\n"
"declare _ctx1 varchar;\n"
"declare _ctx2 varchar;\n"
"declare covar_pop_val numeric;\n"
"declare var_pop_val numeric;\n"
"\n"
"_ctx1 := aref (_ctx, 1);\n"
"_ctx2 := aref (_ctx, 2);\n"
"\n"
"\n"
"covar_pop_val := COVAR_POP_FIN (_ctx1);\n"
"var_pop_val := VAR_POP_FIN (_ctx2);\n"
"\n"
"if (var_pop_val = 0)\n"
"return null;\n"
"return covar_pop_val / var_pop_val;\n"
"}\n"
"--src useraggr.sql:288\n";

static const char *other9 = 
"create aggregate DB.DBA.REGR_SLOPE (in expr1 numeric, in expr2 numeric) returns numeric from REGR_SLOPE_INIT, REGR_SLOPE_ACC, REGR_SLOPE_FIN\n";

static const char *proc18 = 
"#line 327 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_INTERCEPT_INIT (inout _env varchar)\n"
"{\n"
"declare _ctx_regr_slope varchar;\n"
"\n"
"REGR_SLOPE_INIT (_ctx_regr_slope);\n"
"_env := serialize (vector (0, 0.0, 0.0, _ctx_regr_slope));\n"
"}\n"
"--src useraggr.sql:325\n";

static const char *proc19 = 
"#line 337 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_INTERCEPT_ACC (inout _env varchar, in expr1 numeric, in expr2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if ((expr1 is null) or (expr2 is null))\n"
"return;\n"
"\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"aset (_ctx, 0, aref (_ctx, 0) + 1);\n"
"aset (_ctx, 1, aref (_ctx, 1) + expr1);\n"
"aset (_ctx, 2, aref (_ctx, 2) + expr2);\n"
"\n"
"declare _ctx_r varchar;\n"
"_ctx_r := aref (_ctx, 3);\n"
"REGR_SLOPE_ACC (_ctx_r, expr1, expr2);\n"
"aset (_ctx, 3, _ctx_r);\n"
"\n"
"_env := serialize (_ctx);\n"
"}\n"
"--src useraggr.sql:335\n";

static const char *proc20 = 
"#line 361 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_INTERCEPT_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"declare c integer;\n"
"c := aref (_ctx, 0);\n"
"if ((c = 0) or (c = 1))\n"
"return null;\n"
"\n"
"return aref (_ctx, 1) / c - REGR_SLOPE_FIN (aref (_ctx, 3)) * aref (_ctx, 2) / c;\n"
"}\n"
"--src useraggr.sql:359\n";

static const char *other10 = 
"create aggregate DB.DBA.REGR_INTERCEPT (in expr1 numeric, in expr2 numeric) returns numeric from REGR_INTERCEPT_INIT, REGR_INTERCEPT_ACC, REGR_INTERCEPT_FIN\n";

static const char *proc21 = 
"#line 380 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_COUNT_INIT (inout _env integer)\n"
"{\n"
"_env := 0;\n"
"}\n"
"--src useraggr.sql:378\n";

static const char *proc22 = 
"#line 387 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_COUNT_ACC (inout _env integer, in expr numeric, in expr2 numeric)\n"
"{\n"
"if ((_env is null) or (expr is null) or (expr2 is null))\n"
"return;\n"
"_env := _env + 1;\n"
"}\n"
"--src useraggr.sql:385\n";

static const char *proc23 = 
"#line 396 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_COUNT_FIN (inout _env integer)\n"
"{\n"
"return _env;\n"
"}\n"
"--src useraggr.sql:394\n";

static const char *proc24 = 
"#line 403 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_COUNT_MERGE (inout _e1 integer, inout _e2 integer)\n"
"{\n"
"_e1 := _e1 + _e2;\n"
"}\n"
"--src useraggr.sql:401\n";

static const char *other11 = 
"create aggregate DB.DBA.REGR_COUNT (in expr1 numeric, in expr2 numeric) returns numeric from REGR_COUNT_INIT, REGR_COUNT_ACC, REGR_COUNT_FIN, REGR_COUNT_MERGE\n";

static const char *proc25 = 
"#line 413 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_AVG_ACC (inout _env varchar, in expr1 numeric, in expr2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"\n"
"if ( (expr1 is null) or (expr2 is null))\n"
"return;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"aset (_ctx, 0, aref (_ctx, 0) + 1);\n"
"aset (_ctx, 1, aref (_ctx, 1) + expr1);\n"
"aset (_ctx, 2, aref (_ctx, 2) + expr2);\n"
"\n"
"_env := serialize (_ctx);\n"
"}\n"
"--src useraggr.sql:411\n";

static const char *proc26 = 
"#line 432 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_AVGX_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"if (aref (_ctx, 0) = 0)\n"
"return null;\n"
"return aref (_ctx, 1) / aref (_ctx,0);\n"
"}\n"
"--src useraggr.sql:430\n";

static const char *proc27 = 
"#line 445 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_AVGY_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"if (aref (_ctx, 0) = 0)\n"
"return null;\n"
"return aref (_ctx, 2) / aref (_ctx,0);\n"
"}\n"
"--src useraggr.sql:443\n";

static const char *other12 = 
"create aggregate DB.DBA.REGR_AVGX (in x numeric, in y numeric) returns numeric from\n"
"STD12_INIT, REGR_AVG_ACC, REGR_AVGX_FIN\n";

static const char *other13 = 
"create aggregate DB.DBA.REGR_AVGY (in x numeric, in y numeric) returns numeric from\n"
"STD12_INIT, REGR_AVG_ACC, REGR_AVGY_FIN\n";

static const char *proc28 = 
"#line 466 \"[executable]/useraggr.sql\"\n"
" create procedure CORR_INIT (inout _env varchar)\n"
"{\n"
"declare _ctx_cov varchar;\n"
"declare _ctx_stdev1 varchar;\n"
"declare _ctx_stdev2 varchar;\n"
"\n"
"STD13_INIT (_ctx_cov);\n"
"STD12_INIT (_ctx_stdev1);\n"
"STD12_INIT (_ctx_stdev2);\n"
"\n"
"_env := serialize (vector (0, _ctx_cov, _ctx_stdev1, _ctx_stdev2));\n"
"}\n"
"--src useraggr.sql:464\n";

static const char *proc29 = 
"#line 481 \"[executable]/useraggr.sql\"\n"
" create procedure CORR_ACC (inout _env varchar, in e1 numeric, in e2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if ((e1 is null) or (e2 is null))\n"
"return;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _ctx_cov varchar;\n"
"declare _ctx_stdev1 varchar;\n"
"declare _ctx_stdev2 varchar;\n"
"\n"
"_ctx_cov := aref (_ctx, 1);\n"
"_ctx_stdev1 := aref (_ctx, 2);\n"
"_ctx_stdev2 := aref (_ctx, 3);\n"
"\n"
"COVAR_ACC (_ctx_cov, e1, e2);\n"
"VAR_ACC (_ctx_stdev1, e1);\n"
"VAR_ACC (_ctx_stdev2, e2);\n"
"\n"
"aset (_ctx, 0, aref (_ctx, 0) + 1);\n"
"aset (_ctx, 1, _ctx_cov);\n"
"aset (_ctx, 2, _ctx_stdev1);\n"
"aset (_ctx, 3, _ctx_stdev2);\n"
"\n"
"_env := serialize (_ctx);\n"
"}\n"
"--src useraggr.sql:479\n";

static const char *proc30 = 
"#line 512 \"[executable]/useraggr.sql\"\n"
" create procedure CORR_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _ctx_cov_val numeric;\n"
"declare _ctx_stdev1_val numeric;\n"
"declare _ctx_stdev2_val numeric;\n"
"\n"
"_ctx_cov_val := COVAR_POP_FIN (aref (_ctx, 1));\n"
"_ctx_stdev1_val := STDDEV_POP_FIN (aref (_ctx, 2));\n"
"_ctx_stdev2_val := STDDEV_POP_FIN (aref (_ctx, 3));\n"
"\n"
"if (_ctx_cov_val is null)\n"
"return null;\n"
"if (_ctx_stdev1_val is null or _ctx_stdev1_val = 0)\n"
"return null;\n"
"if (_ctx_stdev2_val is null or _ctx_stdev2_val = 0)\n"
"return null;\n"
"\n"
"return _ctx_cov_val / _ctx_stdev1_val / _ctx_stdev2_val;\n"
"}\n"
"--src useraggr.sql:510\n";

static const char *other14 = 
"create aggregate DB.DBA.CORR (in x numeric, in y numeric) returns numeric from\n"
"CORR_INIT, CORR_ACC, CORR_FIN\n";

static const char *proc31 = 
"#line 543 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_R2_INIT (inout _env varchar)\n"
"{\n"
"declare _ctx_vp1 varchar;\n"
"declare _ctx_vp2 varchar;\n"
"declare _ctx_corr varchar;\n"
"\n"
"STD12_INIT (_ctx_vp1);\n"
"STD12_INIT (_ctx_vp2);\n"
"CORR_INIT (_ctx_corr);\n"
"\n"
"_env := serialize (vector (_ctx_vp1, _ctx_vp2, _ctx_corr));\n"
"}\n"
"--src useraggr.sql:541\n";

static const char *proc32 = 
"#line 558 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_R2_ACC (inout _env varchar, in e1 numeric, in e2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if (e1 is null or e2 is null)\n"
"return;\n"
"declare _ctx  any;\n"
"\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _ctx_vp1 varchar;\n"
"declare _ctx_vp2 varchar;\n"
"declare _ctx_corr varchar;\n"
"\n"
"_ctx_vp1 := aref (_ctx, 0);\n"
"_ctx_vp2 := aref (_ctx, 1);\n"
"_ctx_corr := aref (_ctx, 2);\n"
"\n"
"VAR_ACC (_ctx_vp1, e1);\n"
"VAR_ACC (_ctx_vp2, e2);\n"
"CORR_ACC (_ctx_corr, e1, e2);\n"
"\n"
"aset (_ctx, 0, _ctx_vp1);\n"
"aset (_ctx, 1, _ctx_vp2);\n"
"aset (_ctx, 2, _ctx_corr);\n"
"\n"
"_env := serialize (_ctx);\n"
"}\n"
"--src useraggr.sql:556\n";

static const char *proc33 = 
"#line 589 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_R2_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _vp1 numeric;\n"
"declare _vp2 numeric;\n"
"declare _corr numeric;\n"
"\n"
"_vp2 := VAR_POP_FIN (aref(_ctx, 1));\n"
"if (_vp2 is null or _vp2 = 0)\n"
"return null;\n"
"_vp1 := VAR_POP_FIN (aref(_ctx, 0));\n"
"if (_vp1 is null or _vp1 = 0)\n"
"return 1;\n"
"_corr := CORR_FIN (aref (_ctx, 2));\n"
"return _corr * _corr;\n"
"}\n"
"--src useraggr.sql:587\n";

static const char *other15 = 
"create aggregate DB.DBA.REGR_R2 (in e1 numeric, in e2 numeric) returns numeric from\n"
"REGR_R2_INIT, REGR_R2_ACC, REGR_R2_FIN\n";

static const char *proc34 = 
"#line 617 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SXX_ACC (inout _env varchar, in e1 numeric, in e2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if (e1 is null or e2 is null)\n"
"return;\n"
"\n"
"VAR_ACC (_env, e2);\n"
"}\n"
"--src useraggr.sql:615\n";

static const char *proc35 = 
"#line 629 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SYY_ACC (inout _env varchar, in e1 numeric, in e2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if (e1 is null or e2 is null)\n"
"return;\n"
"\n"
"VAR_ACC (_env, e1);\n"
"}\n"
"--src useraggr.sql:627\n";

static const char *proc36 = 
"#line 641 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SXY_ACC (inout _env varchar, in e1 numeric, in e2 numeric)\n"
"{\n"
"if (_env is null)\n"
"return;\n"
"if (e1 is null or e2 is null)\n"
"return;\n"
"\n"
"COVAR_ACC (_env, e1, e2);\n"
"}\n"
"--src useraggr.sql:639\n";

static const char *proc37 = 
"#line 653 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_S___FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _var numeric;\n"
"\n"
"_var := VAR_POP_FIN (_env);\n"
"if (_var is null)\n"
"return null;\n"
"return aref (_ctx,0) * _var;\n"
"}\n"
"--src useraggr.sql:651\n";

static const char *proc38 = 
"#line 670 \"[executable]/useraggr.sql\"\n"
" create procedure REGR_SXY_FIN (inout _env varchar)\n"
"{\n"
"if (_env is null)\n"
"return null;\n"
"declare _ctx any;\n"
"_ctx := deserialize (_env);\n"
"\n"
"declare _var numeric;\n"
"\n"
"_var := COVAR_POP_FIN (_env);\n"
"if (_var is null)\n"
"return null;\n"
"return aref (_ctx,0) * _var;\n"
"}\n"
"--src useraggr.sql:668\n";

static const char *other16 = 
"create aggregate DB.DBA.REGR_SXX (in e1 numeric, in e2 numeric) returns numeric from\n"
"STD12_INIT, REGR_SXX_ACC, REGR_S___FIN\n";

static const char *other17 = 
"create aggregate DB.DBA.REGR_SYY (in e1 numeric, in e2 numeric) returns numeric from\n"
"STD12_INIT, REGR_SYY_ACC, REGR_S___FIN\n";

static const char *other18 = 
"create aggregate DB.DBA.REGR_SXY (in e1 numeric, in e2 numeric) returns numeric from\n"
"STD13_INIT, REGR_SXY_ACC, REGR_SXY_FIN\n";

static const char *proc39 = 
"#line 699 \"[executable]/useraggr.sql\"\n"
" create procedure xte_nodebld_final_root (in acc any) returns any\n"
"{\n"
"return xte_nodebld_xmlagg_final (acc, xte_head (UNAME\' root\'));\n"
"}\n"
"--src useraggr.sql:697\n";

static const char *other19 = 
"create aggregate DB.DBA.XMLAGG (in _child any) returns any\n"
"from xte_nodebld_init, xte_nodebld_xmlagg_acc, xte_nodebld_final_root\n";

static const char *other20 = 
"create aggregate DB.DBA.VECTOR_AGG (in _child any) returns any\n"
"from vectorbld_init, vectorbld_agg_acc, vectorbld_agg_final\n"
"order\n";

static const char *other21 = 
"create aggregate DB.DBA.VECTOR_OF_NONNULLS_AGG (in _child any) returns any\n"
"from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vectorbld_agg_final\n"
"order\n";

static const char *other22 = 
"create aggregate DB.DBA.VECTOR_OR_NULL_AGG (in _child any) returns any\n"
"from vectorbld_init, vectorbld_agg_acc, vector_or_null_bld_agg_final\n"
"order\n";

static const char *other23 = 
"create aggregate DB.DBA.VECTOR_OF_NONNULLS_OR_NULL_AGG (in _child any) returns any\n"
"from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vector_or_null_bld_agg_final\n"
"order\n";

static const char *other24 = 
"create aggregate DB.DBA.VECTOR_CONCAT_AGG (in _child any) returns any\n"
"from vectorbld_init, vectorbld_concat_agg_acc, vectorbld_agg_final\n"
"order\n";

static const char *other25 = 
"create aggregate DB.DBA.XQ_SEQUENCE_AGG (in _child any) returns any\n"
"from xq_sequencebld_init, xq_sequencebld_agg_acc, xq_sequencebld_agg_final\n"
"order\n";

static const char *other26 = 
"create aggregate DB.DBA.BAG_AGG (in _child any) returns any\n"
"from vectorbld_init, vectorbld_agg_acc, vectorbld_agg_final\n";

static const char *other27 = 
"create aggregate DB.DBA.BAG_OF_NONNULLS_AGG (in _child any) returns any\n"
"from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vectorbld_agg_final\n";

static const char *other28 = 
"create aggregate DB.DBA.BAG_OR_NULL_AGG (in _child any) returns any\n"
"from vectorbld_init, vectorbld_agg_acc, vector_or_null_bld_agg_final\n";

static const char *other29 = 
"create aggregate DB.DBA.BAG_OF_NONNULLS_OR_NULL_AGG (in _child any) returns any\n"
"from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vector_or_null_bld_agg_final\n";

static const char *other30 = 
"create aggregate DB.DBA.BAG_CONCAT_AGG (in _child any) returns any\n"
"from vectorbld_init, vectorbld_concat_agg_acc, vectorbld_agg_final\n";

static const char *proc40 = 
"#line 762 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.GROUP_CONCAT_INIT (inout _env any)\n"
"{\n"
"_env := 0;\n"
"}\n"
"--src useraggr.sql:760\n";

static const char *proc41 = 
"#line 769 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.GROUP_CONCAT_ACC (inout _env any, in token varchar, in delim varchar)\n"
"{\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"if (__tag of varchar <> __tag (_env))\n"
"_env := cast (token as varchar);\n"
"else if (delim is not null)\n"
"_env := concat (_env, cast (delim as varchar), cast (token as varchar));\n"
"else\n"
"_env := concat (_env, cast (token as varchar));\n"
"}\n"
"--src useraggr.sql:767\n";

static const char *proc42 = 
"#line 786 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.GROUP_CONCAT_FIN (inout _env any)\n"
"{\n"
"\n"
"\n"
"\n"
"if (__tag of varchar <> __tag (_env))\n"
"return \'\';\n"
"return _env;\n"
"}\n"
"--src useraggr.sql:784\n";

static const char *other31 = 
"create aggregate DB.DBA.GROUP_CONCAT (in token varchar, in delim varchar) returns varchar\n"
"from DB.DBA.GROUP_CONCAT_INIT, DB.DBA.GROUP_CONCAT_ACC, DB.DBA.GROUP_CONCAT_FIN\n"
"order\n";

static const char *proc43 = 
"#line 804 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.GROUP_DIGEST_INIT (inout _env any)\n"
"{\n"
"_env := 0;\n"
"}\n"
"--src useraggr.sql:802\n";

static const char *proc44 = 
"#line 811 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.GROUP_DIGEST_ACC (inout _env any, in token varchar, in delim varchar, in maxlen integer, in mode integer)\n"
"{\n"
"declare curlen integer;\n"
"declare env_vec, items any;\n"
"if (__tag of varchar <> __tag (token))\n"
"{\n"
"token := cast (token as varchar);\n"
"if (token is null)\n"
"return;\n"
"}\n"
"if (__tag of varchar <> __tag (_env))\n"
"{\n"
"if (length (token) > maxlen)\n"
"token := subseq (token, 0, maxlen+1);\n"
"_env := serialize (vector_zap_args (vector_zap_args (token), cast (delim as varchar), maxlen));\n"
"return;\n"
"}\n"
"curlen := length (_env);\n"
"if (curlen >= maxlen)\n"
"return;\n"
"env_vec := deserialize (_env);\n"
"items := aref_set_0 (env_vec, 0);\n"
"if (bit_and (mode, 1))\n"
"{\n"
"if (0 < position (token, items))\n"
"return;\n"
"}\n"
"if (length (token) > (env_vec[2] - curlen))\n"
"token := subseq (token, 0, (env_vec[2] - curlen)+1);\n"
"items := vector_concat (items, vector_zap_args (token));\n"
"aset_zap_arg (env_vec, 0, items);\n"
"_env := serialize (env_vec);\n"
"}\n"
"--src useraggr.sql:809\n";

static const char *proc45 = 
"#line 847 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.GROUP_DIGEST_FIN (inout _env any)\n"
"{\n"
"declare envlen, curlen, maxlen, itemctr, itemcount, delim_len, rest_len integer;\n"
"declare env_vec, items, ses any;\n"
"declare delim varchar;\n"
"if (__tag of varchar <> __tag (_env))\n"
"return \'\';\n"
"envlen := length (_env);\n"
"env_vec := deserialize (_env);\n"
"items := aref_set_0 (env_vec, 0);\n"
"delim := aref_set_0 (env_vec, 1);\n"
"rest_len := maxlen := aref_set_0 (env_vec, 2);\n"
"ses := string_output ();\n"
"itemctr := 0;\n"
"itemcount := length (items);\n"
"delim_len := length (delim);\n"
"for (itemctr := 0; itemctr < itemcount; itemctr := itemctr + 1)\n"
"{\n"
"declare itm varchar;\n"
"declare itm_len integer;\n"
"if (delim_len > (rest_len-5))\n"
"goto items_done;\n"
"if (itemctr)\n"
"{\n"
"http (delim, ses);\n"
"rest_len := rest_len - delim_len;\n"
"}\n"
"itm := items [itemctr];\n"
"itm_len := length (itm);\n"
"if ((itm_len > rest_len) or ((envlen > maxlen) and (itemctr = itemcount-1)))\n"
"{\n"
"itm := subseq (itm, 0, rest_len);\n"
"itm_len := coalesce (__max_notnull (strrchr (itm, 32), strrchr (itm, 10), strrchr (itm, 13)), 0);\n"
"while ((itm_len > 0) and (itm [itm_len-1] in (32, 10, 13)))\n"
"itm_len := itm_len - 1;\n"
"if (0 = itm_len)\n"
"http (subseq (itm, 0, rest_len-3), ses);\n"
"else\n"
"http (subseq (itm, 0, itm_len), ses);\n"
"http (\'...\', ses);\n"
"goto items_done;\n"
"}\n"
"http (itm, ses);\n"
"rest_len := rest_len - itm_len;\n"
"}\n"
"items_done:\n"
"return string_output_string (ses);\n"
"}\n"
"--src useraggr.sql:845\n";

static const char *other32 = 
"create aggregate DB.DBA.GROUP_DIGEST (in token varchar, in delim varchar, in maxlen integer, in mode integer) returns varchar\n"
"from DB.DBA.GROUP_DIGEST_INIT, DB.DBA.GROUP_DIGEST_ACC, DB.DBA.GROUP_DIGEST_FIN\n"
"order\n";

static const char *proc46 = 
"#line 904 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.SAMPLE_INIT (inout _env any)\n"
"{\n"
"_env := null;\n"
"}\n"
"--src useraggr.sql:902\n";

static const char *proc47 = 
"#line 911 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.SAMPLE_ACC (inout _env any, in sample any)\n"
"{\n"
"if (_env is not null)\n"
"return;\n"
"_env := sample;\n"
"}\n"
"--src useraggr.sql:909\n";

static const char *proc48 = 
"#line 920 \"[executable]/useraggr.sql\"\n"
" create procedure DB.DBA.SAMPLE_FIN (inout _env any)\n"
"{\n"
"return _env;\n"
"}\n"
"--src useraggr.sql:918\n";

static const char *other33 = 
"create aggregate DB.DBA.SAMPLE (in sample any) returns any\n"
"from DB.DBA.SAMPLE_INIT, DB.DBA.SAMPLE_ACC, DB.DBA.SAMPLE_FIN\n"
"order\n";

/* sparql_init.sql */

static const char *proc49 = 
"#line 24 \"[executable]/sparql_init.sql\"\n"
"create function DB.DBA.RDF_LANGUAGE_OF_LONG (in longobj any, in dflt varchar := \'\') returns any\n"
"{\n"
"if (__tag of rdf_box = __tag (longobj))\n"
"{\n"
"declare twobyte integer;\n"
"declare res varchar;\n"
"twobyte := rdf_box_lang (longobj);\n"
"if (257 = twobyte)\n"
"return dflt;\n"
"whenever not found goto badlang;\n"
"select lower (RL_ID) into res from DB.DBA.RDF_LANGUAGE where RL_TWOBYTE = twobyte;\n"
"return res;\n"
"\n"
"badlang:\n"
"signal (\'RDFXX\', sprintf (\'Unknown language in DB.DBA.RDF_LANGUAGE_OF_LONG, bad id %d\', twobyte));\n"
"}\n"
"return case (isiri_id (longobj)) when 0 then dflt else null end;\n"
"}\n"
"--src sparql_init.sql:22\n";

static const char *proc50 = 
"#line 47 \"[executable]/sparql_init.sql\"\n"
"create function DB.DBA.JSO_MAKE_INHERITANCE (in jgraph varchar, in class varchar, in rootinst varchar, in destinst varchar, in dest_iid iri_id, inout noinherits any, inout inh_stack any)\n"
"{\n"
"declare base_iid iri_id;\n"
"declare baseinst varchar;\n"
"\n"
"inh_stack := vector_concat (inh_stack, vector (destinst));\n"
"baseinst := null;\n"
"if (not exists (sparql\n"
"define input:storage \"\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"ask where {\n"
"graph ?:jgraph { ?:dest_iid rdf:type `iri(?:class)`\n"
"} } ) )\n"
"signal (\'22023\', \'JSO_MAKE_INHERITANCE has not found object <\' || destinst || \'> of type <\' || class || \'>\');\n"
"/* This fails. !!!TBD: fix sparql2sql.c to preserve data about equalities, fixed values and globals when triples are moved from gp to gp\n"
"for (sparql\n"
"define input:storage \"\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"select ?srcinst\n"
"where {\n"
"graph ?:jgraph {\n"
"{ {\n"
"?destnode rdf:type `iri(?:class)` .\n"
"filter (?destnode = iri(?:destinst)) }\n"
"union\n"
"{\n"
"?destnode rdf:type `iri(?:class)` .\n"
"?destnode rdf:name `iri(?:destinst)` } } .\n"
"?destnode virtrdf:inheritFrom ?srcinst .\n"
"?srcinst rdf:type `iri(?:class)` .\n"
"} } ) do\n"
"*/\n"
"for (sparql\n"
"define input:storage \"\"\n"
"define output:valmode \"LONG\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"select ?src_iid\n"
"where {\n"
"graph ?:jgraph { ?:dest_iid virtrdf:inheritFrom ?src_iid } } ) do\n"
"{\n"
"declare srcinst varchar;\n"
"srcinst := id_to_iri_nosignal (\"src_iid\");\n"
"if (baseinst is null)\n"
"{\n"
"if (not exists (sparql\n"
"define input:storage \"\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"ask where { graph ?:jgraph { ?:\"src_iid\" rdf:type `iri(?:class)` } } ) )\n"
"signal (\'22023\', \'JSO_MAKE_INHERITANCE has found that the object <\' || destinst || \'> has wrong virtrdf:inheritFrom <\' || srcinst || \'> that is not an instance of type <\' || class || \'>\');\n"
"base_iid := \"src_iid\";\n"
"baseinst := srcinst;\n"
"}\n"
"else if (baseinst <> srcinst)\n"
"signal (\'22023\', \'JSO_MAKE_INHERITANCE has found that the object <\' || destinst || \'> has multiple virtrdf:inheritFrom declarations: <\' || baseinst || \'> and <\' || srcinst || \'>\');\n"
"}\n"
"if (position (baseinst, inh_stack))\n"
"signal (\'22023\', \'JSO_MAKE_INHERITANCE has found that the object <\' || baseinst || \'> is recursively inherited from itself\');\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"\n"
"for (sparql\n"
"define input:storage \"\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"select ?pred\n"
"where {\n"
"graph ?:jgraph {\n"
"?:dest_iid virtrdf:noInherit ?pred\n"
"} } ) do\n"
"{\n"
"if (baseinst is null)\n"
"signal (\'22023\', \'JSO_MAKE_INHERITANCE has found that the object <\' || destinst || \'> has set virtrdf:noInherit but has no virtrdf:inheritFrom\');\n"
"dict_put (noinherits, \"pred\", destinst);\n"
"}\n"
"if (baseinst is null)\n"
"return;\n"
"for (select \"pred_id\", \"predval\"\n"
"from (sparql\n"
"define input:storage \"\"\n"
"define output:valmode \"LONG\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"select ?pred_id, ?predval\n"
"where {\n"
"graph ?:jgraph {\n"
"?:base_iid ?pred_id ?predval\n"
"} } ) as \"t00\"\n"
"where not exists (sparql\n"
"define input:storage \"\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"ask where { graph ?:jgraph { ?:\"t00\".\"pred_id\" virtrdf:loadAs virtrdf:jsoTriple } } )\n"
") do\n"
"{\n"
"declare \"pred\" any;\n"
"\"pred\" := id_to_iri (\"pred_id\");\n"
"if (DB.DBA.RDF_LANGUAGE_OF_LONG (\"predval\", null) is not null)\n"
"signal (\'22023\', \'JSO_MAKE_INHERITANCE does not support language marks on objects\');\n"
"if (\'http://www.w3.org/1999/02/22-rdf-syntax-ns#type\' = \"pred\")\n"
" ;\n"
"else if (\'http://www.w3.org/1999/02/22-rdf-syntax-ns#name\' = \"pred\")\n"
" ;\n"
"else if (\'http://www.openlinksw.com/schemas/virtrdf#inheritFrom\' = \"pred\")\n"
" ;\n"
"else if (\'http://www.openlinksw.com/schemas/virtrdf#noInherit\' = \"pred\")\n"
" ;\n"
"else if (dict_get (noinherits, \"pred\", baseinst) = baseinst)\n"
"{\n"
"jso_set (class, rootinst, \"pred\", __rdf_sqlval_of_obj (\"predval\"), isiri_id (\"predval\"));\n"
"dict_put (noinherits, \"pred\", baseinst);\n"
"}\n"
"}\n"
"DB.DBA.JSO_MAKE_INHERITANCE (jgraph, class, rootinst, baseinst, base_iid, noinherits, inh_stack);\n"
"}\n"
"--src sparql_init.sql:45\n";

static const char *proc51 = 
"#line 173 \"[executable]/sparql_init.sql\"\n"
"create function DB.DBA.JSO_LOAD_INSTANCE (in jgraph varchar, in jinst varchar, in delete_first integer, in make_new integer, in jsubj_iid iri_id := 0)\n"
"{\n"
"declare jinst_iid, jgraph_iid IRI_ID;\n"
"declare jclass varchar;\n"
"declare noinherits, inh_stack, \"p\" any;\n"
"\n"
"noinherits := dict_new ();\n"
"jinst_iid := iri_ensure (jinst);\n"
"jgraph_iid := iri_ensure (jgraph);\n"
"if (jsubj_iid is null)\n"
"{\n"
"jsubj_iid := (sparql\n"
"define input:storage \"\"\n"
"define output:valmode \"LONG\"\n"
"select ?s\n"
"where { graph ?:jgraph { ?s rdf:name ?:jinst } } );\n"
"if (jsubj_iid is null)\n"
"jsubj_iid := jinst_iid;\n"
"}\n"
"jclass := (sparql\n"
"define input:storage \"\"\n"
"select ?t\n"
"where {\n"
"graph ?:jgraph { ?:jsubj_iid rdf:type ?t } } );\n"
"if (jclass is null)\n"
"{\n"
"if (exists (sparql\n"
"define input:storage \"\"\n"
"select ?x\n"
"where { graph ?:jgraph {\n"
"{ ?:jinst ?x ?o }\n"
"union\n"
"{ ?x rdf:name ?ji .\n"
"filter (str (?ji) = ?:jinst)\n"
"} } } ) )\n"
"signal (\'22023\', \'JSO_LOAD_INSTANCE can not detect the type of <\' || jinst || \'>\');\n"
"else\n"
"signal (\'22023\', \'JSO_LOAD_INSTANCE can not find an object <\' || jinst || \'>\');\n"
"}\n"
"if (delete_first)\n"
"jso_delete (jclass, jinst, 1);\n"
"if (make_new)\n"
"jso_new (jclass, jinst);\n"
"for (select \"p_id\", coalesce (\"o2\", \"o1\") as \"o\"\n"
"from (sparql\n"
"define input:storage \"\"\n"
"define output:valmode \"LONG\"\n"
"select ?p_id ?o1 ?o2\n"
"where {\n"
"graph ?:jgraph {\n"
"{ ?:jsubj_iid ?p_id ?o1 }  optional { ?o1 rdf:name ?o2 }\n"
"} }\n"
") as \"t00\"\n"
"where not exists (sparql\n"
"define input:storage \"\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"ask where { graph ?:jgraph_iid { ?:\"t00\".\"p_id\" virtrdf:loadAs virtrdf:jsoTriple } } ) option (quietcast)\n"
") do\n"
"{\n"
"\"p\" := id_to_iri (\"p_id\");\n"
"if (DB.DBA.RDF_LANGUAGE_OF_LONG (\"o\", null) is not null)\n"
"signal (\'22023\', \'JSO_LOAD_INSTANCE does not support language marks on objects\');\n"
"if (\'http://www.w3.org/1999/02/22-rdf-syntax-ns#type\' = \"p\")\n"
"{\n"
"if (__rdf_sqlval_of_obj (\"o\") <> jclass)\n"
"signal (\'22023\', \'JSO_LOAD_INSTANCE has found that the object <\' || jinst || \'> has multiple type declarations\');\n"
"}\n"
"else if (\'http://www.w3.org/1999/02/22-rdf-syntax-ns#name\' = \"p\")\n"
" ;\n"
"else if (\'http://www.openlinksw.com/schemas/virtrdf#inheritFrom\' = \"p\")\n"
" ;\n"
"else if (\'http://www.openlinksw.com/schemas/virtrdf#noInherit\' = \"p\")\n"
" ;\n"
"else\n"
"{\n"
"jso_set (jclass, jinst, \"p\", __rdf_sqlval_of_obj (\"o\"), isiri_id (\"o\"));\n"
"dict_put (noinherits, \"p\", jinst);\n"
"}\n"
"}\n"
"inh_stack := vector ();\n"
"DB.DBA.JSO_MAKE_INHERITANCE (jgraph, jclass, jinst, jinst, jsubj_iid, noinherits, inh_stack);\n"
"}\n"
"--src sparql_init.sql:171\n";

static const char *proc52 = 
"#line 257 \"[executable]/sparql_init.sql\"\n"
"create procedure DB.DBA.JSO_LIST_INSTANCES_OF_GRAPH (in jgraph varchar, out instances any)\n"
"{\n"
"declare md, res, st, msg any;\n"
"st:= \'00000\';\n"
"exec (\n"
"\'select DB.DBA.VECTOR_AGG (\n"
"vector (\n"
"id_to_iri (\"jclass\"),\n"
"id_to_iri (\"jinst\"),\n"
"coalesce (\"s\", \"jinst\") ) )\n"
"from ( sparql\n"
"define output:valmode \"LONG\"\n"
"define input:storage \"\"\n"
"select ?jclass ?jinst ?s\n"
"where {\n"
"graph ?? {\n"
"{ ?jinst rdf:type ?jclass .\n"
"filter (!isBLANK (?jinst)) }\n"
"union\n"
"{ ?s rdf:type ?jclass .\n"
"?s rdf:name ?jinst .\n"
"filter (isBLANK (?s))\n"
"} } }\n"
") as inst\',\n"
"st, msg, vector (jgraph), 1, md, res);\n"
"if (st <> \'00000\') signal (st, msg);\n"
"instances := res[0][0];\n"
"}\n"
"--src sparql_init.sql:255\n";

static const char *proc53 = 
"#line 287 \"[executable]/sparql_init.sql\"\n"
"create function DB.DBA.JSO_LOAD_GRAPH (in jgraph varchar, in pin_now integer := 1)\n"
"{\n"
"declare jgraph_iid IRI_ID;\n"
"declare instances, chk any;\n"
"\n"
"log_text (\'DB.DBA.JSO_LOAD_GRAPH (?,?)\', jgraph, pin_now);\n"
"jgraph_iid := iri_ensure (jgraph);\n"
"DB.DBA.JSO_LIST_INSTANCES_OF_GRAPH (jgraph, instances);\n"
"/* Pass 1. Deleting all obsolete instances. */\n"
"foreach (any j in instances) do\n"
"jso_delete (j[0], j[1], 1);\n"
"/* Pass 2. Creating all instances. */\n"
"foreach (any j in instances) do\n"
"jso_new (j[0], j[1]);\n"
"/* Pass 3. Loading all instances, including loading inherited values. */\n"
"foreach (any j in instances) do\n"
"DB.DBA.JSO_LOAD_INSTANCE (jgraph, j[1], 0, 0, j[2]);\n"
"/* Pass 4. Validation all instances. */\n"
"foreach (any j in instances) do\n"
"jso_validate (j[0], j[1], 1);\n"
"/* Pass 5. Pin all instances. */\n"
"if (pin_now)\n"
"{\n"
"foreach (any j in instances) do\n"
"jso_pin (j[0], j[1]);\n"
"}\n"
"/* Pass 6. Load all separate triples */\n"
"exec (\'sparql\n"
"define input:storage \"\"\n"
"define sql:table-option \"LOOP\"\n"
"prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#>\n"
"select (bif:jso_triple_add (?s, ?p, ?o))\n"
"where { graph <\' || id_to_iri (jgraph_iid) || \'> { ?p virtrdf:loadAs virtrdf:jsoTriple . ?s ?p ?o } }\');\n"
"chk := jso_triple_get_objs (\n"
"UNAME\'http://www.openlinksw.com/schemas/virtrdf#loadAs\',\n"
"UNAME\'http://www.openlinksw.com/schemas/virtrdf#loadAs\' );\n"
"if ((1 <> length (chk)) or (cast (chk[0] as varchar) <> \'http://www.openlinksw.com/schemas/virtrdf#jsoTriple\'))\n"
"signal (\'22023\', \'JSO_LOAD_GRAPH has not found expected metadata in the graph\');\n"
"}\n"
"--src sparql_init.sql:285\n";

static const char *proc54 = 
"#line 328 \"[executable]/sparql_init.sql\"\n"
"create function DB.DBA.JSO_PIN_GRAPH (in jgraph varchar)\n"
"{\n"
"declare instances any;\n"
"log_text (\'DB.DBA.JSO_PIN_GRAPH (?)\', jgraph);\n"
"DB.DBA.JSO_LIST_INSTANCES_OF_GRAPH (jgraph, instances);\n"
"foreach (any j in instances) do\n"
"jso_pin (j[0], j[1]);\n"
"}\n"
"--src sparql_init.sql:326\n";

static const char *proc55 = 
"#line 339 \"[executable]/sparql_init.sql\"\n"
" create function DB.DBA.JSO_SYS_GRAPH () returns varchar\n"
"{\n"
"return \'http://www.openlinksw.com/schemas/virtrdf#\';\n"
"}\n"
"--src sparql_init.sql:337\n";

static const char *proc56 = 
"#line 346 \"[executable]/sparql_init.sql\"\n"
"create procedure DB.DBA.JSO_LOAD_AND_PIN_SYS_GRAPH_RO (in graphiri varchar := null)\n"
"{\n"
"if (graphiri is null)\n"
"graphiri := DB.DBA.JSO_SYS_GRAPH();\n"
"if (not exists (select 1 from SYS_KEYS where KEY_TABLE = \'DB.DBA.RDF_QUAD\'))\n"
"return;\n"
"DB.DBA.JSO_LOAD_GRAPH (graphiri, 0);\n"
"DB.DBA.JSO_PIN_GRAPH (graphiri);\n"
"}\n"
"--src sparql_init.sql:344\n";

static const char *proc57 = 
"#line 357 \"[executable]/sparql_init.sql\"\n"
"create procedure DB.DBA.RDF_INIT_SINGLE_SERVER ()\n"
"{\n"
"if (1 <> sys_stat (\'cl_run_local_only\'))\n"
"return;\n"
"DB.DBA.JSO_LOAD_AND_PIN_SYS_GRAPH_RO ();\n"
"}\n"
"--src sparql_init.sql:355\n";

static const char *other34 = 
"DB.DBA.RDF_INIT_SINGLE_SERVER ()\n";
static int
sch_proc_def_exists (client_connection_t *cli, const char *proc_name, const int report)
{
  query_t *proc = NULL;
  char *full_name = sch_full_proc_name (isp_schema(NULL), proc_name,
	cli->cli_qualifier, CLI_OWNER (cli));
  if (full_name)
    proc = sch_proc_def (isp_schema(NULL), full_name);
  if (report && proc != NULL)
     log_debug ("built-in procedure \"%s\" overruled by the RDBMS", proc_name);
  return (proc != NULL);
}

#define DEFINE_PROC(name, proc) \
   if (!sch_proc_def_exists (bootstrap_cli, (name), log_proc_overwrite)) \
     ddl_std_proc_1 (proc, 0x0, 1)


#define DEFINE_PUBLIC_PROC(name, proc) \
   if (!sch_proc_def_exists (bootstrap_cli, (name), log_proc_overwrite)) \
     ddl_std_proc_1 (proc, 0x1, 1)


#define DEFINE_OVERWRITE_PROC(name, proc) \
   ddl_std_proc_1 (proc, 0x1, 1)


void
sqls_define_sparql_init (void)
{
  /* useraggr.sql */
 
  DEFINE_PUBLIC_PROC ("STD_COUNT", proc0); 
  DEFINE_PUBLIC_PROC ("STD11_INIT", proc1); 
  DEFINE_PUBLIC_PROC ("STD12_INIT", proc2); 
  DEFINE_PUBLIC_PROC ("STD13_INIT", proc3); 
  DEFINE_PUBLIC_PROC ("VAR_ACC", proc4); 
  DEFINE_PUBLIC_PROC ("VAR_POP_FIN", proc5); 
  DEFINE_PUBLIC_PROC ("VAR_SAMP_FIN", proc6); 
  DEFINE_PUBLIC_PROC ("VAR_FIN", proc7); 
  DEFINE_PUBLIC_PROC ("STDDEV_POP_FIN", proc8); 
  DEFINE_PUBLIC_PROC ("STDDEV_SAMP_FIN", proc9); 
  DEFINE_PUBLIC_PROC ("STDDEV_FIN", proc10); 
  DEFINE_PUBLIC_PROC ("COVAR_ACC", proc11); 
  DEFINE_PUBLIC_PROC ("COVAR_SAMP_FIN", proc12); 
  DEFINE_PUBLIC_PROC ("COVAR_POP_FIN", proc13); 
  DEFINE_PUBLIC_PROC ("COVAR_FIN", proc14);
  ddl_ensure_table ("do this always", other0);
  ddl_ensure_table ("do this always", other1);
  ddl_ensure_table ("do this always", other2);
  ddl_ensure_table ("do this always", other3);
  ddl_ensure_table ("do this always", other4);
  ddl_ensure_table ("do this always", other5);
  ddl_ensure_table ("do this always", other6);
  ddl_ensure_table ("do this always", other7);
  ddl_ensure_table ("do this always", other8); 
  DEFINE_PUBLIC_PROC ("REGR_SLOPE_INIT", proc15); 
  DEFINE_PUBLIC_PROC ("REGR_SLOPE_ACC", proc16); 
  DEFINE_PUBLIC_PROC ("REGR_SLOPE_FIN", proc17);
  ddl_ensure_table ("do this always", other9); 
  DEFINE_PUBLIC_PROC ("REGR_INTERCEPT_INIT", proc18); 
  DEFINE_PUBLIC_PROC ("REGR_INTERCEPT_ACC", proc19); 
  DEFINE_PUBLIC_PROC ("REGR_INTERCEPT_FIN", proc20);
  ddl_ensure_table ("do this always", other10); 
  DEFINE_PUBLIC_PROC ("REGR_COUNT_INIT", proc21); 
  DEFINE_PUBLIC_PROC ("REGR_COUNT_ACC", proc22); 
  DEFINE_PUBLIC_PROC ("REGR_COUNT_FIN", proc23); 
  DEFINE_PUBLIC_PROC ("REGR_COUNT_MERGE", proc24);
  ddl_ensure_table ("do this always", other11); 
  DEFINE_PUBLIC_PROC ("REGR_AVG_ACC", proc25); 
  DEFINE_PUBLIC_PROC ("REGR_AVGX_FIN", proc26); 
  DEFINE_PUBLIC_PROC ("REGR_AVGY_FIN", proc27);
  ddl_ensure_table ("do this always", other12);
  ddl_ensure_table ("do this always", other13); 
  DEFINE_PUBLIC_PROC ("CORR_INIT", proc28); 
  DEFINE_PUBLIC_PROC ("CORR_ACC", proc29); 
  DEFINE_PUBLIC_PROC ("CORR_FIN", proc30);
  ddl_ensure_table ("do this always", other14); 
  DEFINE_PUBLIC_PROC ("REGR_R2_INIT", proc31); 
  DEFINE_PUBLIC_PROC ("REGR_R2_ACC", proc32); 
  DEFINE_PUBLIC_PROC ("REGR_R2_FIN", proc33);
  ddl_ensure_table ("do this always", other15); 
  DEFINE_PUBLIC_PROC ("REGR_SXX_ACC", proc34); 
  DEFINE_PUBLIC_PROC ("REGR_SYY_ACC", proc35); 
  DEFINE_PUBLIC_PROC ("REGR_SXY_ACC", proc36); 
  DEFINE_PUBLIC_PROC ("REGR_S___FIN", proc37); 
  DEFINE_PUBLIC_PROC ("REGR_SXY_FIN", proc38);
  ddl_ensure_table ("do this always", other16);
  ddl_ensure_table ("do this always", other17);
  ddl_ensure_table ("do this always", other18); 
  DEFINE_PUBLIC_PROC ("xte_nodebld_final_root", proc39);
  ddl_ensure_table ("do this always", other19);
  ddl_ensure_table ("do this always", other20);
  ddl_ensure_table ("do this always", other21);
  ddl_ensure_table ("do this always", other22);
  ddl_ensure_table ("do this always", other23);
  ddl_ensure_table ("do this always", other24);
  ddl_ensure_table ("do this always", other25);
  ddl_ensure_table ("do this always", other26);
  ddl_ensure_table ("do this always", other27);
  ddl_ensure_table ("do this always", other28);
  ddl_ensure_table ("do this always", other29);
  ddl_ensure_table ("do this always", other30); 
  DEFINE_PUBLIC_PROC ("DB.DBA.GROUP_CONCAT_INIT", proc40); 
  DEFINE_PUBLIC_PROC ("DB.DBA.GROUP_CONCAT_ACC", proc41); 
  DEFINE_PUBLIC_PROC ("DB.DBA.GROUP_CONCAT_FIN", proc42);
  ddl_ensure_table ("do this always", other31); 
  DEFINE_PUBLIC_PROC ("DB.DBA.GROUP_DIGEST_INIT", proc43); 
  DEFINE_PUBLIC_PROC ("DB.DBA.GROUP_DIGEST_ACC", proc44); 
  DEFINE_PUBLIC_PROC ("DB.DBA.GROUP_DIGEST_FIN", proc45);
  ddl_ensure_table ("do this always", other32); 
  DEFINE_PUBLIC_PROC ("DB.DBA.SAMPLE_INIT", proc46); 
  DEFINE_PUBLIC_PROC ("DB.DBA.SAMPLE_ACC", proc47); 
  DEFINE_PUBLIC_PROC ("DB.DBA.SAMPLE_FIN", proc48);
  ddl_ensure_table ("do this always", other33);

  /* sparql_init.sql */

  DEFINE_PROC ("DB.DBA.RDF_LANGUAGE_OF_LONG", proc49);
  DEFINE_PROC ("DB.DBA.JSO_MAKE_INHERITANCE", proc50);
  DEFINE_PROC ("DB.DBA.JSO_LOAD_INSTANCE", proc51);
  DEFINE_PROC ("DB.DBA.JSO_LIST_INSTANCES_OF_GRAPH", proc52);
  DEFINE_PROC ("DB.DBA.JSO_LOAD_GRAPH", proc53);
  DEFINE_PROC ("DB.DBA.JSO_PIN_GRAPH", proc54); 
  DEFINE_PUBLIC_PROC ("DB.DBA.JSO_SYS_GRAPH", proc55);
  DEFINE_PROC ("DB.DBA.JSO_LOAD_AND_PIN_SYS_GRAPH_RO", proc56);
  DEFINE_PROC ("DB.DBA.RDF_INIT_SINGLE_SERVER", proc57);
  ddl_ensure_table ("do this always", other34);
}


void
sqls_arfw_define_sparql_init (void)
{
}