MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / aggExecute

Method aggExecute

src/dsql/AggNodes.cpp:723–782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

721}
722
723dsc* AvgAggNode::aggExecute(thread_db* tdbb, Request* request) const
724{
725 impure_value_ex* impure = request->getImpure<impure_value_ex>(impureOffset);
726
727 if (!impure->vlux_count)
728 return NULL;
729
730 dsc temp;
731 SINT64 i;
732 double d;
733 Decimal128 dec;
734 Decimal64 d64;
735 Int128 i128;
736
737 impure_value_ex* impureTemp = request->getImpure<impure_value_ex>(tempImpure);
738 UCHAR dtype = impureTemp->vlu_desc.dsc_dtype;
739
740 if (!dialect1 && impure->vlu_desc.dsc_dtype == dtype_int64)
741 {
742 i = *((SINT64*) impure->vlu_desc.dsc_address) / impure->vlux_count;
743 temp.makeInt64(impure->vlu_desc.dsc_scale, &i);
744 }
745 else if (!dialect1 && impure->vlu_desc.dsc_dtype == dtype_int128)
746 {
747 i128.set(impure->vlux_count, 0);
748 i128 = ((Int128*) impure->vlu_desc.dsc_address)->div(i128, 0);
749 if (dtype == dtype_int128)
750 temp.makeInt128(impure->vlu_desc.dsc_scale, &i128);
751 else
752 {
753 fb_assert(dtype == dtype_int64);
754 i = i128.toInt64(0);
755 temp.makeInt64(impure->vlu_desc.dsc_scale, &i);
756 }
757 }
758 else if (dtype == dtype_dec128)
759 {
760 DecimalStatus decSt = tdbb->getAttachment()->att_dec_status;
761 dec.set(impure->vlux_count, decSt, 0);
762 dec = MOV_get_dec128(tdbb, &impure->vlu_desc).div(decSt, dec);
763 temp.makeDecimal128(&dec);
764 }
765 else if (dtype == dtype_dec64)
766 {
767 DecimalStatus decSt = tdbb->getAttachment()->att_dec_status;
768 // use higher precision for division
769 dec.set(impure->vlux_count, decSt, 0);
770 d64 = MOV_get_dec128(tdbb, &impure->vlu_desc).div(decSt, dec).toDecimal64(decSt);
771 temp.makeDecimal64(&d64);
772 }
773 else
774 {
775 d = MOV_get_double(tdbb, &impure->vlu_desc) / impure->vlux_count;
776 temp.makeDouble(&d);
777 }
778
779 EVL_make_value(tdbb, &temp, impureTemp);
780

Callers

nothing calls this directly

Calls 15

MOV_get_dec128Function · 0.85
MOV_get_doubleFunction · 0.85
EVL_make_valueFunction · 0.85
CDecimal128Class · 0.85
makeInt64Method · 0.80
makeInt128Method · 0.80
makeDecimal128Method · 0.80
toDecimal64Method · 0.80
makeDecimal64Method · 0.80
makeDoubleMethod · 0.80
BLB_closeMethod · 0.80
sqrtMethod · 0.80

Tested by

no test coverage detected