@@ -3500,9 +3500,9 @@ void PgDestroyContext(const std::string_view& contextType, void* ctx) {
3500
3500
}
3501
3501
3502
3502
template <bool PassByValue, bool IsArray>
3503
- class TPgHash : public NUdf ::IHash, public NUdf::TBlockItemHasherBase<TPgHash<PassByValue, IsArray>, true > {
3503
+ class TPgHashBase {
3504
3504
public:
3505
- TPgHash (const NYql::NPg::TTypeDesc& typeDesc)
3505
+ TPgHashBase (const NYql::NPg::TTypeDesc& typeDesc)
3506
3506
: TypeDesc(typeDesc)
3507
3507
{
3508
3508
auto hashProcId = TypeDesc.HashProcId ;
@@ -3521,10 +3521,25 @@ class TPgHash : public NUdf::IHash, public NUdf::TBlockItemHasherBase<TPgHash<Pa
3521
3521
Y_ENSURE (FInfoHash.fn_nargs == 1 );
3522
3522
}
3523
3523
3524
+ protected:
3525
+ const NYql::NPg::TTypeDesc TypeDesc;
3526
+
3527
+ FmgrInfo FInfoHash;
3528
+ };
3529
+
3530
+ template <bool PassByValue, bool IsArray>
3531
+ class TPgHash : public TPgHashBase <PassByValue, IsArray>, public NUdf::IHash {
3532
+ public:
3533
+ using TBase = TPgHashBase<PassByValue, IsArray>;
3534
+
3535
+ TPgHash (const NYql::NPg::TTypeDesc& typeDesc)
3536
+ : TBase(typeDesc)
3537
+ {}
3538
+
3524
3539
ui64 Hash (NUdf::TUnboxedValuePod lhs) const override {
3525
3540
LOCAL_FCINFO (callInfo, 1 );
3526
3541
Zero (*callInfo);
3527
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoHash); // don't copy becase of IHash isn't threadsafe
3542
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoHash ); // don't copy becase of IHash isn't threadsafe
3528
3543
callInfo->nargs = 1 ;
3529
3544
callInfo->fncollation = DEFAULT_COLLATION_OID;
3530
3545
callInfo->isnull = false ;
@@ -3536,30 +3551,36 @@ class TPgHash : public NUdf::IHash, public NUdf::TBlockItemHasherBase<TPgHash<Pa
3536
3551
ScalarDatumFromPod (lhs) :
3537
3552
PointerDatumFromPod (lhs), false };
3538
3553
3539
- auto x = FInfoHash.fn_addr (callInfo);
3554
+ auto x = this -> FInfoHash .fn_addr (callInfo);
3540
3555
Y_ENSURE (!callInfo->isnull );
3541
3556
return DatumGetUInt32 (x);
3542
3557
}
3558
+ };
3559
+
3560
+ template <bool PassByValue, bool IsArray>
3561
+ class TPgHashItem : public TPgHashBase <PassByValue, IsArray>, public NUdf::TBlockItemHasherBase<TPgHashItem<PassByValue, IsArray>, true > {
3562
+ public:
3563
+ using TBase = TPgHashBase<PassByValue, IsArray>;
3564
+
3565
+ TPgHashItem (const NYql::NPg::TTypeDesc& typeDesc)
3566
+ : TBase(typeDesc)
3567
+ {}
3543
3568
3544
3569
ui64 DoHash (NUdf::TBlockItem value) const {
3545
3570
LOCAL_FCINFO (callInfo, 1 );
3546
3571
Zero (*callInfo);
3547
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoHash); // don't copy becase of IHash isn't threadsafe
3572
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoHash ); // don't copy becase of IHash isn't threadsafe
3548
3573
callInfo->nargs = 1 ;
3549
3574
callInfo->fncollation = DEFAULT_COLLATION_OID;
3550
3575
callInfo->isnull = false ;
3551
3576
callInfo->args [0 ] = { PassByValue ?
3552
3577
ScalarDatumFromItem (value) :
3553
3578
PointerDatumFromItem (value), false };
3554
3579
3555
- auto x = FInfoHash.fn_addr (callInfo);
3580
+ auto x = this -> FInfoHash .fn_addr (callInfo);
3556
3581
Y_ENSURE (!callInfo->isnull );
3557
3582
return DatumGetUInt32 (x);
3558
3583
}
3559
- private:
3560
- const NYql::NPg::TTypeDesc TypeDesc;
3561
-
3562
- FmgrInfo FInfoHash;
3563
3584
};
3564
3585
3565
3586
NUdf::IHash::TPtr MakePgHash (const NMiniKQL::TPgType* type) {
@@ -3576,18 +3597,18 @@ NUdf::IHash::TPtr MakePgHash(const NMiniKQL::TPgType* type) {
3576
3597
NUdf::IBlockItemHasher::TPtr MakePgItemHasher (ui32 typeId) {
3577
3598
const auto & typeDesc = NYql::NPg::LookupType (typeId);
3578
3599
if (typeDesc.PassByValue ) {
3579
- return new TPgHash <true , false >(typeDesc);
3600
+ return new TPgHashItem <true , false >(typeDesc);
3580
3601
} else if (typeDesc.TypeId == typeDesc.ArrayTypeId ) {
3581
- return new TPgHash <false , true >(typeDesc);
3602
+ return new TPgHashItem <false , true >(typeDesc);
3582
3603
} else {
3583
- return new TPgHash <false , false >(typeDesc);
3604
+ return new TPgHashItem <false , false >(typeDesc);
3584
3605
}
3585
3606
}
3586
3607
3587
3608
template <bool PassByValue, bool IsArray>
3588
- class TPgCompare : public NUdf ::ICompare, public NUdf::TBlockItemComparatorBase<TPgCompare<PassByValue, IsArray>, true > {
3609
+ class TPgCompareBase {
3589
3610
public:
3590
- TPgCompare (const NYql::NPg::TTypeDesc& typeDesc)
3611
+ TPgCompareBase (const NYql::NPg::TTypeDesc& typeDesc)
3591
3612
: TypeDesc(typeDesc)
3592
3613
{
3593
3614
Zero (FInfoLess);
@@ -3624,14 +3645,29 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3624
3645
Y_ENSURE (FInfoCompare.fn_nargs == 2 );
3625
3646
}
3626
3647
3648
+ protected:
3649
+ const NYql::NPg::TTypeDesc TypeDesc;
3650
+
3651
+ FmgrInfo FInfoLess, FInfoCompare, FInfoEquals;
3652
+ };
3653
+
3654
+ template <bool PassByValue, bool IsArray>
3655
+ class TPgCompare : public TPgCompareBase <PassByValue, IsArray>, public NUdf::ICompare {
3656
+ public:
3657
+ using TBase = TPgCompareBase<PassByValue, IsArray>;
3658
+
3659
+ TPgCompare (const NYql::NPg::TTypeDesc& typeDesc)
3660
+ : TBase(typeDesc)
3661
+ {}
3662
+
3627
3663
bool Less (NUdf::TUnboxedValuePod lhs, NUdf::TUnboxedValuePod rhs) const override {
3628
3664
if constexpr (IsArray) {
3629
3665
return Compare (lhs, rhs) < 0 ;
3630
3666
}
3631
3667
3632
3668
LOCAL_FCINFO (callInfo, 2 );
3633
3669
Zero (*callInfo);
3634
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoLess); // don't copy becase of ICompare isn't threadsafe
3670
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoLess ); // don't copy becase of ICompare isn't threadsafe
3635
3671
callInfo->nargs = 2 ;
3636
3672
callInfo->fncollation = DEFAULT_COLLATION_OID;
3637
3673
callInfo->isnull = false ;
@@ -3654,15 +3690,15 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3654
3690
ScalarDatumFromPod (rhs) :
3655
3691
PointerDatumFromPod (rhs), false };
3656
3692
3657
- auto x = FInfoLess.fn_addr (callInfo);
3693
+ auto x = this -> FInfoLess .fn_addr (callInfo);
3658
3694
Y_ENSURE (!callInfo->isnull );
3659
3695
return DatumGetBool (x);
3660
3696
}
3661
3697
3662
3698
int Compare (NUdf::TUnboxedValuePod lhs, NUdf::TUnboxedValuePod rhs) const override {
3663
3699
LOCAL_FCINFO (callInfo, 2 );
3664
3700
Zero (*callInfo);
3665
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoCompare); // don't copy becase of ICompare isn't threadsafe
3701
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoCompare ); // don't copy becase of ICompare isn't threadsafe
3666
3702
callInfo->nargs = 2 ;
3667
3703
callInfo->fncollation = DEFAULT_COLLATION_OID;
3668
3704
callInfo->isnull = false ;
@@ -3685,15 +3721,25 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3685
3721
ScalarDatumFromPod (rhs) :
3686
3722
PointerDatumFromPod (rhs), false };
3687
3723
3688
- auto x = FInfoCompare.fn_addr (callInfo);
3724
+ auto x = this -> FInfoCompare .fn_addr (callInfo);
3689
3725
Y_ENSURE (!callInfo->isnull );
3690
3726
return DatumGetInt32 (x);
3691
3727
}
3728
+ };
3729
+
3730
+ template <bool PassByValue, bool IsArray>
3731
+ class TPgCompareItem : public TPgCompareBase <PassByValue, IsArray>, public NUdf::TBlockItemComparatorBase<TPgCompareItem<PassByValue, IsArray>, true > {
3732
+ public:
3733
+ using TBase = TPgCompareBase<PassByValue, IsArray>;
3734
+
3735
+ TPgCompareItem (const NYql::NPg::TTypeDesc& typeDesc)
3736
+ : TBase(typeDesc)
3737
+ {}
3692
3738
3693
3739
i64 DoCompare (NUdf::TBlockItem lhs, NUdf::TBlockItem rhs) const {
3694
3740
LOCAL_FCINFO (callInfo, 2 );
3695
3741
Zero (*callInfo);
3696
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoCompare); // don't copy becase of ICompare isn't threadsafe
3742
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoCompare ); // don't copy becase of ICompare isn't threadsafe
3697
3743
callInfo->nargs = 2 ;
3698
3744
callInfo->fncollation = DEFAULT_COLLATION_OID;
3699
3745
callInfo->isnull = false ;
@@ -3704,7 +3750,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3704
3750
ScalarDatumFromItem (rhs) :
3705
3751
PointerDatumFromItem (rhs), false };
3706
3752
3707
- auto x = FInfoCompare.fn_addr (callInfo);
3753
+ auto x = this -> FInfoCompare .fn_addr (callInfo);
3708
3754
Y_ENSURE (!callInfo->isnull );
3709
3755
return DatumGetInt32 (x);
3710
3756
}
@@ -3716,7 +3762,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3716
3762
3717
3763
LOCAL_FCINFO (callInfo, 2 );
3718
3764
Zero (*callInfo);
3719
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoEquals); // don't copy becase of ICompare isn't threadsafe
3765
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoEquals ); // don't copy becase of ICompare isn't threadsafe
3720
3766
callInfo->nargs = 2 ;
3721
3767
callInfo->fncollation = DEFAULT_COLLATION_OID;
3722
3768
callInfo->isnull = false ;
@@ -3727,7 +3773,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3727
3773
ScalarDatumFromItem (rhs) :
3728
3774
PointerDatumFromItem (rhs), false };
3729
3775
3730
- auto x = FInfoEquals.fn_addr (callInfo);
3776
+ auto x = this -> FInfoEquals .fn_addr (callInfo);
3731
3777
Y_ENSURE (!callInfo->isnull );
3732
3778
return DatumGetBool (x);
3733
3779
}
@@ -3739,7 +3785,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3739
3785
3740
3786
LOCAL_FCINFO (callInfo, 2 );
3741
3787
Zero (*callInfo);
3742
- callInfo->flinfo = const_cast <FmgrInfo*>(&FInfoLess); // don't copy becase of ICompare isn't threadsafe
3788
+ callInfo->flinfo = const_cast <FmgrInfo*>(&this -> FInfoLess ); // don't copy becase of ICompare isn't threadsafe
3743
3789
callInfo->nargs = 2 ;
3744
3790
callInfo->fncollation = DEFAULT_COLLATION_OID;
3745
3791
callInfo->isnull = false ;
@@ -3750,15 +3796,10 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
3750
3796
ScalarDatumFromItem (rhs) :
3751
3797
PointerDatumFromItem (rhs), false };
3752
3798
3753
- auto x = FInfoLess.fn_addr (callInfo);
3799
+ auto x = this -> FInfoLess .fn_addr (callInfo);
3754
3800
Y_ENSURE (!callInfo->isnull );
3755
3801
return DatumGetBool (x);
3756
3802
}
3757
-
3758
- private:
3759
- const NYql::NPg::TTypeDesc TypeDesc;
3760
-
3761
- FmgrInfo FInfoLess, FInfoCompare, FInfoEquals;
3762
3803
};
3763
3804
3764
3805
NUdf::ICompare::TPtr MakePgCompare (const NMiniKQL::TPgType* type) {
@@ -3775,11 +3816,11 @@ NUdf::ICompare::TPtr MakePgCompare(const NMiniKQL::TPgType* type) {
3775
3816
NUdf::IBlockItemComparator::TPtr MakePgItemComparator (ui32 typeId) {
3776
3817
const auto & typeDesc = NYql::NPg::LookupType (typeId);
3777
3818
if (typeDesc.PassByValue ) {
3778
- return new TPgCompare <true , false >(typeDesc);
3819
+ return new TPgCompareItem <true , false >(typeDesc);
3779
3820
} else if (typeDesc.TypeId == typeDesc.ArrayTypeId ) {
3780
- return new TPgCompare <false , true >(typeDesc);
3821
+ return new TPgCompareItem <false , true >(typeDesc);
3781
3822
} else {
3782
- return new TPgCompare <false , false >(typeDesc);
3823
+ return new TPgCompareItem <false , false >(typeDesc);
3783
3824
}
3784
3825
}
3785
3826
@@ -3959,7 +4000,7 @@ class TPgBuilderImpl : public NUdf::IPgBuilder {
3959
4000
3960
4001
NUdf::TStringRef AsCStringBuffer (const NUdf::TUnboxedValue& value) const override {
3961
4002
auto x = (const char *)PointerDatumFromPod (value);
3962
- return { x, strlen (x) + 1 };
4003
+ return { x, ui32 ( strlen (x) + 1 ) };
3963
4004
}
3964
4005
3965
4006
NUdf::TStringRef AsTextBuffer (const NUdf::TUnboxedValue& value) const override {
0 commit comments