Skip to content

Commit f207c70

Browse files
authored
Merge b92903a into 91d6e34
2 parents 91d6e34 + b92903a commit f207c70

File tree

8 files changed

+35
-8
lines changed

8 files changed

+35
-8
lines changed

ydb/docs/en/core/postgresql/_includes/functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,13 +3869,13 @@ Table 9.57. General-Purpose Aggregate Functions
38693869
Collects all the input values, including nulls, into an array. (NOT SUPPORTED)|
38703870
No|
38713871
```sql
3872-
#SELECT array_agg(x) FROM (VALUES (1),(2)) a(x) → {1,2}
3872+
SELECT array_agg(x) FROM (VALUES (1),(2)) a(x) → {1,2}
38733873
```||
38743874
||array_agg ( anyarray ) → anyarray|
38753875
Concatenates all the input arrays into an array of one higher dimension. (The inputs must all have the same dimensionality, and cannot be empty or null.) (NOT SUPPORTED)|
38763876
No|
38773877
```sql
3878-
#SELECT array_agg(x) FROM (VALUES (Array[1,2]),(Array[3,4])) a(x) → {{1,2},{3,4}}
3878+
SELECT array_agg(x) FROM (VALUES (Array[1,2]),(Array[3,4])) a(x) → {{1,2},{3,4}}
38793879
```||
38803880
||avg ( smallint ) → numeric
38813881
avg ( integer ) → numeric

ydb/docs/ru/core/postgresql/_includes/functions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3869,13 +3869,13 @@ Table 9.57. General-Purpose Aggregate Functions
38693869
Collects all the input values, including nulls, into an array. (NOT SUPPORTED)|
38703870
No|
38713871
```sql
3872-
#SELECT array_agg(x) FROM (VALUES (1),(2)) a(x) → {1,2}
3872+
SELECT array_agg(x) FROM (VALUES (1),(2)) a(x) → {1,2}
38733873
```||
38743874
||array_agg ( anyarray ) → anyarray|
38753875
Concatenates all the input arrays into an array of one higher dimension. (The inputs must all have the same dimensionality, and cannot be empty or null.) (NOT SUPPORTED)|
38763876
No|
38773877
```sql
3878-
#SELECT array_agg(x) FROM (VALUES (Array[1,2]),(Array[3,4])) a(x) → {{1,2},{3,4}}
3878+
SELECT array_agg(x) FROM (VALUES (Array[1,2]),(Array[3,4])) a(x) → {{1,2},{3,4}}
38793879
```||
38803880
||avg ( smallint ) → numeric
38813881
avg ( integer ) → numeric

ydb/library/yql/core/type_ann/type_ann_pg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ bool IsCastRequired(ui32 fromTypeId, ui32 toTypeId) {
2222
if (toTypeId == fromTypeId) {
2323
return false;
2424
}
25-
if (toTypeId == NPg::AnyOid || toTypeId == NPg::AnyArrayOid) {
25+
if (toTypeId == NPg::AnyOid || toTypeId == NPg::AnyArrayOid || toTypeId == NPg::AnyNonArrayOid) {
2626
return false;
2727
}
2828
return true;

ydb/library/yql/core/yql_expr_type_annotation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6331,6 +6331,7 @@ TExprNode::TPtr ExpandPgAggregationTraits(TPositionHandle pos, const NPg::TAggre
63316331
auto saveLambda = idLambda;
63326332
auto loadLambda = idLambda;
63336333
auto finishLambda = idLambda;
6334+
auto nullValue = ctx.NewCallable(pos, "Null", {});
63346335
if (aggDesc.FinalFuncId) {
63356336
finishLambda = ctx.Builder(pos)
63366337
.Lambda()
@@ -6341,12 +6342,18 @@ TExprNode::TPtr ExpandPgAggregationTraits(TPositionHandle pos, const NPg::TAggre
63416342
.List(2)
63426343
.Seal()
63436344
.Arg(3, "state")
6345+
.Do([&aggDesc, nullValue](TExprNodeBuilder& builder) -> TExprNodeBuilder& {
6346+
if (aggDesc.FinalExtra) {
6347+
builder.Add(4, nullValue);
6348+
}
6349+
6350+
return builder;
6351+
})
63446352
.Seal()
63456353
.Seal()
63466354
.Build();
63476355
}
63486356

6349-
auto nullValue = ctx.NewCallable(pos, "Null", {});
63506357
auto initValue = nullValue;
63516358
if (aggDesc.InitValue) {
63526359
initValue = ctx.Builder(pos)

ydb/library/yql/parser/pg_catalog/catalog.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ bool IsCompatibleTo(ui32 actualTypeId, ui32 expectedTypeId, const TTypes& types)
7373
return actualDescPtr->ArrayTypeId == actualDescPtr->TypeId;
7474
}
7575

76+
if (expectedTypeId == AnyNonArrayOid) {
77+
const auto& actualDescPtr = types.FindPtr(actualTypeId);
78+
Y_ENSURE(actualDescPtr);
79+
return actualDescPtr->ArrayTypeId != actualDescPtr->TypeId;
80+
}
81+
7682
return false;
7783
}
7884

@@ -753,6 +759,8 @@ class TAggregationsParser : public TParser {
753759
}
754760
} else if (key == "agginitval") {
755761
LastAggregation.InitValue = value;
762+
} else if (key == "aggfinalextra") {
763+
LastAggregation.FinalExtra = (value == "t");;
756764
}
757765
}
758766

@@ -1920,7 +1928,6 @@ bool IsCoercible(ui32 fromTypeId, ui32 toTypeId, ECoercionCode coercionType, con
19201928
if (toTypeId == AnyOid) {
19211929
return true;
19221930
}
1923-
19241931
//TODO: support polymorphic types
19251932

19261933
if (fromTypeId == UnknownOid) {
@@ -1943,6 +1950,12 @@ bool IsCoercible(ui32 fromTypeId, ui32 toTypeId, ECoercionCode coercionType, con
19431950
return actualDescPtr->ArrayTypeId == actualDescPtr->TypeId;
19441951
}
19451952

1953+
if (toTypeId == AnyNonArrayOid) {
1954+
const auto& actualDescPtr = catalog.Types.FindPtr(fromTypeId);
1955+
Y_ENSURE(actualDescPtr);
1956+
return actualDescPtr->ArrayTypeId != actualDescPtr->TypeId;
1957+
}
1958+
19461959
return false;
19471960
}
19481961

ydb/library/yql/parser/pg_catalog/catalog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace NYql::NPg {
1212
constexpr ui32 UnknownOid = 705;
1313
constexpr ui32 AnyOid = 2276;
1414
constexpr ui32 AnyArrayOid = 2277;
15+
constexpr ui32 AnyNonArrayOid = 2776;
1516
constexpr ui32 RecordOid = 2249;
1617
constexpr ui32 VarcharOid = 1043;
1718
constexpr ui32 TextOid = 25;
@@ -156,6 +157,7 @@ struct TAggregateDesc {
156157
ui32 SerializeFuncId = 0;
157158
ui32 DeserializeFuncId = 0;
158159
TString InitValue;
160+
bool FinalExtra = false;
159161
};
160162

161163
enum class EAmType {

ydb/library/yql/parser/pg_catalog/ut/catalog_consts_ut.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Y_UNIT_TEST_SUITE(TConstantsTests) {
5151
UNIT_ASSERT_VALUES_EQUAL(typeDesc.TypeId, VarcharOid);
5252
typeDesc = LookupType("text");
5353
UNIT_ASSERT_VALUES_EQUAL(typeDesc.TypeId, TextOid);
54+
typeDesc = LookupType("anynonarray");
55+
UNIT_ASSERT_VALUES_EQUAL(typeDesc.TypeId, AnyNonArrayOid);
5456
}
5557

5658
Y_UNIT_TEST(TRelationOidConsts) {

ydb/library/yql/parser/pg_wrapper/syscache.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern "C" {
1111
#include "catalog/pg_type_d.h"
1212
#include "catalog/pg_authid.h"
1313
#include "access/htup_details.h"
14+
#include "utils/fmgroids.h"
1415
}
1516

1617
#undef TypeName
@@ -183,7 +184,7 @@ struct TSysCache {
183184
std::fill_n(nulls, Natts_pg_type, true);
184185
std::fill_n(nulls, Anum_pg_type_typcollation, false); // fixed part of Form_pg_type
185186
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_oid, oid);
186-
auto name = MakeFixedString(desc.Name, NPg::LookupType(NAMEOID).TypeLen);
187+
auto name = MakeFixedString(desc.Name, NAMEDATALEN);
187188
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typname, (Datum)name);
188189
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typbyval, desc.PassByValue);
189190
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typlen, desc.TypeLen);
@@ -193,6 +194,8 @@ struct TSysCache {
193194
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typisdefined, true);
194195
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typdelim, desc.TypeDelim);
195196
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typarray, desc.ArrayTypeId);
197+
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typsubscript,
198+
(desc.ArrayTypeId == desc.TypeId) ? F_ARRAY_SUBSCRIPT_HANDLER : desc.TypeSubscriptFuncId);
196199
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typelem, desc.ElementTypeId);
197200
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typinput, desc.InFuncId);
198201
FillDatum(Natts_pg_type, values, nulls, Anum_pg_type_typoutput, desc.OutFuncId);

0 commit comments

Comments
 (0)