Skip to content

fix warnings for pg_wrapper #1383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ydb/library/yql/parser/pg_wrapper/arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ extern "C" {
namespace NYql {

extern "C" {
Y_PRAGMA_DIAGNOSTIC_PUSH
Y_PRAGMA("GCC diagnostic ignored \"-Wreturn-type-c-linkage\"")
#include "pg_kernels_fwd.inc"
Y_PRAGMA_DIAGNOSTIC_POP
}

struct TExecs {
Expand Down Expand Up @@ -114,7 +117,7 @@ std::shared_ptr<arrow::Array> PgConvertString(const std::shared_ptr<arrow::Array
for (size_t i = 0; i < length; ++i) {
auto item = reader.GetItem(*data, i);
if (!item) {
builder.AppendNull();
ARROW_OK(builder.AppendNull());
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions ydb/library/yql/parser/pg_wrapper/arrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ struct TDefaultArgsPolicy {
static constexpr std::array<bool, 0> IsFixedArg = {};
};

Y_PRAGMA_DIAGNOSTIC_PUSH
Y_PRAGMA("GCC diagnostic ignored \"-Wreturn-type-c-linkage\"")
extern "C" TPgKernelState& GetPGKernelState(arrow::compute::KernelContext* ctx);
Y_PRAGMA_DIAGNOSTIC_POP

template <typename TFunc, bool IsStrict, bool IsFixedResult, typename TArgsPolicy = TDefaultArgsPolicy>
struct TGenericExec {
Expand Down
2 changes: 1 addition & 1 deletion ydb/library/yql/parser/pg_wrapper/arrow_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ std::shared_ptr<arrow::Array> PgConvertNumeric(const std::shared_ptr<arrow::Arra
auto input = data->GetValues<T>(1);
for (size_t i = 0; i < length; ++i) {
if (value->IsNull(i)) {
builder.AppendNull();
ARROW_OK(builder.AppendNull());
continue;
}
T item = input[i];
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_wrapper/cflags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CFLAGS(
-Wno-duplicate-decl-specifier
-Wno-unused-function
-Wno-unused-variable
-Wno-unused-but-set-variable
-Wno-unused-private-field
-Wno-register
-Wno-unguarded-availability-new
Expand Down
109 changes: 75 additions & 34 deletions ydb/library/yql/parser/pg_wrapper/comp_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3499,9 +3499,9 @@ void PgDestroyContext(const std::string_view& contextType, void* ctx) {
}

template <bool PassByValue, bool IsArray>
class TPgHash : public NUdf::IHash, public NUdf::TBlockItemHasherBase<TPgHash<PassByValue, IsArray>, true> {
class TPgHashBase {
public:
TPgHash(const NYql::NPg::TTypeDesc& typeDesc)
TPgHashBase(const NYql::NPg::TTypeDesc& typeDesc)
: TypeDesc(typeDesc)
{
auto hashProcId = TypeDesc.HashProcId;
Expand All @@ -3520,10 +3520,25 @@ class TPgHash : public NUdf::IHash, public NUdf::TBlockItemHasherBase<TPgHash<Pa
Y_ENSURE(FInfoHash.fn_nargs == 1);
}

protected:
const NYql::NPg::TTypeDesc TypeDesc;

FmgrInfo FInfoHash;
};

template <bool PassByValue, bool IsArray>
class TPgHash : public TPgHashBase<PassByValue, IsArray>, public NUdf::IHash {
public:
using TBase = TPgHashBase<PassByValue, IsArray>;

TPgHash(const NYql::NPg::TTypeDesc& typeDesc)
: TBase(typeDesc)
{}

ui64 Hash(NUdf::TUnboxedValuePod lhs) const override {
LOCAL_FCINFO(callInfo, 1);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoHash); // don't copy becase of IHash isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoHash); // don't copy becase of IHash isn't threadsafe
callInfo->nargs = 1;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
Expand All @@ -3535,30 +3550,36 @@ class TPgHash : public NUdf::IHash, public NUdf::TBlockItemHasherBase<TPgHash<Pa
ScalarDatumFromPod(lhs) :
PointerDatumFromPod(lhs), false };

auto x = FInfoHash.fn_addr(callInfo);
auto x = this->FInfoHash.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetUInt32(x);
}
};

template <bool PassByValue, bool IsArray>
class TPgHashItem : public TPgHashBase<PassByValue, IsArray>, public NUdf::TBlockItemHasherBase<TPgHashItem<PassByValue, IsArray>, true> {
public:
using TBase = TPgHashBase<PassByValue, IsArray>;

TPgHashItem(const NYql::NPg::TTypeDesc& typeDesc)
: TBase(typeDesc)
{}

ui64 DoHash(NUdf::TBlockItem value) const {
LOCAL_FCINFO(callInfo, 1);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoHash); // don't copy becase of IHash isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoHash); // don't copy becase of IHash isn't threadsafe
callInfo->nargs = 1;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
callInfo->args[0] = { PassByValue ?
ScalarDatumFromItem(value) :
PointerDatumFromItem(value), false };

auto x = FInfoHash.fn_addr(callInfo);
auto x = this->FInfoHash.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetUInt32(x);
}
private:
const NYql::NPg::TTypeDesc TypeDesc;

FmgrInfo FInfoHash;
};

NUdf::IHash::TPtr MakePgHash(const NMiniKQL::TPgType* type) {
Expand All @@ -3575,18 +3596,18 @@ NUdf::IHash::TPtr MakePgHash(const NMiniKQL::TPgType* type) {
NUdf::IBlockItemHasher::TPtr MakePgItemHasher(ui32 typeId) {
const auto& typeDesc = NYql::NPg::LookupType(typeId);
if (typeDesc.PassByValue) {
return new TPgHash<true, false>(typeDesc);
return new TPgHashItem<true, false>(typeDesc);
} else if (typeDesc.TypeId == typeDesc.ArrayTypeId) {
return new TPgHash<false, true>(typeDesc);
return new TPgHashItem<false, true>(typeDesc);
} else {
return new TPgHash<false, false>(typeDesc);
return new TPgHashItem<false, false>(typeDesc);
}
}

template <bool PassByValue, bool IsArray>
class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<TPgCompare<PassByValue, IsArray>, true> {
class TPgCompareBase {
public:
TPgCompare(const NYql::NPg::TTypeDesc& typeDesc)
TPgCompareBase(const NYql::NPg::TTypeDesc& typeDesc)
: TypeDesc(typeDesc)
{
Zero(FInfoLess);
Expand Down Expand Up @@ -3623,14 +3644,29 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
Y_ENSURE(FInfoCompare.fn_nargs == 2);
}

protected:
const NYql::NPg::TTypeDesc TypeDesc;

FmgrInfo FInfoLess, FInfoCompare, FInfoEquals;
};

template <bool PassByValue, bool IsArray>
class TPgCompare : public TPgCompareBase<PassByValue, IsArray>, public NUdf::ICompare {
public:
using TBase = TPgCompareBase<PassByValue, IsArray>;

TPgCompare(const NYql::NPg::TTypeDesc& typeDesc)
: TBase(typeDesc)
{}

bool Less(NUdf::TUnboxedValuePod lhs, NUdf::TUnboxedValuePod rhs) const override {
if constexpr (IsArray) {
return Compare(lhs, rhs) < 0;
}

LOCAL_FCINFO(callInfo, 2);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoLess); // don't copy becase of ICompare isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoLess); // don't copy becase of ICompare isn't threadsafe
callInfo->nargs = 2;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
Expand All @@ -3653,15 +3689,15 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
ScalarDatumFromPod(rhs) :
PointerDatumFromPod(rhs), false };

auto x = FInfoLess.fn_addr(callInfo);
auto x = this->FInfoLess.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetBool(x);
}

int Compare(NUdf::TUnboxedValuePod lhs, NUdf::TUnboxedValuePod rhs) const override {
LOCAL_FCINFO(callInfo, 2);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoCompare); // don't copy becase of ICompare isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoCompare); // don't copy becase of ICompare isn't threadsafe
callInfo->nargs = 2;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
Expand All @@ -3684,15 +3720,25 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
ScalarDatumFromPod(rhs) :
PointerDatumFromPod(rhs), false };

auto x = FInfoCompare.fn_addr(callInfo);
auto x = this->FInfoCompare.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetInt32(x);
}
};

template <bool PassByValue, bool IsArray>
class TPgCompareItem : public TPgCompareBase<PassByValue, IsArray>, public NUdf::TBlockItemComparatorBase<TPgCompareItem<PassByValue, IsArray>, true> {
public:
using TBase = TPgCompareBase<PassByValue, IsArray>;

TPgCompareItem(const NYql::NPg::TTypeDesc& typeDesc)
: TBase(typeDesc)
{}

i64 DoCompare(NUdf::TBlockItem lhs, NUdf::TBlockItem rhs) const {
LOCAL_FCINFO(callInfo, 2);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoCompare); // don't copy becase of ICompare isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoCompare); // don't copy becase of ICompare isn't threadsafe
callInfo->nargs = 2;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
Expand All @@ -3703,7 +3749,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
ScalarDatumFromItem(rhs) :
PointerDatumFromItem(rhs), false };

auto x = FInfoCompare.fn_addr(callInfo);
auto x = this->FInfoCompare.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetInt32(x);
}
Expand All @@ -3715,7 +3761,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<

LOCAL_FCINFO(callInfo, 2);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoEquals); // don't copy becase of ICompare isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoEquals); // don't copy becase of ICompare isn't threadsafe
callInfo->nargs = 2;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
Expand All @@ -3726,7 +3772,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
ScalarDatumFromItem(rhs) :
PointerDatumFromItem(rhs), false };

auto x = FInfoEquals.fn_addr(callInfo);
auto x = this->FInfoEquals.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetBool(x);
}
Expand All @@ -3738,7 +3784,7 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<

LOCAL_FCINFO(callInfo, 2);
Zero(*callInfo);
callInfo->flinfo = const_cast<FmgrInfo*>(&FInfoLess); // don't copy becase of ICompare isn't threadsafe
callInfo->flinfo = const_cast<FmgrInfo*>(&this->FInfoLess); // don't copy becase of ICompare isn't threadsafe
callInfo->nargs = 2;
callInfo->fncollation = DEFAULT_COLLATION_OID;
callInfo->isnull = false;
Expand All @@ -3749,15 +3795,10 @@ class TPgCompare : public NUdf::ICompare, public NUdf::TBlockItemComparatorBase<
ScalarDatumFromItem(rhs) :
PointerDatumFromItem(rhs), false };

auto x = FInfoLess.fn_addr(callInfo);
auto x = this->FInfoLess.fn_addr(callInfo);
Y_ENSURE(!callInfo->isnull);
return DatumGetBool(x);
}

private:
const NYql::NPg::TTypeDesc TypeDesc;

FmgrInfo FInfoLess, FInfoCompare, FInfoEquals;
};

NUdf::ICompare::TPtr MakePgCompare(const NMiniKQL::TPgType* type) {
Expand All @@ -3774,11 +3815,11 @@ NUdf::ICompare::TPtr MakePgCompare(const NMiniKQL::TPgType* type) {
NUdf::IBlockItemComparator::TPtr MakePgItemComparator(ui32 typeId) {
const auto& typeDesc = NYql::NPg::LookupType(typeId);
if (typeDesc.PassByValue) {
return new TPgCompare<true, false>(typeDesc);
return new TPgCompareItem<true, false>(typeDesc);
} else if (typeDesc.TypeId == typeDesc.ArrayTypeId) {
return new TPgCompare<false, true>(typeDesc);
return new TPgCompareItem<false, true>(typeDesc);
} else {
return new TPgCompare<false, false>(typeDesc);
return new TPgCompareItem<false, false>(typeDesc);
}
}

Expand Down Expand Up @@ -3952,7 +3993,7 @@ class TPgBuilderImpl : public NUdf::IPgBuilder {

NUdf::TStringRef AsCStringBuffer(const NUdf::TUnboxedValue& value) const override {
auto x = (const char*)PointerDatumFromPod(value);
return { x, strlen(x) + 1};
return { x, ui32(strlen(x) + 1)};
}

NUdf::TStringRef AsTextBuffer(const NUdf::TUnboxedValue& value) const override {
Expand Down
3 changes: 3 additions & 0 deletions ydb/library/yql/parser/pg_wrapper/generate_kernels.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,15 @@ def main():
'\n'
'extern "C" {\n'
'\n'
'Y_PRAGMA_DIAGNOSTIC_PUSH\n'
'Y_PRAGMA("GCC diagnostic ignored \\"-Wreturn-type-c-linkage\\"")\n'
'#ifdef USE_SLOW_PG_KERNELS\n'
'#include "pg_kernels.slow.INDEX.inc"\n'
'#else\n'
'#include "pg_proc_policies.INDEX.inc"\n'
'#include "pg_kernels.INDEX.inc"\n'
'#endif\n'
'Y_PRAGMA_DIAGNOSTIC_POP\n'
'\n'
'}\n'
'\n'
Expand Down
3 changes: 3 additions & 0 deletions ydb/library/yql/parser/pg_wrapper/pg_aggs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ namespace NYql {

extern "C" {

Y_PRAGMA_DIAGNOSTIC_PUSH
Y_PRAGMA("GCC diagnostic ignored \"-Wreturn-type-c-linkage\"")
#ifdef USE_SLOW_PG_KERNELS
#include "pg_aggs.slow.inc"
#else
#include "pg_proc_policies.all.inc"
#include "pg_aggs.inc"
#endif
Y_PRAGMA_DIAGNOSTIC_POP

}

Expand Down
Loading