Skip to content

Commit d428041

Browse files
dreab8mbellade
authored andcommitted
HHH-18069 - Add test
1 parent ab28a7f commit d428041

File tree

1 file changed

+90
-14
lines changed

1 file changed

+90
-14
lines changed

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

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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;
13+
import org.hibernate.testing.orm.junit.JiraKey;
1414
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
1515
import org.hibernate.testing.orm.junit.SessionFactory;
1616
import org.hibernate.testing.orm.junit.SessionFactoryScope;
@@ -25,41 +25,106 @@
2525
/**
2626
* @author Jan Schatteman
2727
*/
28-
@DomainModel (
29-
annotatedClasses = { UnionOfPartitionResultsTest.Apple.class, UnionOfPartitionResultsTest.Pie.class }
28+
@DomainModel(
29+
annotatedClasses = {UnionOfPartitionResultsTest.Apple.class, UnionOfPartitionResultsTest.Pie.class}
3030
)
3131
@SessionFactory
32+
@JiraKey( "HHH-18069" )
3233
public class UnionOfPartitionResultsTest {
3334

3435
@Test
35-
@FailureExpected
3636
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
37+
public void testSubqueryWithUnion(SessionFactoryScope scope) {
38+
scope.inTransaction(
39+
session -> {
40+
String q = "SELECT id " +
41+
"FROM " +
42+
"( " +
43+
"( SELECT id id, bakedPie bakedPie " +
44+
"\tFROM Apple c " +
45+
") " +
46+
"\tUNION ALL " +
47+
"( SELECT id id, bakedPie bakedPie " +
48+
"\tFROM Apple a " +
49+
") " +
50+
")";
51+
52+
Query query = session.createQuery( q );
53+
54+
query.list();
55+
}
56+
);
57+
}
58+
59+
@Test
60+
public void testSubquery(SessionFactoryScope scope) {
61+
scope.inTransaction(
62+
session -> {
63+
String q = "SELECT id " +
64+
"FROM " +
65+
"( " +
66+
"\tSELECT id id, bakedPie bakedPie " +
67+
"\tFROM Apple c " +
68+
")";
69+
70+
Query query = session.createQuery( q );
71+
72+
query.list();
73+
}
74+
);
75+
}
76+
77+
@Test
78+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
79+
public void testUnionQuery(SessionFactoryScope scope) {
80+
scope.inTransaction(
81+
session -> {
82+
String q = "( SELECT id id, bakedPie bakedPie " +
83+
"\tFROM Apple c " +
84+
") " +
85+
"\tUNION ALL " +
86+
"( SELECT id id, bakedPie bakedPie " +
87+
"\tFROM Apple c " +
88+
") ";
89+
90+
Query query = session.createQuery( q );
91+
92+
query.list();
93+
}
94+
);
95+
}
96+
97+
98+
@Test
99+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportsUnion.class)
100+
@RequiresDialectFeature(feature = DialectFeatureChecks.SupportPartitionBy.class)
37101
public void testUnionOfPartitionResults(SessionFactoryScope scope) {
38102
scope.inTransaction(
39103
session -> {
40104
String q =
41105
"SELECT new CurrentApple(id, bakedPie.id, dir) " +
42106
"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-
")" +
107+
"(" +
108+
"SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MAX(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, -1 dir " +
109+
"FROM Apple c " +
110+
"WHERE bakedPie.id IN (1,2,3,4) AND bakedOn <= :now" +
111+
") UNION ALL (" +
112+
"SELECT id id, bakedPie bakedPie, bakedOn bakedOn, MIN(bakedOn) OVER (PARTITION BY bakedPie.id) mbo, 1 dir " +
113+
"FROM Apple c " +
114+
"WHERE bakedPie.id IN (1,2,3,4) AND bakedOn > :now" +
115+
")" +
52116
") " +
53117
"WHERE bakedOn = mbo ORDER BY dir";
54118

55119
Query<CurrentApple> query = session.createQuery( q, CurrentApple.class );
56120
query.setParameter( "now", LocalDate.now());
57121

58-
query.getSingleResult();
122+
query.list();
59123
}
60124
);
61125
}
62126

127+
63128
public static class CurrentApple {
64129
private final int id;
65130
private final int pieId;
@@ -70,12 +135,15 @@ public CurrentApple(int id, int pieId, int dir) {
70135
this.pieId = pieId;
71136
this.dir = dir;
72137
}
138+
73139
public int getDir() {
74140
return dir;
75141
}
142+
76143
public int getId() {
77144
return id;
78145
}
146+
79147
public int getPieId() {
80148
return pieId;
81149
}
@@ -93,20 +161,25 @@ public static class Apple {
93161
public Integer getId() {
94162
return id;
95163
}
164+
96165
public Apple setId(Integer id) {
97166
this.id = id;
98167
return this;
99168
}
169+
100170
public LocalDate getBakedOn() {
101171
return bakedOn;
102172
}
173+
103174
public Apple setBakedOn(LocalDate bakedOn) {
104175
this.bakedOn = bakedOn;
105176
return this;
106177
}
178+
107179
public Pie getBakedPie() {
108180
return bakedPie;
109181
}
182+
110183
public Apple setBakedPie(Pie bakedPie) {
111184
this.bakedPie = bakedPie;
112185
return this;
@@ -123,13 +196,16 @@ public static class Pie {
123196
public Integer getId() {
124197
return id;
125198
}
199+
126200
public Pie setId(Integer id) {
127201
this.id = id;
128202
return this;
129203
}
204+
130205
public String getTaste() {
131206
return taste;
132207
}
208+
133209
public Pie setTaste(String taste) {
134210
this.taste = taste;
135211
return this;

0 commit comments

Comments
 (0)