@@ -10917,12 +10917,18 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
10917
10917
10918
10918
bool IsValidTypeForRanges(const TTypeAnnotationNode* type) {
10919
10919
YQL_ENSURE(type);
10920
+ // top level optional is always present and used for +- infinity value
10920
10921
if (type->GetKind() != ETypeAnnotationKind::Optional) {
10921
10922
return false;
10922
10923
}
10924
+ type = type->Cast<TOptionalExprType>()->GetItemType();
10925
+ bool hasOptionals = type->GetKind() == ETypeAnnotationKind::Optional;
10923
10926
type = RemoveAllOptionals(type);
10924
10927
YQL_ENSURE(type);
10925
- return type->GetKind() == ETypeAnnotationKind::Data && type->IsComparable() && type->IsEquatable();
10928
+ if (!type->IsComparable() || !type->IsEquatable()) {
10929
+ return false;
10930
+ }
10931
+ return type->GetKind() == ETypeAnnotationKind::Data || (type->GetKind() == ETypeAnnotationKind::Pg && !hasOptionals);
10926
10932
}
10927
10933
10928
10934
bool EnsureValidRangeBoundary(TPositionHandle pos, const TTypeAnnotationNode* type, TExprContext& ctx) {
@@ -10957,7 +10963,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
10957
10963
ctx.AddError(TIssue(ctx.GetPosition(pos),
10958
10964
TStringBuilder() << "Expected " << i <<
10959
10965
"th component of range boundary tuple to be (multi) optional of "
10960
- "comparable and equatable Data type, but got: " << *itemType));
10966
+ "comparable and equatable Data or Pg type, but got: " << *itemType));
10961
10967
return false;
10962
10968
}
10963
10969
}
@@ -11043,7 +11049,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11043
11049
if (!IsValidTypeForRanges(items[i])) {
11044
11050
ctx.AddError(TIssue(ctx.GetPosition(pos),
11045
11051
TStringBuilder() << "Expected " << i << "th component of range boundary tuple to be (multi) optional of "
11046
- "comparable and equatable Data type, but got: " << *items[i]));
11052
+ "comparable and equatable Data or Pg type, but got: " << *items[i]));
11047
11053
return false;
11048
11054
}
11049
11055
resultBoundaryItems.push_back(int32Type);
@@ -11152,7 +11158,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11152
11158
for (auto& optKeyType : optKeys) {
11153
11159
if (!IsValidTypeForRanges(optKeyType)) {
11154
11160
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Head().Pos()),
11155
- TStringBuilder() << "Expected (multi) optional of comparable and equatable Data type, but got: " << *optKeyType));
11161
+ TStringBuilder() << "Expected (multi) optional of comparable and equatable Data or Pg type, but got: " << *optKeyType));
11156
11162
return IGraphTransformer::TStatus::Error;
11157
11163
}
11158
11164
resultBoundaryItems.push_back(int32Type);
@@ -11198,8 +11204,13 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11198
11204
if (op != "Exists" && op != "NotExists") {
11199
11205
valueBaseType = RemoveAllOptionals(valueType);
11200
11206
YQL_ENSURE(valueBaseType);
11201
- if (valueBaseType->GetKind() != ETypeAnnotationKind::Data &&
11202
- valueBaseType->GetKind() != ETypeAnnotationKind::Null)
11207
+ const auto valueKind = valueBaseType->GetKind();
11208
+ if (valueKind != ETypeAnnotationKind::Pg) {
11209
+ valueBaseType = RemoveAllOptionals(valueType);
11210
+ }
11211
+ if (valueKind != ETypeAnnotationKind::Data &&
11212
+ valueKind != ETypeAnnotationKind::Null &&
11213
+ valueKind != ETypeAnnotationKind::Pg)
11203
11214
{
11204
11215
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Child(1)->Pos()),
11205
11216
TStringBuilder() << "Expecting (optional) Data as second argument, but got: " << *valueType));
@@ -11218,14 +11229,29 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11218
11229
auto optKeyType = ctx.Expr.MakeType<TOptionalExprType>(keyType);
11219
11230
if (!IsValidTypeForRanges(optKeyType)) {
11220
11231
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Head().Pos()),
11221
- TStringBuilder() << "Expected (optional) of comparable and equatable Data type, but got: " << *keyType));
11232
+ TStringBuilder() << "Expected (optional) of comparable and equatable Data or Pg type, but got: " << *keyType));
11222
11233
return IGraphTransformer::TStatus::Error;
11223
11234
}
11224
11235
11225
- if (valueBaseType && CanCompare<false>(RemoveAllOptionals(keyType), valueBaseType) == ECompareOptions::Uncomparable) {
11226
- ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()),
11227
- TStringBuilder() << "Uncompatible key and value types: " << *keyType << " and " << *valueType));
11228
- return IGraphTransformer::TStatus::Error;
11236
+ if (valueBaseType) {
11237
+ if (keyType->GetKind() == ETypeAnnotationKind::Pg) {
11238
+ if (!IsSameAnnotation(*keyType, *valueBaseType)) {
11239
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()),
11240
+ TStringBuilder() << "Unequal key/value types are not supported: " << *keyType << " and " << *valueType));
11241
+ return IGraphTransformer::TStatus::Error;
11242
+ }
11243
+ if (op == "StartsWith" || op == "NotStartsWith") {
11244
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()),
11245
+ TStringBuilder() << "Operation " << op << "is unsupported for pg type " << *keyType));
11246
+ return IGraphTransformer::TStatus::Error;
11247
+
11248
+ }
11249
+ }
11250
+ if (CanCompare<false>(RemoveAllOptionals(keyType), valueBaseType) == ECompareOptions::Uncomparable) {
11251
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()),
11252
+ TStringBuilder() << "Uncompatible key and value types: " << *keyType << " and " << *valueType));
11253
+ return IGraphTransformer::TStatus::Error;
11254
+ }
11229
11255
}
11230
11256
11231
11257
auto int32Type = ctx.Expr.MakeType<TDataExprType>(EDataSlot::Int32);
@@ -11412,7 +11438,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11412
11438
auto optKeyType = ctx.Expr.MakeType<TOptionalExprType>(keyType);
11413
11439
if (!IsValidTypeForRanges(optKeyType)) {
11414
11440
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(keyNode->Pos()),
11415
- TStringBuilder() << "Unsupported index column type: expecting Data or (multi) optional of Data, "
11441
+ TStringBuilder() << "Unsupported index column type: expecting Data or (multi) optional of Data (or Pg) , "
11416
11442
<< "got: " << *keyType << " for column '" << key << "'"));
11417
11443
return IGraphTransformer::TStatus::Error;
11418
11444
}
@@ -11438,7 +11464,7 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11438
11464
return IGraphTransformer::TStatus::Error;
11439
11465
}
11440
11466
11441
- if (!EnsureDataType (input->Head(), ctx.Expr)) {
11467
+ if (!EnsureDataOrPgType (input->Head(), ctx.Expr)) {
11442
11468
return IGraphTransformer::TStatus::Error;
11443
11469
}
11444
11470
@@ -11447,12 +11473,12 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11447
11473
}
11448
11474
11449
11475
auto dstType = input->Tail().GetTypeAnn()->Cast<TTypeExprType>()->GetType();
11450
- if (!EnsureDataType (input->Tail().Pos(), *dstType, ctx.Expr)) {
11476
+ if (!EnsureDataOrPgType (input->Tail().Pos(), *dstType, ctx.Expr)) {
11451
11477
return IGraphTransformer::TStatus::Error;
11452
11478
}
11453
11479
11454
11480
auto srcType = input->Head().GetTypeAnn();
11455
- if (CanCompare<false>(srcType, dstType) != ECompareOptions::Comparable ) {
11481
+ if (CanCompare<false>(srcType, dstType) == ECompareOptions::Uncomparable ) {
11456
11482
ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()),
11457
11483
TStringBuilder() << "Uncompatible types in rounding: " << *srcType << " " << input->Content() << " to " << *dstType));
11458
11484
return IGraphTransformer::TStatus::Error;
@@ -11463,6 +11489,12 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
11463
11489
return IGraphTransformer::TStatus::Repeat;
11464
11490
}
11465
11491
11492
+ if (dstType->GetKind() == ETypeAnnotationKind::Pg) {
11493
+ ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()),
11494
+ TStringBuilder() << "Pg types in rounding are not supported: " << *srcType << " " << input->Content() << " to " << *dstType));
11495
+ return IGraphTransformer::TStatus::Error;
11496
+ }
11497
+
11466
11498
auto sSlot = srcType->Cast<TDataExprType>()->GetSlot();
11467
11499
auto tSlot = dstType->Cast<TDataExprType>()->GetSlot();
11468
11500
auto resultType = ctx.Expr.MakeType<TOptionalExprType>(dstType);
0 commit comments