Skip to content

Commit 63494d4

Browse files
authored
Merge 27940c3 into 1dd1ce1
2 parents 1dd1ce1 + 27940c3 commit 63494d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+6476
-1278
lines changed

ydb/library/yql/providers/common/provider/yql_provider.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ bool NeedToRenamePgSelectColumns(const TCoPgSelect& pgSelect) {
14751475
bool RenamePgSelectColumns(
14761476
const TCoPgSelect& node,
14771477
TExprNode::TPtr& output,
1478-
TMaybe<TVector<TString>> tableColumnOrder,
1478+
const TMaybe<TColumnOrder>& tableColumnOrder,
14791479
TExprContext& ctx,
14801480
TTypeAnnotationContext& types) {
14811481

@@ -1485,7 +1485,7 @@ bool RenamePgSelectColumns(
14851485
TString optionName = (hasValues) ? "values" : "projection_order";
14861486

14871487
auto selectorColumnOrder = types.LookupColumnOrder(node.Ref());
1488-
TVector<TString> insertColumnOrder;
1488+
TColumnOrder insertColumnOrder;
14891489
if (auto targetColumnsOption = GetSetItemOption(node, "target_columns")) {
14901490
auto targetColumns = GetSetItemOptionValue(TExprBase(targetColumnsOption));
14911491
for (const auto& child : targetColumns->ChildrenList()) {

ydb/library/yql/providers/common/provider/yql_provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bool NeedToRenamePgSelectColumns(const NNodes::TCoPgSelect& pgSelect);
209209
bool RenamePgSelectColumns(
210210
const NNodes::TCoPgSelect& node,
211211
TExprNode::TPtr& output,
212-
TMaybe<TVector<TString>> tableColumnOrder,
212+
const TMaybe<TColumnOrder>& tableColumnOrder,
213213
TExprContext& ctx,
214214
TTypeAnnotationContext& types);
215215
} // namespace NCommon

ydb/library/yql/providers/yt/provider/yql_yt_datasink_type_ann.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ class TYtDataSinkTypeAnnotationTransformer : public TVisitorTransformerBase {
459459
auto pgSelect = TCoPgSelect(content);
460460
if (NCommon::NeedToRenamePgSelectColumns(pgSelect)) {
461461
TExprNode::TPtr output;
462-
bool result = NCommon::RenamePgSelectColumns(pgSelect, output, contentColumnOrder, ctx, *State_->Types);
462+
463+
const auto& columnOrder = (outTableInfo.RowSpec)
464+
? outTableInfo.RowSpec->GetColumnOrder()
465+
: contentColumnOrder;
466+
467+
bool result = NCommon::RenamePgSelectColumns(pgSelect, output, columnOrder, ctx, *State_->Types);
463468
if (!result) {
464469
return TStatus::Error;
465470
}

ydb/library/yql/tests/postgresql/cases/aggregates.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ SELECT covar_pop(1::float8,'nan'::float8), covar_samp(3::float8,'nan'::float8);
270270
-- test accum and combine functions directly
271271
CREATE TABLE regr_test (x float8, y float8);
272272
INSERT INTO regr_test VALUES (10,150),(20,250),(30,350),(80,540),(100,200);
273+
SELECT count(*), sum(x), regr_sxx(y,x), sum(y),regr_syy(y,x), regr_sxy(y,x)
274+
FROM regr_test;
275+
count | sum | regr_sxx | sum | regr_syy | regr_sxy
276+
-------+-----+----------+------+----------+----------
277+
5 | 240 | 6280 | 1490 | 95080 | 8680
278+
(1 row)
279+
273280
SELECT float8_accum('{4,140,2900}'::float8[], 100);
274281
float8_accum
275282
--------------

ydb/library/yql/tests/postgresql/cases/aggregates.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ SELECT covar_pop(1::float8,'nan'::float8), covar_samp(3::float8,'nan'::float8);
6565
-- test accum and combine functions directly
6666
CREATE TABLE regr_test (x float8, y float8);
6767
INSERT INTO regr_test VALUES (10,150),(20,250),(30,350),(80,540),(100,200);
68+
SELECT count(*), sum(x), regr_sxx(y,x), sum(y),regr_syy(y,x), regr_sxy(y,x)
69+
FROM regr_test;
6870
SELECT float8_accum('{4,140,2900}'::float8[], 100);
6971
SELECT float8_regr_accum('{4,140,2900,1290,83075,15050}'::float8[], 200, 100);
7072
SELECT float8_combine('{3,60,200}'::float8[], '{0,0,0}'::float8[]);

ydb/library/yql/tests/postgresql/cases/arrays.err

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,27 @@ CREATE TEMP TABLE arrtest_s (
431431
<sql-statement>
432432
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
433433
</sql-statement>
434+
-stdin-:<main>: Fatal: Execution
435+
436+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
437+
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
438+
^
439+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type smallint: "{1,2,3,4,5}"
440+
441+
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
442+
^
434443
<sql-statement>
435444
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
436445
</sql-statement>
446+
-stdin-:<main>: Fatal: Execution
447+
448+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
449+
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
450+
^
451+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type smallint: "[0:4]={1,2,3,4,5}"
452+
453+
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
454+
^
437455
<sql-statement>
438456
SELECT * FROM arrtest_s;
439457
</sql-statement>
@@ -589,6 +607,20 @@ CREATE TEMP TABLE arrtest1 (i int[], t text[]);
589607
<sql-statement>
590608
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
591609
</sql-statement>
610+
-stdin-:<main>: Error: Type annotation
611+
612+
-stdin-:<main>:1:1: Error: At function: YtWriteTable!
613+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
614+
^
615+
-stdin-:<main>:1:1: Error: Failed to convert type: List<Struct<'i':_pgint4,'t':_pgtext>> to List<Struct<'i':pgint4,'t':pgtext>>
616+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
617+
^
618+
-stdin-:<main>:1:1: Error: Failed to convert 'i': _pgint4 to pgint4
619+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
620+
^
621+
-stdin-:<main>:1:1: Error: Table "arrtest1" row type differs from the written row type: Struct<i:pgint4!=_pgint4,t:pgtext!=_pgtext>
622+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
623+
^
592624
<sql-statement>
593625
select * from arrtest1;
594626
</sql-statement>
@@ -722,6 +754,20 @@ delete from arrtest1;
722754
<sql-statement>
723755
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
724756
</sql-statement>
757+
-stdin-:<main>: Error: Type annotation
758+
759+
-stdin-:<main>:1:1: Error: At function: YtWriteTable!
760+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
761+
^
762+
-stdin-:<main>:1:1: Error: Failed to convert type: List<Struct<'i':_pgint4,'t':_pgtext>> to List<Struct<'i':pgint4,'t':pgtext>>
763+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
764+
^
765+
-stdin-:<main>:1:1: Error: Failed to convert 'i': _pgint4 to pgint4
766+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
767+
^
768+
-stdin-:<main>:1:1: Error: Table "arrtest1" row type differs from the written row type: Struct<i:pgint4!=_pgint4,t:pgtext!=_pgtext>
769+
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
770+
^
725771
<sql-statement>
726772
select * from arrtest1;
727773
</sql-statement>
@@ -751,6 +797,20 @@ INSERT INTO arrtest2 VALUES(
751797
ARRAY['19620326','19931223','19970117']::timestamp[]
752798
);
753799
</sql-statement>
800+
-stdin-:<main>: Error: Type annotation
801+
802+
-stdin-:<main>:1:1: Error: At function: YtWriteTable!
803+
INSERT INTO arrtest2 VALUES(
804+
^
805+
-stdin-:<main>:1:1: Error: Failed to convert type: List<Struct<'d':_pgtimestamp,'f':_pgfloat8,'i':_pgint4,'n':_pgnumeric,'t':_pgtext>> to List<Struct<'d':pgtimestamp,'f':pgfloat8,'i':pgint4,'n':pgnumeric,'t':pgtext>>
806+
INSERT INTO arrtest2 VALUES(
807+
^
808+
-stdin-:<main>:1:1: Error: Failed to convert 'd': _pgtimestamp to pgtimestamp
809+
INSERT INTO arrtest2 VALUES(
810+
^
811+
-stdin-:<main>:1:1: Error: Table "arrtest2" row type differs from the written row type: Struct<d:pgtimestamp!=_pgtimestamp,f:pgfloat8!=_pgfloat8,i:pgint4!=_pgint4,n:pgnumeric!=_pgnumeric,t:pgtext!=_pgtext>
812+
INSERT INTO arrtest2 VALUES(
813+
^
754814
<sql-statement>
755815
-- some more test data
756816
CREATE TEMP TABLE arrtest_f (f0 int, f1 text, f2 float8);
@@ -1715,22 +1775,76 @@ create temp table arr_tbl (f1 int[] unique);
17151775
<sql-statement>
17161776
insert into arr_tbl values ('{1,2,3}');
17171777
</sql-statement>
1778+
-stdin-:<main>: Fatal: Execution
1779+
1780+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1781+
insert into arr_tbl values ('{1,2,3}');
1782+
^
1783+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{1,2,3}"
1784+
1785+
insert into arr_tbl values ('{1,2,3}');
1786+
^
17181787
<sql-statement>
17191788
insert into arr_tbl values ('{1,2}');
17201789
</sql-statement>
1790+
-stdin-:<main>: Fatal: Execution
1791+
1792+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1793+
insert into arr_tbl values ('{1,2}');
1794+
^
1795+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{1,2}"
1796+
1797+
insert into arr_tbl values ('{1,2}');
1798+
^
17211799
<sql-statement>
17221800
-- failure expected:
17231801
insert into arr_tbl values ('{1,2,3}');
17241802
</sql-statement>
1803+
-stdin-:<main>: Fatal: Execution
1804+
1805+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1806+
-- failure expected:
1807+
^
1808+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{1,2,3}"
1809+
1810+
-- failure expected:
1811+
^
17251812
<sql-statement>
17261813
insert into arr_tbl values ('{2,3,4}');
17271814
</sql-statement>
1815+
-stdin-:<main>: Fatal: Execution
1816+
1817+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1818+
insert into arr_tbl values ('{2,3,4}');
1819+
^
1820+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{2,3,4}"
1821+
1822+
insert into arr_tbl values ('{2,3,4}');
1823+
^
17281824
<sql-statement>
17291825
insert into arr_tbl values ('{1,5,3}');
17301826
</sql-statement>
1827+
-stdin-:<main>: Fatal: Execution
1828+
1829+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1830+
insert into arr_tbl values ('{1,5,3}');
1831+
^
1832+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{1,5,3}"
1833+
1834+
insert into arr_tbl values ('{1,5,3}');
1835+
^
17311836
<sql-statement>
17321837
insert into arr_tbl values ('{1,2,10}');
17331838
</sql-statement>
1839+
-stdin-:<main>: Fatal: Execution
1840+
1841+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1842+
insert into arr_tbl values ('{1,2,10}');
1843+
^
1844+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{1,2,10}"
1845+
1846+
insert into arr_tbl values ('{1,2,10}');
1847+
^
17341848
<sql-statement>
17351849
set enable_seqscan to off;
17361850
</sql-statement>
@@ -1760,6 +1874,15 @@ create temp table arr_pk_tbl (pk int4 primary key, f1 int[]);
17601874
<sql-statement>
17611875
insert into arr_pk_tbl values (1, '{1,2,3}');
17621876
</sql-statement>
1877+
-stdin-:<main>: Fatal: Execution
1878+
1879+
-stdin-:<main>:1:1: Fatal: Execution of node: YtFill!
1880+
insert into arr_pk_tbl values (1, '{1,2,3}');
1881+
^
1882+
-stdin-:<main>:1:1: Fatal: ERROR: invalid input syntax for type integer: "{1,2,3}"
1883+
1884+
insert into arr_pk_tbl values (1, '{1,2,3}');
1885+
^
17631886
<sql-statement>
17641887
insert into arr_pk_tbl values (1, '{3,4,5}') on conflict (pk)
17651888
do update set f1[1] = excluded.f1[1], f1[3] = excluded.f1[3]

ydb/library/yql/tests/postgresql/cases/arrays.out

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,16 @@ CREATE TEMP TABLE arrtest_s (
2828
a int2[],
2929
b int2[][]
3030
);
31-
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
32-
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
3331
INSERT INTO arrtest_s VALUES(NULL, NULL);
3432
--
3533
-- test array extension
3634
--
3735
CREATE TEMP TABLE arrtest1 (i int[], t text[]);
38-
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
39-
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
4036
--
4137
-- array expressions and operators
4238
--
4339
-- table creation and INSERTs
4440
CREATE TEMP TABLE arrtest2 (i integer ARRAY[4], f float8[], n numeric[], t text[], d timestamp[]);
45-
INSERT INTO arrtest2 VALUES(
46-
ARRAY[[[113,142],[1,147]]],
47-
ARRAY[1.1,1.2,1.3]::float8[],
48-
ARRAY[1.1,1.2,1.3],
49-
ARRAY[[['aaa','aab'],['aba','abb'],['aca','acb']],[['baa','bab'],['bba','bbb'],['bca','bcb']]],
50-
ARRAY['19620326','19931223','19970117']::timestamp[]
51-
);
5241
-- some more test data
5342
CREATE TEMP TABLE arrtest_f (f0 int, f1 text, f2 float8);
5443
insert into arrtest_f values(1,'cat1',1.21);
@@ -128,14 +117,8 @@ SELECT NULL::text[]::int[] AS "NULL";
128117

129118
-- test indexes on arrays
130119
create temp table arr_tbl (f1 int[] unique);
131-
insert into arr_tbl values ('{1,2,3}');
132-
insert into arr_tbl values ('{1,2}');
133-
insert into arr_tbl values ('{2,3,4}');
134-
insert into arr_tbl values ('{1,5,3}');
135-
insert into arr_tbl values ('{1,2,10}');
136120
-- test ON CONFLICT DO UPDATE with arrays
137121
create temp table arr_pk_tbl (pk int4 primary key, f1 int[]);
138-
insert into arr_pk_tbl values (1, '{1,2,3}');
139122
--
140123
-- General array parser tests
141124
--

ydb/library/yql/tests/postgresql/cases/arrays.sql

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,16 @@ CREATE TEMP TABLE arrtest_s (
1818
a int2[],
1919
b int2[][]
2020
);
21-
INSERT INTO arrtest_s VALUES ('{1,2,3,4,5}', '{{1,2,3}, {4,5,6}, {7,8,9}}');
22-
INSERT INTO arrtest_s VALUES ('[0:4]={1,2,3,4,5}', '[0:2][0:2]={{1,2,3}, {4,5,6}, {7,8,9}}');
2321
INSERT INTO arrtest_s VALUES(NULL, NULL);
2422
--
2523
-- test array extension
2624
--
2725
CREATE TEMP TABLE arrtest1 (i int[], t text[]);
28-
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
29-
insert into arrtest1 values(array[1,2,null,4], array['one','two',null,'four']);
3026
--
3127
-- array expressions and operators
3228
--
3329
-- table creation and INSERTs
3430
CREATE TEMP TABLE arrtest2 (i integer ARRAY[4], f float8[], n numeric[], t text[], d timestamp[]);
35-
INSERT INTO arrtest2 VALUES(
36-
ARRAY[[[113,142],[1,147]]],
37-
ARRAY[1.1,1.2,1.3]::float8[],
38-
ARRAY[1.1,1.2,1.3],
39-
ARRAY[[['aaa','aab'],['aba','abb'],['aca','acb']],[['baa','bab'],['bba','bbb'],['bca','bcb']]],
40-
ARRAY['19620326','19931223','19970117']::timestamp[]
41-
);
4231
-- some more test data
4332
CREATE TEMP TABLE arrtest_f (f0 int, f1 text, f2 float8);
4433
insert into arrtest_f values(1,'cat1',1.21);
@@ -73,14 +62,8 @@ SELECT CAST(ARRAY[[[[[['a','bb','ccc']]]]]] as text[]) as "{{{{{{a,bb,ccc}}}}}}"
7362
SELECT NULL::text[]::int[] AS "NULL";
7463
-- test indexes on arrays
7564
create temp table arr_tbl (f1 int[] unique);
76-
insert into arr_tbl values ('{1,2,3}');
77-
insert into arr_tbl values ('{1,2}');
78-
insert into arr_tbl values ('{2,3,4}');
79-
insert into arr_tbl values ('{1,5,3}');
80-
insert into arr_tbl values ('{1,2,10}');
8165
-- test ON CONFLICT DO UPDATE with arrays
8266
create temp table arr_pk_tbl (pk int4 primary key, f1 int[]);
83-
insert into arr_pk_tbl values (1, '{1,2,3}');
8467
--
8568
-- General array parser tests
8669
--

0 commit comments

Comments
 (0)