Skip to content

Commit 190b207

Browse files
committed
compare sorted results
1 parent e6766bc commit 190b207

File tree

10 files changed

+76
-55
lines changed

10 files changed

+76
-55
lines changed

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-select.test_/query_10.plan

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"PlanNodeId": 4,
2525
"Plans": [
2626
{
27-
"Node Type": "Merge",
27+
"Node Type": "UnionAll",
2828
"PlanNodeId": 3,
2929
"PlanNodeType": "Connection",
3030
"Plans": [
@@ -70,9 +70,6 @@
7070
}
7171
]
7272
}
73-
],
74-
"SortColumns": [
75-
"unique1 (Asc)"
7673
]
7774
}
7875
]

ydb/tests/functional/suite_tests/canondata/test_postgres.TestPGSQL.test_sql_suite_plan-select.test_/query_12.plan

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
"PlanNodeId": 4,
2525
"Plans": [
2626
{
27-
"Node Type": "Merge",
27+
"Node Type": "UnionAll",
2828
"PlanNodeId": 3,
2929
"PlanNodeType": "Connection",
3030
"Plans": [
3131
{
32-
"Node Type": "TopSort-InnerJoin (MapJoin)-Filter",
32+
"Node Type": "Limit-InnerJoin (MapJoin)-Filter",
3333
"Operators": [
3434
{
3535
"Inputs": [
@@ -38,8 +38,7 @@
3838
}
3939
],
4040
"Limit": "1001",
41-
"Name": "TopSort",
42-
"TopSortBy": "argument.onek.unique1"
41+
"Name": "Limit"
4342
},
4443
{
4544
"Condition": "onek.stringu1,onek.unique1 = v.j,v.i",
@@ -103,9 +102,6 @@
103102
}
104103
]
105104
}
106-
],
107-
"SortColumns": [
108-
"onek.unique1 (Asc)"
109105
]
110106
}
111107
]

ydb/tests/functional/suite_tests/postgres/case.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,17 @@ SELECT CASE 1 WHEN 0 THEN 1/0 WHEN 1 THEN 1 ELSE 2/0 END;
122122
-- reachable subexpressions
123123
-- but in yql it works fine
124124

125-
statement skipped_cs query
125+
statement query
126126
SELECT CASE WHEN i > 100 THEN 1/0 ELSE 0 END FROM CASE_TBL;
127127

128-
statement skipped_cs query
128+
statement query
129129
SELECT 2 as ft, CASE WHEN i > 0 THEN 1/0 ELSE 0 END FROM CASE_TBL;
130130

131131

132132
statement query
133133
SELECT CASE 'a' WHEN 'a' THEN 1 ELSE 2 END;
134134

135-
statement skipped_cs query
135+
statement query
136136
SELECT 1 AS `Five`,
137137
CASE
138138
WHEN i >= 3 THEN i
@@ -148,7 +148,7 @@ SELECT 1 AS `Five`,
148148
FROM CASE_TBL
149149
ORDER By Simplest_Math
150150

151-
statement skipped_cs query
151+
statement query
152152
SELECT 1 AS `Five`, i AS `Value`,
153153
CASE WHEN (i < 0) THEN 'small'
154154
WHEN (i = 0) THEN 'zero'
@@ -158,7 +158,7 @@ SELECT 1 AS `Five`, i AS `Value`,
158158
END AS `Category`
159159
FROM CASE_TBL;
160160

161-
statement skipped_cs query
161+
statement query
162162
SELECT 1 AS `Five`,
163163
CASE WHEN ((i < 0) or (i < 0)) THEN 'small'
164164
WHEN ((i = 0) or (i = 0)) THEN 'zero'

ydb/tests/functional/suite_tests/postgres/jointest/join1.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ SELECT J1_TBL.i as i, j, t, k
184184
FROM J1_TBL JOIN J2_TBL ON (J1_TBL.i = J2_TBL.k)
185185
ORDER BY i;
186186

187-
statement error
187+
statement error JOIN ON expression must be a conjunction of equality predicates
188188
SELECT J1_TBL.i as i1, J2_TBL.i as i2, j, t, k
189189
FROM J1_TBL JOIN J2_TBL ON (J1_TBL.i <= J2_TBL.k);
190190
-----------------------

ydb/tests/functional/suite_tests/postgres/jointest/join2.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ INSERT INTO t2 (name, n) VALUES ( 'ee', 42 );
2727
statement ok
2828
INSERT INTO t3 (name, n) VALUES ( 'bb', 13 );
2929

30-
statement skipped_cs ok
30+
statement ok
3131
INSERT INTO t3 (name, n) VALUES ( 'cc', 23 );
3232

3333
statement ok
@@ -46,15 +46,15 @@ order by name
4646
--
4747
-- Basic cases (we expect planner to pull up the subquery here)
4848

49-
statement skipped_cs query
49+
statement query
5050
SELECT s2.name as name, s2.n as n2, s3.n as n3 FROM
5151
(SELECT * FROM t2) as s2
5252
INNER JOIN
5353
(SELECT * FROM t3) as s3
5454
USING (name)
5555
order by name
5656

57-
statement skipped_cs query
57+
statement query
5858
SELECT s2.name as name, s2.n as n2, s3.n as n3 FROM
5959
(SELECT * FROM t2) as s2
6060
LEFT JOIN

ydb/tests/functional/suite_tests/postgres/jointest/join4.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ INSERT INTO qrt3 (x, y) VALUES (500, 100);
296296
statement ok
297297
DELETE FROM qrt3 WHERE qrt3.x = 5;
298298

299-
statement skipped_cs query
299+
statement query
300300
SELECT * FROM qrt3;
301301

302302
statement ok
303303
DELETE FROM qrt3 WHERE qrt3.x = 500;
304304

305-
statement skipped_cs query
305+
statement query
306306
SELECT * FROM qrt3;
307307

308308
statement ok

ydb/tests/functional/suite_tests/postgres/select.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ SELECT onek2.unique1, onek2.stringu1 FROM onek2
114114

115115
statement query
116116
SELECT onek2.unique1, onek2.stringu1 FROM onek2
117-
WHERE onek2.unique1 > 980
118-
ORDER BY onek2.unique1;
117+
WHERE onek2.unique1 > 980;
119118

120119
statement ok
121120
CREATE TABLE tmp (
@@ -146,8 +145,7 @@ unique1, unique2, two, four, ten, twenty,
146145
hundred, thousand, twothousand, fivethous,
147146
tenthous, odd, even, stringu1, stringu2, string4, i, j
148147
from onek cross join (select 147 as i, 'RFAAAA' as j union all select 931 as i, 'VJAAAA' as j) as v
149-
WHERE onek.unique1 = v.i and onek.stringu1 = v.j
150-
ORDER BY unique1;
148+
WHERE onek.unique1 = v.i and onek.stringu1 = v.j;
151149

152150
-- a more complex case
153151
-- looks like we're coding lisp :-)

ydb/tests/functional/suite_tests/postgres/strings.test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -859,74 +859,74 @@ SELECT 'i_dio' NOT LIKE 'i$_d%o' ESCAPE '$' AS `false`;
859859

860860
-- escape character same as pattern character
861861

862-
statement skipped query
862+
statement skipped unsupported symbol
863863
SELECT 'maca' LIKE 'm%aca' ESCAPE '%' AS "true";
864864
------
865865
true
866866
------
867867
True
868868

869-
statement skipped query
869+
statement skipped unsupported symbol
870870
SELECT 'maca' NOT LIKE 'm%aca' ESCAPE '%' AS "false";
871871
-------
872872
false
873873
-------
874874
False
875875

876-
statement skipped query
876+
statement skipped unsupported symbol
877877
SELECT 'ma%a' LIKE 'm%a%%a' ESCAPE '%' AS "true";
878878
------
879879
true
880880
------
881881
True
882882

883883

884-
statement skipped query
884+
statement skipped unsupported symbol
885885
SELECT 'ma%a' NOT LIKE 'm%a%%a' ESCAPE '%' AS "false";
886886
-------
887887
false
888888
-------
889889
False
890890

891891

892-
statement skipped query
892+
statement skipped unsupported symbol
893893
SELECT 'bear' LIKE 'b_ear' ESCAPE '_' AS `true`;
894894
------
895895
true
896896
------
897897
True
898898

899-
statement skipped query
899+
statement skipped unsupported symbol
900900
SELECT 'bear' NOT LIKE 'b_ear' ESCAPE '_' AS `false`;
901901
-------
902902
false
903903
-------
904904
False
905905

906906

907-
statement skipped query
907+
statement skipped unsupported symbol
908908
SELECT 'be_r' LIKE 'b_e__r' ESCAPE '_' AS `true`;
909909
------
910910
true
911911
------
912912
True
913913

914-
statement skipped query
914+
statement skipped unsupported symbol
915915
SELECT 'be_r' NOT LIKE 'b_e__r' ESCAPE '_' AS `false`;
916916
-------
917917
false
918918
-------
919919
False
920920

921921

922-
statement skipped query
922+
statement skipped unsupported symbol
923923
SELECT 'be_r' LIKE '__e__r' ESCAPE '_' AS `false`;
924924
-------
925925
false
926926
-------
927927
False
928928

929-
statement skipped query
929+
statement skipped unsupported symbol
930930
SELECT 'be_r' NOT LIKE '__e__r' ESCAPE '_' AS `true`;
931931
------
932932
true

ydb/tests/functional/suite_tests/sqllogictest/select2-1.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ from t1
806806
where a is null
807807
order by col3,col2,col1,col4,col6,col5
808808

809-
statement skipped_cs query
809+
statement query
810810
select d as col1,
811811
c-d as col2,
812812
e as col3
@@ -1237,7 +1237,7 @@ where b is not null
12371237
and e+d between a+b-10 and c+130
12381238
order by col1
12391239

1240-
statement skipped_cs query
1240+
statement query
12411241
select a+b*2+c*3+d*4+e*5 as col1,
12421242
a+b*2 as col2,
12431243
d as col3,
@@ -1704,7 +1704,7 @@ where d not between 110 and 150
17041704
or a>b
17051705
order by col2,col1,col3
17061706

1707-
statement skipped_cs query
1707+
statement query
17081708
select b as col1,
17091709
d as col2,
17101710
a as col3,

ydb/tests/functional/suite_tests/test_base.py

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# import time
1010
import six
1111
import enum
12+
from functools import cmp_to_key
1213
from concurrent import futures
1314

1415
from hamcrest import assert_that, equal_to, raises
@@ -85,18 +86,21 @@ def __str__(self):
8586
def _parse_statement_type(statement_line: str) -> (Type, {TableType}):
8687
parts = statement_line.split(' ')
8788
parts.pop(0) # skip 'statement' word
88-
if parts[0] == 'skipped':
89-
table_types = {}
90-
parts.pop(0)
91-
elif parts[0] == 'skipped_cs':
92-
table_types = {StatementDefinition.TableType.Row}
93-
parts.pop(0)
89+
table_types = {}
90+
if parts[0] == 'error':
91+
type = StatementDefinition.Type.Error
9492
else:
95-
table_types = {StatementDefinition.TableType.Row, StatementDefinition.TableType.Column}
96-
type = None
97-
for t in list(StatementDefinition.Type):
98-
if t.value == ' '.join(parts):
99-
type = t
93+
if parts[0] == 'skipped':
94+
parts.pop(0)
95+
elif parts[0] == 'skipped_cs':
96+
table_types = {StatementDefinition.TableType.Row}
97+
parts.pop(0)
98+
else:
99+
table_types = {StatementDefinition.TableType.Row, StatementDefinition.TableType.Column}
100+
type = None
101+
for t in list(StatementDefinition.Type):
102+
if t.value == ' '.join(parts):
103+
type = t
100104
return (type, table_types)
101105

102106
@staticmethod
@@ -112,7 +116,6 @@ def _parse_sql_statement_type(lines: [str]) -> SqlStatementType:
112116

113117
@staticmethod
114118
def parse(suite: str, at_line: int, lines: list[str]):
115-
print(f'QQQ: {at_line} {lines}')
116119
if not lines or not lines[0]:
117120
raise RuntimeError(f'Invalid statement in {suite}, at line: {at_line}')
118121
type, table_types = StatementDefinition._parse_statement_type(lines[0])
@@ -180,7 +183,7 @@ def split_by_statement(lines):
180183
yield (statement_start_line_idx, statement_lines)
181184
statement_lines = []
182185
if statement_lines:
183-
yield (statement_start_line_idx, statement_lines)
186+
yield (statement_start_line_idx + 1, statement_lines)
184187

185188

186189
def get_statements(suite_path, suite_name):
@@ -480,9 +483,36 @@ def execute_query(self, statement: StatementDefinition, amended_text: str = None
480483
"Scan query and query service produce different results",
481484
)
482485
if StatementDefinition.TableType.Column in statement.table_types:
486+
def flatten_result(result_sets):
487+
return [row for result_set in result_sets for row in result_set.rows]
488+
489+
def compare(lhs, rhs):
490+
lhs_keys = sorted(lhs.keys())
491+
rhs_keys = sorted(rhs.keys())
492+
if lhs_keys != rhs_keys:
493+
return -1 if lhs_keys < rhs_keys else 1
494+
495+
def cmp_val_none(lhs, rhs):
496+
if lhs is None or rhs is None:
497+
if lhs == rhs:
498+
return 0
499+
return -1 if lhs is None else 1
500+
if lhs == rhs:
501+
return 0
502+
return -1 if lhs < rhs else 1
503+
504+
for k in lhs_keys:
505+
c = cmp_val_none(lhs[k], rhs[k])
506+
if c != 0:
507+
return c
508+
return 0
509+
510+
sorted_result_row = sorted(flatten_result(result_row), key=cmp_to_key(compare))
511+
sorted_result_column = sorted(flatten_result(result_column), key=cmp_to_key(compare))
512+
483513
self.execute_assert(
484-
result_row[0].rows,
485-
result_column[0].rows,
486-
"Row table and column table produce different results",
514+
sorted_result_row,
515+
sorted_result_column,
516+
f"Row table and column table produce different results: \n{sorted_result_row} \n{sorted_result_column}",
487517
)
488518
return result_row

0 commit comments

Comments
 (0)