Skip to content

Commit fce9212

Browse files
committed
HHH-18069 - Add test
1 parent 2d0714f commit fce9212

File tree

1 file changed

+120
-22
lines changed

1 file changed

+120
-22
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/set/UnionOfPartitionResultsTest.java

Lines changed: 120 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
1212
import org.hibernate.testing.orm.junit.DomainModel;
13-
import org.hibernate.testing.orm.junit.FailureExpected;
1413
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1514
import org.hibernate.testing.orm.junit.SessionFactory;
1615
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@@ -25,37 +24,125 @@
2524
/**
2625
* @author Jan Schatteman
2726
*/
28-
@DomainModel (
29-
annotatedClasses = { UnionOfPartitionResultsTest.Apple.class, UnionOfPartitionResultsTest.Pie.class }
27+
@DomainModel(
28+
annotatedClasses = {UnionOfPartitionResultsTest.Apple.class, UnionOfPartitionResultsTest.Pie.class}
3029
)
3130
@SessionFactory
3231
public class UnionOfPartitionResultsTest {
3332

3433
@Test
35-
@FailureExpected
3634
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
3735
public void testUnionOfPartitionResults(SessionFactoryScope scope) {
36+
scope.inTransaction(
37+
session -> {
38+
String q = """
39+
SELECT id
40+
FROM
41+
(
42+
( SELECT id id, bakedPie bakedPie
43+
FROM Apple c
44+
)
45+
UNION ALL
46+
( SELECT id id, bakedPie bakedPie
47+
FROM Apple a
48+
)
49+
)
50+
""";
51+
52+
Query query = session.createQuery( q );
53+
54+
query.list();
55+
}
56+
);
57+
}
58+
59+
@Test
60+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
61+
public void testUnionOfPartitionResults6(SessionFactoryScope scope) {
62+
scope.inTransaction(
63+
session -> {
64+
String q = """
65+
SELECT id
66+
FROM
67+
(
68+
SELECT id id, bakedPie bakedPie
69+
FROM Apple c
70+
)
71+
""";
72+
73+
Query query = session.createQuery( q );
74+
75+
query.list();
76+
}
77+
);
78+
}
79+
80+
@Test
81+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
82+
public void testUnionOfPartitionResults4(SessionFactoryScope scope) {
83+
scope.inTransaction(
84+
session -> {
85+
String q = """
86+
( SELECT id id, bakedPie bakedPie
87+
FROM Apple c
88+
)
89+
UNION ALL
90+
( SELECT id id, bakedPie bakedPie
91+
FROM Apple c
92+
)
93+
""";
94+
95+
Query query = session.createQuery( q );
96+
97+
query.list();
98+
}
99+
);
100+
}
101+
102+
@Test
103+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
104+
public void testUnionOfPartitionResults2(SessionFactoryScope scope) {
105+
scope.inTransaction(
106+
session -> {
107+
String q = """
108+
SELECT id
109+
FROM
110+
(
111+
( SELECT id id, bakedPie.id bakedPie
112+
FROM Apple c
113+
)
114+
UNION ALL
115+
( SELECT id id, bakedPie.id bakedPie
116+
FROM Apple c
117+
)
118+
)
119+
""";
120+
121+
Query query = session.createQuery( q );
122+
123+
query.list();
124+
}
125+
);
126+
}
127+
128+
@Test
129+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
130+
public void testUnionOfPartitionResults3(SessionFactoryScope scope) {
38131
scope.inTransaction(
39132
session -> {
40133
String q =
41-
"SELECT new CurrentApple(id, bakedPie.id, dir) " +
42-
"FROM (" +
43-
"(" +
44-
"SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MAX(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, -1 dir " +
45-
"FROM Apple c " +
46-
"WHERE bakedPie.id IN (1,2,3,4) AND bakedOn <= :now" +
47-
") UNION ALL (" +
48-
"SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MIN(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, 1 dir " +
49-
"FROM Apple c " +
50-
"WHERE bakedPie.id IN (1,2,3,4) AND bakedOn > :now" +
51-
")" +
52-
") " +
53-
"WHERE bakedOn = mbo ORDER BY dir";
54-
55-
Query<CurrentApple> query = session.createQuery( q, CurrentApple.class );
56-
query.setParameter( "now", LocalDate.now());
57-
58-
query.getSingleResult();
134+
"SELECT id id, bakedPie bp, bakedOn bakedOn, MAX(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, -1 dir " +
135+
"FROM Apple c " +
136+
"WHERE bakedPie.id IN (1,2,3,4) AND bakedOn <= :now" +
137+
" UNION ALL " +
138+
"SELECT id id, bakedPie bp, bakedOn bakedOn, MIN(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, 1 dir " +
139+
"FROM Apple c " +
140+
"WHERE bakedPie.id IN (1,2,3,4) AND bakedOn > :now";
141+
142+
Query query = session.createQuery( q );
143+
query.setParameter( "now", LocalDate.now() );
144+
145+
query.list();
59146
}
60147
);
61148
}
@@ -70,12 +157,15 @@ public CurrentApple(int id, int pieId, int dir) {
70157
this.pieId = pieId;
71158
this.dir = dir;
72159
}
160+
73161
public int getDir() {
74162
return dir;
75163
}
164+
76165
public int getId() {
77166
return id;
78167
}
168+
79169
public int getPieId() {
80170
return pieId;
81171
}
@@ -93,20 +183,25 @@ public static class Apple {
93183
public Integer getId() {
94184
return id;
95185
}
186+
96187
public Apple setId(Integer id) {
97188
this.id = id;
98189
return this;
99190
}
191+
100192
public LocalDate getBakedOn() {
101193
return bakedOn;
102194
}
195+
103196
public Apple setBakedOn(LocalDate bakedOn) {
104197
this.bakedOn = bakedOn;
105198
return this;
106199
}
200+
107201
public Pie getBakedPie() {
108202
return bakedPie;
109203
}
204+
110205
public Apple setBakedPie(Pie bakedPie) {
111206
this.bakedPie = bakedPie;
112207
return this;
@@ -123,13 +218,16 @@ public static class Pie {
123218
public Integer getId() {
124219
return id;
125220
}
221+
126222
public Pie setId(Integer id) {
127223
this.id = id;
128224
return this;
129225
}
226+
130227
public String getTaste() {
131228
return taste;
132229
}
230+
133231
public Pie setTaste(String taste) {
134232
this.taste = taste;
135233
return this;

0 commit comments

Comments
 (0)