Skip to content

Pass pg extensions & catalog to mrjob #7516

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
Aug 7, 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
14 changes: 14 additions & 0 deletions ydb/library/yql/ast/yql_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3282,6 +3282,20 @@ ui32 TPgExprType::GetFlags(ui32 typeId) {
return ret;
}

ui64 TPgExprType::GetPgExtensionsMask(ui32 typeId) {
auto descPtr = &NPg::LookupType(typeId);
return MakePgExtensionMask(descPtr->ExtensionIndex);
}

ui64 MakePgExtensionMask(ui32 extensionIndex) {
if (!extensionIndex) {
return 0;
}

YQL_ENSURE(extensionIndex <= 64);
return 1ull << (extensionIndex - 1);
}

TExprContext::TExprContext(ui64 nextUniqueId)
: StringPool(4096)
, NextUniqueId(nextUniqueId)
Expand Down
74 changes: 47 additions & 27 deletions ydb/library/yql/ast/yql_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ void ReportError(TExprContext& ctx, const TIssue& issue);

class TTypeAnnotationNode {
protected:
TTypeAnnotationNode(ETypeAnnotationKind kind, ui32 flags, ui64 hash)
TTypeAnnotationNode(ETypeAnnotationKind kind, ui32 flags, ui64 hash, ui64 usedPgExtensions)
: Kind(kind)
, Flags(flags)
, Hash(hash)
, UsedPgExtensions(usedPgExtensions)
{
}

Expand Down Expand Up @@ -278,6 +279,10 @@ class TTypeAnnotationNode {
return Hash;
}

ui64 GetUsedPgExtensions() const {
return UsedPgExtensions;
}

bool Equals(const TTypeAnnotationNode& node) const;
void Accept(TTypeAnnotationVisitor& visitor) const;

Expand Down Expand Up @@ -310,10 +315,21 @@ class TTypeAnnotationNode {
return flags;
}

template <typename T>
static ui64 CombinePgExtensions(const T& items) {
ui64 mask = 0;
for (auto& item : items) {
mask |= item->GetUsedPgExtensions();
}

return mask;
}

private:
const ETypeAnnotationKind Kind;
const ui32 Flags;
const ui64 Hash;
const ui64 UsedPgExtensions;
};

class TUnitExprType : public TTypeAnnotationNode {
Expand All @@ -322,7 +338,7 @@ class TUnitExprType : public TTypeAnnotationNode {

TUnitExprType(ui64 hash)
: TTypeAnnotationNode(KindValue,
TypeNonComputable | TypeNonPersistable, hash)
TypeNonComputable | TypeNonPersistable, hash, 0)
{
}

Expand All @@ -341,7 +357,7 @@ class TTupleExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Tuple;

TTupleExprType(ui64 hash, const TTypeAnnotationNode::TListType& items)
: TTypeAnnotationNode(KindValue, CombineFlags(items), hash)
: TTypeAnnotationNode(KindValue, CombineFlags(items), hash, CombinePgExtensions(items))
, Items(items)
{
}
Expand Down Expand Up @@ -390,7 +406,7 @@ class TMultiExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Multi;

TMultiExprType(ui64 hash, const TTypeAnnotationNode::TListType& items)
: TTypeAnnotationNode(KindValue, CombineFlags(items), hash)
: TTypeAnnotationNode(KindValue, CombineFlags(items), hash, CombinePgExtensions(items))
, Items(items)
{
}
Expand Down Expand Up @@ -445,7 +461,7 @@ class TItemExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Item;

TItemExprType(ui64 hash, const TStringBuf& name, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, itemType->GetFlags(), hash)
: TTypeAnnotationNode(KindValue, itemType->GetFlags(), hash, itemType->GetUsedPgExtensions())
, Name(name)
, ItemType(itemType)
{
Expand Down Expand Up @@ -501,7 +517,7 @@ class TStructExprType : public TTypeAnnotationNode {
};

TStructExprType(ui64 hash, const TVector<const TItemExprType*>& items)
: TTypeAnnotationNode(KindValue, TypeNonComparable | CombineFlags(items), hash)
: TTypeAnnotationNode(KindValue, TypeNonComparable | CombineFlags(items), hash, CombinePgExtensions(items))
, Items(items)
{
}
Expand Down Expand Up @@ -623,7 +639,7 @@ class TListExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::List;

TListExprType(ui64 hash, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeHasDynamicSize, hash)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeHasDynamicSize, hash, itemType->GetUsedPgExtensions())
, ItemType(itemType)
{
}
Expand All @@ -650,7 +666,7 @@ class TStreamExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Stream;

TStreamExprType(ui64 hash, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash, itemType->GetUsedPgExtensions())
, ItemType(itemType)
{
}
Expand All @@ -677,7 +693,7 @@ class TFlowExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Flow;

TFlowExprType(ui64 hash, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash, itemType->GetUsedPgExtensions())
, ItemType(itemType)
{
}
Expand All @@ -704,7 +720,7 @@ class TBlockExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Block;

TBlockExprType(ui64 hash, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash, itemType->GetUsedPgExtensions())
, ItemType(itemType)
{
}
Expand All @@ -731,7 +747,7 @@ class TScalarExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Scalar;

TScalarExprType(ui64 hash, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash)
: TTypeAnnotationNode(KindValue, itemType->GetFlags() | TypeNonPersistable, hash, itemType->GetUsedPgExtensions())
, ItemType(itemType)
{
}
Expand All @@ -758,7 +774,7 @@ class TDataExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Data;

TDataExprType(ui64 hash, EDataSlot slot)
: TTypeAnnotationNode(KindValue, GetFlags(slot), hash)
: TTypeAnnotationNode(KindValue, GetFlags(slot), hash, 0)
, Slot(slot)
{
}
Expand Down Expand Up @@ -853,7 +869,7 @@ class TPgExprType : public TTypeAnnotationNode {

// TODO: TypeHasDynamicSize for Pg types
TPgExprType(ui64 hash, ui32 typeId)
: TTypeAnnotationNode(KindValue, GetFlags(typeId), hash)
: TTypeAnnotationNode(KindValue, GetFlags(typeId), hash, GetPgExtensionsMask(typeId))
, TypeId(typeId)
{
}
Expand All @@ -875,18 +891,21 @@ class TPgExprType : public TTypeAnnotationNode {

private:
ui32 GetFlags(ui32 typeId);
ui64 GetPgExtensionsMask(ui32 typeId);

private:
ui32 TypeId;
};

ui64 MakePgExtensionMask(ui32 extensionIndex);

class TWorldExprType : public TTypeAnnotationNode {
public:
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::World;

TWorldExprType(ui64 hash)
: TTypeAnnotationNode(KindValue,
TypeNonComposable | TypeNonComputable | TypeNonPersistable | TypeNonInspectable, hash)
TypeNonComposable | TypeNonComputable | TypeNonPersistable | TypeNonInspectable, hash, 0)
{
}

Expand All @@ -905,7 +924,7 @@ class TOptionalExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Optional;

TOptionalExprType(ui64 hash, const TTypeAnnotationNode* itemType)
: TTypeAnnotationNode(KindValue, GetFlags(itemType), hash)
: TTypeAnnotationNode(KindValue, GetFlags(itemType), hash, itemType->GetUsedPgExtensions())
, ItemType(itemType)
{
}
Expand Down Expand Up @@ -945,7 +964,7 @@ class TVariantExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Variant;

TVariantExprType(ui64 hash, const TTypeAnnotationNode* underlyingType)
: TTypeAnnotationNode(KindValue, MakeFlags(underlyingType), hash)
: TTypeAnnotationNode(KindValue, MakeFlags(underlyingType), hash, underlyingType->GetUsedPgExtensions())
, UnderlyingType(underlyingType)
{
}
Expand Down Expand Up @@ -977,7 +996,7 @@ class TTypeExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Type;

TTypeExprType(ui64 hash, const TTypeAnnotationNode* type)
: TTypeAnnotationNode(KindValue, TypeNonPersistable | TypeNonComputable, hash)
: TTypeAnnotationNode(KindValue, TypeNonPersistable | TypeNonComputable, hash, 0)
, Type(type)
{
}
Expand Down Expand Up @@ -1005,7 +1024,8 @@ class TDictExprType : public TTypeAnnotationNode {

TDictExprType(ui64 hash, const TTypeAnnotationNode* keyType, const TTypeAnnotationNode* payloadType)
: TTypeAnnotationNode(KindValue, TypeNonComparable | TypeHasDynamicSize |
keyType->GetFlags() | payloadType->GetFlags(), hash)
keyType->GetFlags() | payloadType->GetFlags(), hash,
keyType->GetUsedPgExtensions() | payloadType->GetUsedPgExtensions())
, KeyType(keyType)
, PayloadType(payloadType)
{
Expand Down Expand Up @@ -1042,7 +1062,7 @@ class TVoidExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Void;

TVoidExprType(ui64 hash)
: TTypeAnnotationNode(KindValue, 0, hash)
: TTypeAnnotationNode(KindValue, 0, hash, 0)
{
}

Expand All @@ -1061,7 +1081,7 @@ class TNullExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Null;

TNullExprType(ui64 hash)
: TTypeAnnotationNode(KindValue, TypeHasNull, hash)
: TTypeAnnotationNode(KindValue, TypeHasNull, hash, 0)
{
}

Expand Down Expand Up @@ -1101,7 +1121,7 @@ class TCallableExprType : public TTypeAnnotationNode {

TCallableExprType(ui64 hash, const TTypeAnnotationNode* returnType, const TVector<TArgumentInfo>& arguments
, size_t optionalArgumentsCount, const TStringBuf& payload)
: TTypeAnnotationNode(KindValue, MakeFlags(returnType), hash)
: TTypeAnnotationNode(KindValue, MakeFlags(returnType), hash, returnType->GetUsedPgExtensions())
, ReturnType(returnType)
, Arguments(arguments)
, OptionalArgumentsCount(optionalArgumentsCount)
Expand Down Expand Up @@ -1207,7 +1227,7 @@ class TGenericExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Generic;

TGenericExprType(ui64 hash)
: TTypeAnnotationNode(KindValue, TypeNonComputable, hash)
: TTypeAnnotationNode(KindValue, TypeNonComputable, hash, 0)
{
}

Expand All @@ -1226,7 +1246,7 @@ class TResourceExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Resource;

TResourceExprType(ui64 hash, const TStringBuf& tag)
: TTypeAnnotationNode(KindValue, TypeNonPersistable | TypeHasManyValues, hash)
: TTypeAnnotationNode(KindValue, TypeNonPersistable | TypeHasManyValues, hash, 0)
, Tag(tag)
{}

Expand All @@ -1253,7 +1273,7 @@ class TTaggedExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Tagged;

TTaggedExprType(ui64 hash, const TTypeAnnotationNode* baseType, const TStringBuf& tag)
: TTypeAnnotationNode(KindValue, baseType->GetFlags(), hash)
: TTypeAnnotationNode(KindValue, baseType->GetFlags(), hash, baseType->GetUsedPgExtensions())
, BaseType(baseType)
, Tag(tag)
{}
Expand Down Expand Up @@ -1290,7 +1310,7 @@ class TErrorExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::Error;

TErrorExprType(ui64 hash, const TIssue& error)
: TTypeAnnotationNode(KindValue, 0, hash)
: TTypeAnnotationNode(KindValue, 0, hash, 0)
, Error(error)
{}

Expand All @@ -1315,7 +1335,7 @@ class TEmptyListExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::EmptyList;

TEmptyListExprType(ui64 hash)
: TTypeAnnotationNode(KindValue, 0, hash)
: TTypeAnnotationNode(KindValue, 0, hash, 0)
{
}

Expand All @@ -1334,7 +1354,7 @@ class TEmptyDictExprType : public TTypeAnnotationNode {
static constexpr ETypeAnnotationKind KindValue = ETypeAnnotationKind::EmptyDict;

TEmptyDictExprType(ui64 hash)
: TTypeAnnotationNode(KindValue, 0, hash)
: TTypeAnnotationNode(KindValue, 0, hash, 0)
{
}

Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/core/pg_ext/yql_pg_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void PgExtensionsFromProto(const NYql::NProto::TPgExtensions& proto,

desc.LibraryPath = e.GetLibraryPath();
desc.TypesOnly = e.GetTypesOnly();
desc.LibraryMD5 = e.GetLibraryMD5();
extensions.emplace_back(desc);
}
}
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/core/yql_user_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum class EUserDataBlockUsage {
Content,
Udf,
Library,
PgExt,
End,
};
typedef TEnumBitSet<EUserDataBlockUsage, static_cast<int>(EUserDataBlockUsage::Begin),
Expand Down
Loading
Loading