00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "fennel/common/CommonPreamble.h"
00024 #include "fennel/calculator/ExtendedInstructionTable.h"
00025 #include "fennel/calculator/WinAggHistogram.h"
00026 #include "fennel/calculator/WinAggHistogramStrA.h"
00027 #include "fennel/calculator/RegisterReference.h"
00028 #include "fennel/tuple/StandardTypeDescriptor.h"
00029
00030
00031 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/calculator/ExtWinAggFuncs.cpp#3 $");
00032
00043
00044
00045
00046
00047
00048
00049
00050
00051 void histogramAlloc(
00052 RegisterRef<char*>* result,
00053 RegisterReference* targetDataType)
00054 {
00055 StandardTypeDescriptorOrdinal dType = targetDataType->type();
00056
00057 PBuffer histogramObject = NULL;
00058 if (StandardTypeDescriptor::isExact(dType)) {
00059 histogramObject =
00060 reinterpret_cast<PBuffer>(new WinAggHistogram<int64_t>);
00061 } else if (StandardTypeDescriptor::isApprox(dType)) {
00062 histogramObject =
00063 reinterpret_cast<PBuffer>(new WinAggHistogram<double>);
00064 } else if (StandardTypeDescriptor::isArray(dType)) {
00065 histogramObject =
00066 reinterpret_cast<PBuffer>(new WinAggHistogramStrA);
00067 } else {
00068
00069 throw 22001;
00070 }
00071
00072 TupleDatum *bind = result->getBinding(false);
00073 *(reinterpret_cast<PBuffer*>(const_cast<PBuffer>(bind->pData))) =
00074 histogramObject;
00075 }
00076
00083 template <typename STDTYPE>
00084 inline void add(RegisterRef<STDTYPE>* node, RegisterRef<char*>* aggDataBlock)
00085 {
00086
00087 TupleDatum *bind = aggDataBlock->getBinding(false);
00088 WinAggHistogram<STDTYPE> *pAcc =
00089 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00090 const_cast<PBuffer>(bind->pData)));
00091
00092
00093
00094 pAcc->addRow(node);
00095 }
00096
00097 inline void add(RegisterRef<char*>* node, RegisterRef<char*>* aggDataBlock)
00098 {
00099
00100 TupleDatum *bind = aggDataBlock->getBinding(false);
00101 WinAggHistogramStrA *pAcc =
00102 *(reinterpret_cast<WinAggHistogramStrA**>(
00103 const_cast<PBuffer>(bind->pData)));
00104
00105
00106 pAcc->addRow(node);
00107 }
00108
00109
00117 template <typename STDTYPE>
00118 inline void drop(RegisterRef<STDTYPE>* node, RegisterRef<char*>* aggDataBlock)
00119 {
00120
00121 TupleDatum *bind = aggDataBlock->getBinding(false);
00122 WinAggHistogram<STDTYPE> *pAcc =
00123 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00124 const_cast<PBuffer>(bind->pData)));
00125
00126
00127 pAcc->dropRow(node);
00128 }
00129
00130 inline void drop(RegisterRef<char*>* node, RegisterRef<char*>* aggDataBlock)
00131 {
00132 TupleDatum *bind = aggDataBlock->getBinding(false);
00133 WinAggHistogramStrA *pAcc =
00134 *(reinterpret_cast<WinAggHistogramStrA**>(
00135 const_cast<PBuffer>(bind->pData)));
00136
00137 pAcc->dropRow(node);
00138 }
00139
00146 template <typename STDTYPE>
00147 inline void min(RegisterRef<STDTYPE>* result, RegisterRef<char*>* aggDataBlock)
00148 {
00149
00150 TupleDatum *bind = aggDataBlock->getBinding(false);
00151 WinAggHistogram<STDTYPE> *pAcc =
00152 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00153 const_cast<PBuffer>(bind->pData)));
00154
00155 pAcc->getMin(result);
00156 }
00157
00158 inline void min(RegisterRef<char*>* result, RegisterRef<char*>* aggDataBlock)
00159 {
00160 TupleDatum *bind = aggDataBlock->getBinding(false);
00161 WinAggHistogramStrA *pAcc =
00162 *(reinterpret_cast<WinAggHistogramStrA**>(
00163 const_cast<PBuffer>(bind->pData)));
00164 pAcc->getMin(result);
00165 }
00166
00173 template <typename STDTYPE>
00174 inline void max(RegisterRef<STDTYPE>* result, RegisterRef<char*>* aggDataBlock)
00175 {
00176
00177 TupleDatum *bind = aggDataBlock->getBinding(false);
00178 WinAggHistogram<STDTYPE> *pAcc =
00179 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00180 const_cast<PBuffer>(bind->pData)));
00181
00182
00183 pAcc->getMax(result);
00184 }
00185
00186 inline void max(RegisterRef<char*>* result, RegisterRef<char*>* aggDataBlock)
00187 {
00188 TupleDatum *bind = aggDataBlock->getBinding(false);
00189 WinAggHistogramStrA *pAcc =
00190 *(reinterpret_cast<WinAggHistogramStrA**>(
00191 const_cast<PBuffer>(bind->pData)));
00192 pAcc->getMax(result);
00193 }
00194
00201 template <typename STDTYPE>
00202 inline void avg(
00203 RegisterRef<STDTYPE>* result,
00204 RegisterRef<char*>* aggDataBlock)
00205 {
00206
00207 TupleDatum *bind = aggDataBlock->getBinding(false);
00208 WinAggHistogram<STDTYPE> *pAcc =
00209 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00210 const_cast<PBuffer>(bind->pData)));
00211
00212
00213 pAcc->getAvg(result);
00214 }
00215
00222 template <typename STDTYPE>
00223 inline void sum(
00224 RegisterRef<STDTYPE>* result,
00225 RegisterRef<char*>* aggDataBlock)
00226 {
00227
00228 TupleDatum *bind = aggDataBlock->getBinding(false);
00229 WinAggHistogram<STDTYPE> *pAcc =
00230 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00231 const_cast<PBuffer>(bind->pData)));
00232
00233
00234 pAcc->getSum(result);
00235 }
00236
00243 template <typename STDTYPE>
00244 inline void count(
00245 RegisterRef<STDTYPE>* result,
00246 RegisterRef<char*>* aggDataBlock)
00247 {
00248
00249 TupleDatum *bind = aggDataBlock->getBinding(false);
00250 WinAggHistogram<STDTYPE> *pAcc =
00251 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00252 const_cast<PBuffer>(bind->pData)));
00253
00254
00255 pAcc->getCount(result);
00256 }
00257
00258
00259
00260 template <typename TDT>
00261 void WinAggInit(RegisterRef<char*>* result, RegisterRef<TDT>* targetDataType)
00262 {
00263 histogramAlloc(result, targetDataType);
00264 }
00265
00272 template <typename STDTYPE>
00273 inline void firstValue(
00274 RegisterRef<STDTYPE>* result,
00275 RegisterRef<char*>* aggDataBlock)
00276 {
00277
00278 TupleDatum *bind = aggDataBlock->getBinding(false);
00279 WinAggHistogram<STDTYPE> *pAcc =
00280 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00281 const_cast<PBuffer>(bind->pData)));
00282
00283
00284 pAcc->getFirstValue(result);
00285 }
00286
00287 inline void firstValue(
00288 RegisterRef<char*>* result,
00289 RegisterRef<char*>* aggDataBlock)
00290 {
00291 TupleDatum *bind = aggDataBlock->getBinding(false);
00292 WinAggHistogramStrA *pAcc =
00293 *(reinterpret_cast<WinAggHistogramStrA**>(
00294 const_cast<PBuffer>(bind->pData)));
00295 pAcc->getFirstValue(result);
00296 }
00297
00304 template <typename STDTYPE>
00305 inline void lastValue(
00306 RegisterRef<STDTYPE>* result,
00307 RegisterRef<char*>* aggDataBlock)
00308 {
00309
00310 TupleDatum *bind = aggDataBlock->getBinding(false);
00311 WinAggHistogram<STDTYPE> *pAcc =
00312 *(reinterpret_cast<WinAggHistogram<STDTYPE>**>(
00313 const_cast<PBuffer>(bind->pData)));
00314
00315
00316 pAcc->getLastValue(result);
00317 }
00318
00319 inline void lastValue(
00320 RegisterRef<char*>* result,
00321 RegisterRef<char*>* aggDataBlock)
00322 {
00323 TupleDatum *bind = aggDataBlock->getBinding(false);
00324 WinAggHistogramStrA *pAcc =
00325 *(reinterpret_cast<WinAggHistogramStrA**>(
00326 const_cast<PBuffer>(bind->pData)));
00327 pAcc->getLastValue(result);
00328 }
00329
00330 void WinAggCount(RegisterRef<int64_t>* result, RegisterRef<char*>* aggDataBlock)
00331 {
00332 count(result, aggDataBlock);
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343 void WinAggAdd(
00344 RegisterRef<int64_t>* node,
00345 RegisterRef<char*>* aggDataBlock)
00346 {
00347 add(node, aggDataBlock);
00348 }
00349
00350 void WinAggDrop(
00351 RegisterRef<int64_t>* node,
00352 RegisterRef<char*>* aggDataBlock)
00353 {
00354 drop(node, aggDataBlock);
00355 }
00356
00357 void WinAggMin(
00358 RegisterRef<int64_t>* result,
00359 RegisterRef<char*>* aggDataBlock)
00360 {
00361 min(result, aggDataBlock);
00362 }
00363
00364 void WinAggMax(
00365 RegisterRef<int64_t>* result,
00366 RegisterRef<char*>* aggDataBlock)
00367 {
00368 max(result, aggDataBlock);
00369 }
00370
00371 void WinAggSum(
00372 RegisterRef<int64_t>* result,
00373 RegisterRef<char*>* aggDataBlock)
00374 {
00375 sum(result, aggDataBlock);
00376 }
00377
00378 void WinAggAvg(
00379 RegisterRef<int64_t>* result,
00380 RegisterRef<char*>* aggDataBlock)
00381 {
00382 avg(result, aggDataBlock);
00383 }
00384
00385 void WinAggFirstValue(
00386 RegisterRef<int64_t>* result,
00387 RegisterRef<char*>* aggDataBlock)
00388 {
00389 firstValue(result, aggDataBlock);
00390 }
00391
00392 void WinAggLastValue(
00393 RegisterRef<int64_t>* result,
00394 RegisterRef<char*>* aggDataBlock)
00395 {
00396 lastValue(result, aggDataBlock);
00397 }
00398
00399
00400
00401
00402 void WinAggAdd(
00403 RegisterRef<double>* node,
00404 RegisterRef<char*>* aggDataBlock)
00405 {
00406 add(node, aggDataBlock);
00407 }
00408
00409 void WinAggDrop(
00410 RegisterRef<double>* node,
00411 RegisterRef<char*>* aggDataBlock)
00412 {
00413 drop(node, aggDataBlock);
00414 }
00415
00416 void WinAggAvg(
00417 RegisterRef<double>* result,
00418 RegisterRef<char*>* aggDataBlock)
00419 {
00420 avg(result, aggDataBlock);
00421 }
00422
00423 void WinAggSum(
00424 RegisterRef<double>* result,
00425 RegisterRef<char*>* aggDataBlock)
00426 {
00427 sum(result, aggDataBlock);
00428 }
00429
00430 void WinAggMin(
00431 RegisterRef<double>* result,
00432 RegisterRef<char*>* aggDataBlock)
00433 {
00434 min(result, aggDataBlock);
00435 }
00436
00437 void WinAggMax(
00438 RegisterRef<double>* result,
00439 RegisterRef<char*>* aggDataBlock)
00440 {
00441 max(result, aggDataBlock);
00442 }
00443
00444 void WinAggFirstValue(
00445 RegisterRef<double>* result,
00446 RegisterRef<char*>* aggDataBlock)
00447 {
00448 firstValue(result, aggDataBlock);
00449 }
00450
00451 void WinAggLastValue(
00452 RegisterRef<double>* result,
00453 RegisterRef<char*>* aggDataBlock)
00454 {
00455 lastValue(result, aggDataBlock);
00456 }
00457
00458
00459
00460
00461 void WinAggAdd(
00462 RegisterRef<char*>* node,
00463 RegisterRef<char*>* aggDataBlock)
00464 {
00465 add(node, aggDataBlock);
00466 }
00467
00468 void WinAggDrop(
00469 RegisterRef<char*>* node,
00470 RegisterRef<char*>* aggDataBlock)
00471 {
00472 drop(node, aggDataBlock);
00473 }
00474
00475
00476 void WinAggMin(
00477 RegisterRef<char*>* node,
00478 RegisterRef<char*>* aggDataBlock)
00479 {
00480 min(node, aggDataBlock);
00481 }
00482
00483 void WinAggMax(
00484 RegisterRef<char*>* node,
00485 RegisterRef<char*>* aggDataBlock)
00486 {
00487 max(node, aggDataBlock);
00488 }
00489
00490 void WinAggFirstValue(
00491 RegisterRef<char*>* node,
00492 RegisterRef<char*>* aggDataBlock)
00493 {
00494 firstValue(node, aggDataBlock);
00495 }
00496
00497 void WinAggLastValue(
00498 RegisterRef<char*>* node,
00499 RegisterRef<char*>* aggDataBlock)
00500 {
00501 lastValue(node, aggDataBlock);
00502 }
00503
00504
00505
00506
00507
00508 void
00509 ExtWinAggFuncRegister(ExtendedInstructionTable* eit)
00510 {
00511 assert(eit != NULL);
00512
00513
00514
00515
00516
00517
00518
00519 vector<StandardTypeDescriptorOrdinal> params_mm64_init;
00520 params_mm64_init.push_back(STANDARD_TYPE_VARBINARY);
00521 params_mm64_init.push_back(STANDARD_TYPE_INT_64);
00522
00523 eit->add(
00524 "WinAggInit", params_mm64_init,
00525 (ExtendedInstruction2<char*,int64_t>*) NULL,
00526 &WinAggInit);
00527
00528 vector<StandardTypeDescriptorOrdinal> params_mm32_init;
00529 params_mm32_init.push_back(STANDARD_TYPE_VARBINARY);
00530 params_mm32_init.push_back(STANDARD_TYPE_INT_32);
00531
00532 eit->add(
00533 "WinAggInit", params_mm32_init,
00534 (ExtendedInstruction2<char*,int32_t>*) NULL,
00535 &WinAggInit);
00536
00537 vector<StandardTypeDescriptorOrdinal> params_mm16_init;
00538 params_mm16_init.push_back(STANDARD_TYPE_VARBINARY);
00539 params_mm16_init.push_back(STANDARD_TYPE_INT_16);
00540
00541 eit->add(
00542 "WinAggInit", params_mm16_init,
00543 (ExtendedInstruction2<char*,int16_t>*) NULL,
00544 &WinAggInit);
00545
00546 vector<StandardTypeDescriptorOrdinal> params_mm8_init;
00547 params_mm8_init.push_back(STANDARD_TYPE_VARBINARY);
00548 params_mm8_init.push_back(STANDARD_TYPE_INT_8);
00549
00550 eit->add(
00551 "WinAggInit", params_mm8_init,
00552 (ExtendedInstruction2<char*,int8_t>*) NULL,
00553 &WinAggInit);
00554
00555
00556 vector<StandardTypeDescriptorOrdinal> params_ad_I64;
00557 params_ad_I64.push_back(STANDARD_TYPE_INT_64);
00558 params_ad_I64.push_back(STANDARD_TYPE_VARBINARY);
00559
00560 eit->add(
00561 "WinAggAdd", params_ad_I64,
00562 (ExtendedInstruction2<int64_t, char*>*) NULL,
00563 &WinAggAdd);
00564
00565 eit->add(
00566 "WinAggDrop", params_ad_I64,
00567 (ExtendedInstruction2<int64_t, char*>*) NULL,
00568 &WinAggDrop);
00569
00570 vector<StandardTypeDescriptorOrdinal> params_I64_funcs;
00571 params_I64_funcs.push_back(STANDARD_TYPE_INT_64);
00572 params_I64_funcs.push_back(STANDARD_TYPE_VARBINARY);
00573
00574 eit->add(
00575 "WinAggSum", params_I64_funcs,
00576 (ExtendedInstruction2<int64_t, char*>*) NULL,
00577 &WinAggSum);
00578
00579 eit->add(
00580 "WinAggCount", params_I64_funcs,
00581 (ExtendedInstruction2<int64_t, char*>*) NULL,
00582 &WinAggCount);
00583
00584 eit->add(
00585 "WinAggAvg", params_I64_funcs,
00586 (ExtendedInstruction2<int64_t, char*>*) NULL,
00587 &WinAggAvg);
00588
00589 eit->add(
00590 "WinAggMin", params_I64_funcs,
00591 (ExtendedInstruction2<int64_t, char*>*) NULL,
00592 &WinAggMin);
00593
00594 eit->add(
00595 "WinAggMax", params_I64_funcs,
00596 (ExtendedInstruction2<int64_t, char*>*) NULL,
00597 &WinAggMax);
00598
00599 eit->add(
00600 "WinAggFirstValue", params_I64_funcs,
00601 (ExtendedInstruction2<int64_t, char*>*) NULL,
00602 &WinAggFirstValue);
00603
00604 eit->add(
00605 "WinAggLastValue", params_I64_funcs,
00606 (ExtendedInstruction2<int64_t, char*>*) NULL,
00607 &WinAggLastValue);
00608
00609
00610 vector<StandardTypeDescriptorOrdinal> params_mmd_init;
00611 params_mmd_init.push_back(STANDARD_TYPE_VARBINARY);
00612 params_mmd_init.push_back(STANDARD_TYPE_DOUBLE);
00613
00614 eit->add(
00615 "WinAggInit", params_mmd_init,
00616 (ExtendedInstruction2<char*,double>*) NULL,
00617 &WinAggInit);
00618
00619 vector<StandardTypeDescriptorOrdinal> params_mmr_init;
00620 params_mmr_init.push_back(STANDARD_TYPE_VARBINARY);
00621 params_mmr_init.push_back(STANDARD_TYPE_REAL);
00622
00623 eit->add(
00624 "WinAggInit", params_mmr_init,
00625 (ExtendedInstruction2<char*,float>*) NULL,
00626 &WinAggInit);
00627
00628 vector<StandardTypeDescriptorOrdinal> params_DBL_funcs;
00629 params_DBL_funcs.push_back(STANDARD_TYPE_DOUBLE);
00630 params_DBL_funcs.push_back(STANDARD_TYPE_VARBINARY);
00631
00632 eit->add(
00633 "WinAggAdd", params_DBL_funcs,
00634 (ExtendedInstruction2<double, char*>*) NULL,
00635 &WinAggAdd);
00636
00637 eit->add(
00638 "WinAggDrop", params_DBL_funcs,
00639 (ExtendedInstruction2<double, char*>*) NULL,
00640 &WinAggDrop);
00641
00642 eit->add(
00643 "WinAggMin", params_DBL_funcs,
00644 (ExtendedInstruction2<double, char*>*) NULL,
00645 &WinAggMin);
00646
00647 eit->add(
00648 "WinAggMax", params_DBL_funcs,
00649 (ExtendedInstruction2<double, char*>*) NULL,
00650 &WinAggMax);
00651
00652 eit->add(
00653 "WinAggSum", params_DBL_funcs,
00654 (ExtendedInstruction2<double, char*>*) NULL,
00655 &WinAggSum);
00656
00657 eit->add(
00658 "WinAggAvg", params_DBL_funcs,
00659 (ExtendedInstruction2<double, char*>*) NULL,
00660 &WinAggAvg);
00661
00662 eit->add(
00663 "WinAggFirstValue", params_DBL_funcs,
00664 (ExtendedInstruction2<double, char*>*) NULL,
00665 &WinAggFirstValue);
00666
00667 eit->add(
00668 "WinAggLastValue", params_DBL_funcs,
00669 (ExtendedInstruction2<double, char*>*) NULL,
00670 &WinAggLastValue);
00671
00672
00673 vector<StandardTypeDescriptorOrdinal> params_mmvc_init;
00674 params_mmvc_init.push_back(STANDARD_TYPE_VARBINARY);
00675 params_mmvc_init.push_back(STANDARD_TYPE_VARCHAR);
00676
00677 eit->add(
00678 "WinAggInit", params_mmvc_init,
00679 (ExtendedInstruction2<char*,char*>*) NULL,
00680 &WinAggInit);
00681
00682 vector<StandardTypeDescriptorOrdinal> params_StrA_funcs;
00683 params_StrA_funcs.push_back(STANDARD_TYPE_VARCHAR);
00684 params_StrA_funcs.push_back(STANDARD_TYPE_VARBINARY);
00685
00686 eit->add(
00687 "WinAggAdd", params_StrA_funcs,
00688 (ExtendedInstruction2<char *, char*>*) NULL,
00689 &WinAggAdd);
00690
00691 eit->add(
00692 "WinAggDrop", params_StrA_funcs,
00693 (ExtendedInstruction2<char*, char*>*) NULL,
00694 &WinAggDrop);
00695
00696 eit->add(
00697 "WinAggMin", params_StrA_funcs,
00698 (ExtendedInstruction2<char*, char*>*) NULL,
00699 &WinAggMin);
00700
00701 eit->add(
00702 "WinAggMax", params_StrA_funcs,
00703 (ExtendedInstruction2<char*, char*>*) NULL,
00704 &WinAggMax);
00705
00706 eit->add(
00707 "WinAggFirstValue", params_StrA_funcs,
00708 (ExtendedInstruction2<char*, char*>*) NULL,
00709 &WinAggFirstValue);
00710
00711 eit->add(
00712 "WinAggLastValue", params_StrA_funcs,
00713 (ExtendedInstruction2<char*, char*>*) NULL,
00714 &WinAggLastValue);
00715
00716 vector<StandardTypeDescriptorOrdinal> params_mmc_init;
00717 params_mmc_init.push_back(STANDARD_TYPE_VARBINARY);
00718 params_mmc_init.push_back(STANDARD_TYPE_CHAR);
00719
00720 eit->add(
00721 "WinAggInit", params_mmc_init,
00722 (ExtendedInstruction2<char*,char*>*) NULL,
00723 &WinAggInit);
00724
00725 vector<StandardTypeDescriptorOrdinal> params_StrA2_funcs;
00726 params_StrA2_funcs.push_back(STANDARD_TYPE_CHAR);
00727 params_StrA2_funcs.push_back(STANDARD_TYPE_VARBINARY);
00728
00729 eit->add(
00730 "WinAggAdd", params_StrA2_funcs,
00731 (ExtendedInstruction2<char *, char*>*) NULL,
00732 &WinAggAdd);
00733
00734 eit->add(
00735 "WinAggDrop", params_StrA2_funcs,
00736 (ExtendedInstruction2<char*, char*>*) NULL,
00737 &WinAggDrop);
00738
00739 eit->add(
00740 "WinAggMin", params_StrA2_funcs,
00741 (ExtendedInstruction2<char*, char*>*) NULL,
00742 &WinAggMin);
00743
00744 eit->add(
00745 "WinAggMax", params_StrA2_funcs,
00746 (ExtendedInstruction2<char*, char*>*) NULL,
00747 &WinAggMax);
00748
00749 eit->add(
00750 "WinAggFirstValue", params_StrA2_funcs,
00751 (ExtendedInstruction2<char*, char*>*) NULL,
00752 &WinAggFirstValue);
00753
00754 eit->add(
00755 "WinAggLastValue", params_StrA2_funcs,
00756 (ExtendedInstruction2<char*, char*>*) NULL,
00757 &WinAggLastValue);
00758 }
00759
00760
00761 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/calculator/ExtWinAggFuncs.cpp#3 $");
00762
00763