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
|
--
-- $Id$
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2012 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--
--!AWK PUBLIC
create procedure STD_COUNT (in _env varchar)
{
return aref (deserialize(_env), 0);
}
;
--!AWK PUBLIC
create procedure STD11_INIT (inout _env varchar)
{
_env := serialize (vector (0, 0.0));
}
;
--!AWK PUBLIC
create procedure STD12_INIT (inout _env varchar)
{
_env := serialize (vector (0, 0.0,0.0));
}
;
--!AWK PUBLIC
create procedure STD13_INIT (inout _env varchar)
{
_env := serialize (vector (0, 0.0,0.0, 0.0));
}
;
--!AWK PUBLIC
create procedure VAR_ACC (inout _env varchar, in val numeric)
{
if (_env is null)
return;
if (val is null)
return;
declare ctx any;
ctx := deserialize (_env);
aset( ctx, 1, aref (ctx, 1) + val);
aset( ctx, 2, aref (ctx, 2) + val*val);
aset( ctx, 0, aref (ctx, 0) + 1);
_env := serialize (ctx);
}
;
--!AWK PUBLIC
create procedure VAR_POP_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
declare _env any;
_env := deserialize (_ctx);
declare c integer;
c := aref (_env, 0);
if (c = 0)
return null;
return (aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / c;
}
;
--!AWK PUBLIC
create procedure VAR_SAMP_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
declare _env any;
_env := deserialize (_ctx);
declare c integer;
c := aref (_env, 0);
if (c = 0)
return null;
if (c = 1)
return 0.0;
return (aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / (c - 1);
}
;
--!AWK PUBLIC
create procedure VAR_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
if (STD_COUNT (_ctx) = 1)
return null;
return VAR_SAMP_FIN (_ctx);
}
;
--!AWK PUBLIC
create procedure STDDEV_POP_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
declare c integer;
declare _env any;
_env := deserialize (_ctx);
c := aref (_env, 0);
if (c = 0)
return null;
return sqrt ((aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / c) ;
}
;
--!AWK PUBLIC
create procedure STDDEV_SAMP_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
declare c integer;
declare _env any;
_env := deserialize (_ctx);
c := aref (_env, 0);
if (c = 0)
return null;
if (c = 1)
return 0.0;
return sqrt ((aref (_env, 2) - aref (_env, 1) * aref (_env, 1) / c) / ( c - 1));
}
;
--!AWK PUBLIC
create procedure STDDEV_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
if (STD_COUNT (_ctx) = 1)
return null;
return STDDEV_SAMP_FIN (_ctx);
}
;
--!AWK PUBLIC
create procedure COVAR_ACC (inout _ctx any,
in expr1 numeric,
in expr2 numeric)
{
if (_ctx is null)
return;
if (expr1 is null or expr2 is null)
return;
declare _env any;
_env := deserialize (_ctx);
aset (_env, 1, aref (_env,1)+expr1);
aset (_env, 2, aref (_env,2)+expr2);
aset (_env, 3, aref (_env,3)+expr2*expr1);
aset (_env, 0, aref (_env,0)+1);
_ctx := serialize (_env);
}
;
--!AWK PUBLIC
create procedure COVAR_SAMP_FIN (inout _ctx any)
{
if (_ctx is null)
return null;
declare _env any;
_env := deserialize (_ctx);
if (aref (_env, 0) = 0)
return null;
if (aref (_env, 0) = 1)
return 0.0;
return (aref (_env, 3) - aref(_env,2) * aref (_env,1) / aref (_env, 0)) / ( aref (_env, 0) - 1);
}
;
--!AWK PUBLIC
create procedure COVAR_POP_FIN (inout _ctx any)
{
if (_ctx is null)
return null;
declare _env any;
_env := deserialize (_ctx);
if (aref (_env, 0) = 0)
return null;
if (aref (_env, 0) = 1)
return 0.0;
return (aref (_env, 3) - aref(_env,2) * aref (_env,1) / aref (_env, 0))/ aref (_env,0);
}
;
--!AWK PUBLIC
create procedure COVAR_FIN (inout _ctx varchar)
{
if (_ctx is null)
return null;
if (STD_COUNT (_ctx) = 1)
return null;
return COVAR_SAMP_FIN (_ctx);
}
;
create aggregate DB.DBA.VAR_POP (in val numeric) returns numeric from
STD12_INIT, VAR_ACC, VAR_POP_FIN
;
create aggregate DB.DBA.VAR_SAMP (in val numeric) returns numeric from
STD12_INIT, VAR_ACC, VAR_SAMP_FIN
;
create aggregate DB.DBA.VAR (in val numeric) returns numeric from
STD12_INIT, VAR_ACC, VAR_FIN
;
create aggregate DB.DBA.STDDEV_POP (in val numeric) returns numeric from
STD12_INIT, VAR_ACC, STDDEV_POP_FIN
;
create aggregate DB.DBA.STDDEV_SAMP (in val numeric) returns numeric from
STD12_INIT, VAR_ACC, STDDEV_SAMP_FIN
;
create aggregate DB.DBA.STDDEV (in val numeric) returns numeric from
STD12_INIT, VAR_ACC, STDDEV_FIN
;
create aggregate DB.DBA.COVAR_SAMP (in expr1 numeric, in expr2 numeric) returns numeric from
STD13_INIT, COVAR_ACC, COVAR_SAMP_FIN
;
create aggregate DB.DBA.COVAR_POP (in expr1 numeric, in expr2 numeric) returns numeric from
STD13_INIT, COVAR_ACC, COVAR_POP_FIN
;
create aggregate DB.DBA.COVAR (in expr1 numeric, in expr2 numeric) returns numeric from
STD13_INIT, COVAR_ACC, COVAR_FIN
;
--!AWK PUBLIC
create procedure REGR_SLOPE_INIT (inout _env varchar)
{
declare _ctx1 varchar;
declare _ctx2 varchar;
STD13_INIT (_ctx1);
STD12_INIT (_ctx2);
_env := serialize (vector (0, _ctx1, _ctx2));
}
;
--!AWK PUBLIC
create procedure REGR_SLOPE_ACC (inout _env varchar, in expr1 numeric, in expr2 numeric)
{
if (_env is null)
return;
if ( (expr1 is null) or (expr2 is null))
return;
declare _ctx any;
_ctx := deserialize (_env);
declare _ctx1 varchar;
declare _ctx2 varchar;
_ctx1 := aref (_ctx, 1);
_ctx2 := aref (_ctx, 2);
aset (_ctx, 0, aref (_ctx,0) + 1);
COVAR_ACC (_ctx1, expr1, expr2);
VAR_ACC (_ctx2, expr2);
aset (_ctx, 1, _ctx1);
aset (_ctx, 2, _ctx2);
_env := serialize (_ctx);
}
;
--!AWK PUBLIC
create procedure REGR_SLOPE_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
declare c integer;
_ctx := deserialize (_env);
c := aref (_ctx, 0);
if (c = 0)
return 0;
if (c = 1)
return null;
declare _ctx1 varchar;
declare _ctx2 varchar;
declare covar_pop_val numeric;
declare var_pop_val numeric;
_ctx1 := aref (_ctx, 1);
_ctx2 := aref (_ctx, 2);
covar_pop_val := COVAR_POP_FIN (_ctx1);
var_pop_val := VAR_POP_FIN (_ctx2);
if (var_pop_val = 0)
return null;
return covar_pop_val / var_pop_val;
}
;
create aggregate DB.DBA.REGR_SLOPE (in expr1 numeric, in expr2 numeric) returns numeric from REGR_SLOPE_INIT, REGR_SLOPE_ACC, REGR_SLOPE_FIN
;
--!AWK PUBLIC
create procedure REGR_INTERCEPT_INIT (inout _env varchar)
{
declare _ctx_regr_slope varchar;
REGR_SLOPE_INIT (_ctx_regr_slope);
_env := serialize (vector (0, 0.0, 0.0, _ctx_regr_slope));
}
;
--!AWK PUBLIC
create procedure REGR_INTERCEPT_ACC (inout _env varchar, in expr1 numeric, in expr2 numeric)
{
if (_env is null)
return;
if ((expr1 is null) or (expr2 is null))
return;
declare _ctx any;
_ctx := deserialize (_env);
aset (_ctx, 0, aref (_ctx, 0) + 1);
aset (_ctx, 1, aref (_ctx, 1) + expr1);
aset (_ctx, 2, aref (_ctx, 2) + expr2);
declare _ctx_r varchar;
_ctx_r := aref (_ctx, 3);
REGR_SLOPE_ACC (_ctx_r, expr1, expr2);
aset (_ctx, 3, _ctx_r);
_env := serialize (_ctx);
}
;
--!AWK PUBLIC
create procedure REGR_INTERCEPT_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
declare c integer;
c := aref (_ctx, 0);
if ((c = 0) or (c = 1))
return null;
return aref (_ctx, 1) / c - REGR_SLOPE_FIN (aref (_ctx, 3)) * aref (_ctx, 2) / c;
}
;
create aggregate DB.DBA.REGR_INTERCEPT (in expr1 numeric, in expr2 numeric) returns numeric from REGR_INTERCEPT_INIT, REGR_INTERCEPT_ACC, REGR_INTERCEPT_FIN
;
--!AWK PUBLIC
create procedure REGR_COUNT_INIT (inout _env integer)
{
_env := 0;
}
;
--!AWK PUBLIC
create procedure REGR_COUNT_ACC (inout _env integer, in expr numeric, in expr2 numeric)
{
if ((_env is null) or (expr is null) or (expr2 is null))
return;
_env := _env + 1;
}
;
--!AWK PUBLIC
create procedure REGR_COUNT_FIN (inout _env integer)
{
return _env;
}
;
--!AWK PUBLIC
create procedure REGR_COUNT_MERGE (inout _e1 integer, inout _e2 integer)
{
_e1 := _e1 + _e2;
}
;
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
;
--!AWK PUBLIC
create procedure REGR_AVG_ACC (inout _env varchar, in expr1 numeric, in expr2 numeric)
{
if (_env is null)
return;
if ( (expr1 is null) or (expr2 is null))
return;
declare _ctx any;
_ctx := deserialize (_env);
aset (_ctx, 0, aref (_ctx, 0) + 1);
aset (_ctx, 1, aref (_ctx, 1) + expr1);
aset (_ctx, 2, aref (_ctx, 2) + expr2);
_env := serialize (_ctx);
}
;
--!AWK PUBLIC
create procedure REGR_AVGX_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
if (aref (_ctx, 0) = 0)
return null;
return aref (_ctx, 1) / aref (_ctx,0);
}
;
--!AWK PUBLIC
create procedure REGR_AVGY_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
if (aref (_ctx, 0) = 0)
return null;
return aref (_ctx, 2) / aref (_ctx,0);
}
;
create aggregate DB.DBA.REGR_AVGX (in x numeric, in y numeric) returns numeric from
STD12_INIT, REGR_AVG_ACC, REGR_AVGX_FIN
;
create aggregate DB.DBA.REGR_AVGY (in x numeric, in y numeric) returns numeric from
STD12_INIT, REGR_AVG_ACC, REGR_AVGY_FIN
;
--!AWK PUBLIC
create procedure CORR_INIT (inout _env varchar)
{
declare _ctx_cov varchar;
declare _ctx_stdev1 varchar;
declare _ctx_stdev2 varchar;
STD13_INIT (_ctx_cov);
STD12_INIT (_ctx_stdev1);
STD12_INIT (_ctx_stdev2);
_env := serialize (vector (0, _ctx_cov, _ctx_stdev1, _ctx_stdev2));
}
;
--!AWK PUBLIC
create procedure CORR_ACC (inout _env varchar, in e1 numeric, in e2 numeric)
{
if (_env is null)
return;
if ((e1 is null) or (e2 is null))
return;
declare _ctx any;
_ctx := deserialize (_env);
declare _ctx_cov varchar;
declare _ctx_stdev1 varchar;
declare _ctx_stdev2 varchar;
_ctx_cov := aref (_ctx, 1);
_ctx_stdev1 := aref (_ctx, 2);
_ctx_stdev2 := aref (_ctx, 3);
COVAR_ACC (_ctx_cov, e1, e2);
VAR_ACC (_ctx_stdev1, e1);
VAR_ACC (_ctx_stdev2, e2);
aset (_ctx, 0, aref (_ctx, 0) + 1);
aset (_ctx, 1, _ctx_cov);
aset (_ctx, 2, _ctx_stdev1);
aset (_ctx, 3, _ctx_stdev2);
_env := serialize (_ctx);
}
;
--!AWK PUBLIC
create procedure CORR_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
declare _ctx_cov_val numeric;
declare _ctx_stdev1_val numeric;
declare _ctx_stdev2_val numeric;
_ctx_cov_val := COVAR_POP_FIN (aref (_ctx, 1));
_ctx_stdev1_val := STDDEV_POP_FIN (aref (_ctx, 2));
_ctx_stdev2_val := STDDEV_POP_FIN (aref (_ctx, 3));
if (_ctx_cov_val is null)
return null;
if (_ctx_stdev1_val is null or _ctx_stdev1_val = 0)
return null;
if (_ctx_stdev2_val is null or _ctx_stdev2_val = 0)
return null;
return _ctx_cov_val / _ctx_stdev1_val / _ctx_stdev2_val;
}
;
create aggregate DB.DBA.CORR (in x numeric, in y numeric) returns numeric from
CORR_INIT, CORR_ACC, CORR_FIN
;
--!AWK PUBLIC
create procedure REGR_R2_INIT (inout _env varchar)
{
declare _ctx_vp1 varchar;
declare _ctx_vp2 varchar;
declare _ctx_corr varchar;
STD12_INIT (_ctx_vp1);
STD12_INIT (_ctx_vp2);
CORR_INIT (_ctx_corr);
_env := serialize (vector (_ctx_vp1, _ctx_vp2, _ctx_corr));
}
;
--!AWK PUBLIC
create procedure REGR_R2_ACC (inout _env varchar, in e1 numeric, in e2 numeric)
{
if (_env is null)
return;
if (e1 is null or e2 is null)
return;
declare _ctx any;
_ctx := deserialize (_env);
declare _ctx_vp1 varchar;
declare _ctx_vp2 varchar;
declare _ctx_corr varchar;
_ctx_vp1 := aref (_ctx, 0);
_ctx_vp2 := aref (_ctx, 1);
_ctx_corr := aref (_ctx, 2);
VAR_ACC (_ctx_vp1, e1);
VAR_ACC (_ctx_vp2, e2);
CORR_ACC (_ctx_corr, e1, e2);
aset (_ctx, 0, _ctx_vp1);
aset (_ctx, 1, _ctx_vp2);
aset (_ctx, 2, _ctx_corr);
_env := serialize (_ctx);
}
;
--!AWK PUBLIC
create procedure REGR_R2_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
declare _vp1 numeric;
declare _vp2 numeric;
declare _corr numeric;
_vp2 := VAR_POP_FIN (aref(_ctx, 1));
if (_vp2 is null or _vp2 = 0)
return null;
_vp1 := VAR_POP_FIN (aref(_ctx, 0));
if (_vp1 is null or _vp1 = 0)
return 1;
_corr := CORR_FIN (aref (_ctx, 2));
return _corr * _corr;
}
;
create aggregate DB.DBA.REGR_R2 (in e1 numeric, in e2 numeric) returns numeric from
REGR_R2_INIT, REGR_R2_ACC, REGR_R2_FIN
;
--!AWK PUBLIC
create procedure REGR_SXX_ACC (inout _env varchar, in e1 numeric, in e2 numeric)
{
if (_env is null)
return;
if (e1 is null or e2 is null)
return;
VAR_ACC (_env, e2);
}
;
--!AWK PUBLIC
create procedure REGR_SYY_ACC (inout _env varchar, in e1 numeric, in e2 numeric)
{
if (_env is null)
return;
if (e1 is null or e2 is null)
return;
VAR_ACC (_env, e1);
}
;
--!AWK PUBLIC
create procedure REGR_SXY_ACC (inout _env varchar, in e1 numeric, in e2 numeric)
{
if (_env is null)
return;
if (e1 is null or e2 is null)
return;
COVAR_ACC (_env, e1, e2);
}
;
--!AWK PUBLIC
create procedure REGR_S___FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
declare _var numeric;
_var := VAR_POP_FIN (_env);
if (_var is null)
return null;
return aref (_ctx,0) * _var;
}
;
--!AWK PUBLIC
create procedure REGR_SXY_FIN (inout _env varchar)
{
if (_env is null)
return null;
declare _ctx any;
_ctx := deserialize (_env);
declare _var numeric;
_var := COVAR_POP_FIN (_env);
if (_var is null)
return null;
return aref (_ctx,0) * _var;
}
;
create aggregate DB.DBA.REGR_SXX (in e1 numeric, in e2 numeric) returns numeric from
STD12_INIT, REGR_SXX_ACC, REGR_S___FIN
;
create aggregate DB.DBA.REGR_SYY (in e1 numeric, in e2 numeric) returns numeric from
STD12_INIT, REGR_SYY_ACC, REGR_S___FIN
;
create aggregate DB.DBA.REGR_SXY (in e1 numeric, in e2 numeric) returns numeric from
STD13_INIT, REGR_SXY_ACC, REGR_SXY_FIN
;
--!AWK PUBLIC
create procedure xte_nodebld_final_root (in acc any) returns any
{
return xte_nodebld_xmlagg_final (acc, xte_head (UNAME' root'));
}
;
create aggregate DB.DBA.XMLAGG (in _child any) returns any
from xte_nodebld_init, xte_nodebld_xmlagg_acc, xte_nodebld_final_root
;
create aggregate DB.DBA.VECTOR_AGG (in _child any) returns any
from vectorbld_init, vectorbld_agg_acc, vectorbld_agg_final
order
;
create aggregate DB.DBA.VECTOR_OF_NONNULLS_AGG (in _child any) returns any
from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vectorbld_agg_final
order
;
create aggregate DB.DBA.VECTOR_OR_NULL_AGG (in _child any) returns any
from vectorbld_init, vectorbld_agg_acc, vector_or_null_bld_agg_final
order
;
create aggregate DB.DBA.VECTOR_OF_NONNULLS_OR_NULL_AGG (in _child any) returns any
from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vector_or_null_bld_agg_final
order
;
create aggregate DB.DBA.VECTOR_CONCAT_AGG (in _child any) returns any
from vectorbld_init, vectorbld_concat_agg_acc, vectorbld_agg_final
order
;
create aggregate DB.DBA.XQ_SEQUENCE_AGG (in _child any) returns any
from xq_sequencebld_init, xq_sequencebld_agg_acc, xq_sequencebld_agg_final
order
;
-- same as vector aggregates but they do not force query to produce deterministic result order
create aggregate DB.DBA.BAG_AGG (in _child any) returns any
from vectorbld_init, vectorbld_agg_acc, vectorbld_agg_final
;
create aggregate DB.DBA.BAG_OF_NONNULLS_AGG (in _child any) returns any
from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vectorbld_agg_final
;
create aggregate DB.DBA.BAG_OR_NULL_AGG (in _child any) returns any
from vectorbld_init, vectorbld_agg_acc, vector_or_null_bld_agg_final
;
create aggregate DB.DBA.BAG_OF_NONNULLS_OR_NULL_AGG (in _child any) returns any
from vectorbld_init, vector_of_nonnulls_bld_agg_acc, vector_or_null_bld_agg_final
;
create aggregate DB.DBA.BAG_CONCAT_AGG (in _child any) returns any
from vectorbld_init, vectorbld_concat_agg_acc, vectorbld_agg_final
;
--!AWK PUBLIC
create procedure DB.DBA.GROUP_CONCAT_INIT (inout _env any)
{
_env := 0;
}
;
--!AWK PUBLIC
create procedure DB.DBA.GROUP_CONCAT_ACC (inout _env any, in token varchar, in delim varchar)
{
-- if (185 <> __tag (_env))
-- _env := string_output();
-- else if (delim is not null)
-- http (cast (delim as varchar), _env);
-- http (cast (token as varchar), _env);
if (__tag of varchar <> __tag (_env))
_env := cast (token as varchar);
else if (delim is not null)
_env := concat (_env, cast (delim as varchar), cast (token as varchar));
else
_env := concat (_env, cast (token as varchar));
}
;
--!AWK PUBLIC
create procedure DB.DBA.GROUP_CONCAT_FIN (inout _env any)
{
-- if (185 <> __tag (_env))
-- return '';
-- return string_output_string (_env);
if (__tag of varchar <> __tag (_env))
return '';
return _env;
}
;
create aggregate DB.DBA.GROUP_CONCAT (in token varchar, in delim varchar) returns varchar
from DB.DBA.GROUP_CONCAT_INIT, DB.DBA.GROUP_CONCAT_ACC, DB.DBA.GROUP_CONCAT_FIN
order
;
--!AWK PUBLIC
create procedure DB.DBA.GROUP_DIGEST_INIT (inout _env any)
{
_env := 0;
}
;
--!AWK PUBLIC
create procedure DB.DBA.GROUP_DIGEST_ACC (inout _env any, in token varchar, in delim varchar, in maxlen integer, in mode integer)
{
declare curlen integer;
declare env_vec, items any;
if (__tag of varchar <> __tag (token))
{
token := cast (token as varchar);
if (token is null)
return;
}
if (__tag of varchar <> __tag (_env))
{
if (length (token) > maxlen)
token := subseq (token, 0, maxlen+1);
_env := serialize (vector_zap_args (vector_zap_args (token), cast (delim as varchar), maxlen));
return;
}
curlen := length (_env);
if (curlen >= maxlen)
return;
env_vec := deserialize (_env);
items := aref_set_0 (env_vec, 0);
if (bit_and (mode, 1))
{
if (0 < position (token, items))
return;
}
if (length (token) > (env_vec[2] - curlen))
token := subseq (token, 0, (env_vec[2] - curlen)+1);
items := vector_concat (items, vector_zap_args (token));
aset_zap_arg (env_vec, 0, items);
_env := serialize (env_vec);
}
;
--!AWK PUBLIC
create procedure DB.DBA.GROUP_DIGEST_FIN (inout _env any)
{
declare envlen, curlen, maxlen, itemctr, itemcount, delim_len, rest_len integer;
declare env_vec, items, ses any;
declare delim varchar;
if (__tag of varchar <> __tag (_env))
return '';
envlen := length (_env);
env_vec := deserialize (_env);
items := aref_set_0 (env_vec, 0);
delim := aref_set_0 (env_vec, 1);
rest_len := maxlen := aref_set_0 (env_vec, 2);
ses := string_output ();
itemctr := 0;
itemcount := length (items);
delim_len := length (delim);
for (itemctr := 0; itemctr < itemcount; itemctr := itemctr + 1)
{
declare itm varchar;
declare itm_len integer;
if (delim_len > (rest_len-5))
goto items_done;
if (itemctr)
{
http (delim, ses);
rest_len := rest_len - delim_len;
}
itm := items [itemctr];
itm_len := length (itm);
if ((itm_len > rest_len) or ((envlen > maxlen) and (itemctr = itemcount-1)))
{
itm := subseq (itm, 0, rest_len);
itm_len := coalesce (__max_notnull (strrchr (itm, 32), strrchr (itm, 10), strrchr (itm, 13)), 0);
while ((itm_len > 0) and (itm [itm_len-1] in (32, 10, 13)))
itm_len := itm_len - 1;
if (0 = itm_len)
http (subseq (itm, 0, rest_len-3), ses);
else
http (subseq (itm, 0, itm_len), ses);
http ('...', ses);
goto items_done;
}
http (itm, ses);
rest_len := rest_len - itm_len;
}
items_done:
return string_output_string (ses);
}
;
create aggregate DB.DBA.GROUP_DIGEST (in token varchar, in delim varchar, in maxlen integer, in mode integer) returns varchar
from DB.DBA.GROUP_DIGEST_INIT, DB.DBA.GROUP_DIGEST_ACC, DB.DBA.GROUP_DIGEST_FIN
order
;
--!AWK PUBLIC
create procedure DB.DBA.SAMPLE_INIT (inout _env any)
{
_env := null;
}
;
--!AWK PUBLIC
create procedure DB.DBA.SAMPLE_ACC (inout _env any, in sample any)
{
if (_env is not null)
return;
_env := sample;
}
;
--!AWK PUBLIC
create procedure DB.DBA.SAMPLE_FIN (inout _env any)
{
return _env;
}
;
create aggregate DB.DBA.SAMPLE (in sample any) returns any
from DB.DBA.SAMPLE_INIT, DB.DBA.SAMPLE_ACC, DB.DBA.SAMPLE_FIN
order
;
|