@@ -412,7 +412,7 @@ class CanonicalSpringKotlinTest {
412412 }
413413
414414 assertThat(records).hasSize(3 )
415- with (records[0 ]!! ) {
415+ with (records[0 ]) {
416416 assertThat(id).isEqualTo(1 )
417417 assertThat(firstName).isEqualTo(" Fred" )
418418 assertThat(lastName).isEqualTo(" Flintstone" )
@@ -422,7 +422,7 @@ class CanonicalSpringKotlinTest {
422422 assertThat(addressId).isEqualTo(1 )
423423 }
424424
425- with (records[2 ]!! ) {
425+ with (records[2 ]) {
426426 assertThat(id).isEqualTo(3 )
427427 assertThat(firstName).isEqualTo(" Pebbles" )
428428 assertThat(lastName).isEqualTo(" Flintstone" )
@@ -485,7 +485,7 @@ class CanonicalSpringKotlinTest {
485485 }
486486
487487 assertThat(records).hasSize(3 )
488- with (records[0 ]!! ) {
488+ with (records[0 ]) {
489489 assertThat(id).isEqualTo(1 )
490490 assertThat(firstName).isEqualTo(" Fred" )
491491 assertThat(lastName).isEqualTo(" Flintstone" )
@@ -495,7 +495,7 @@ class CanonicalSpringKotlinTest {
495495 assertThat(addressId).isEqualTo(1 )
496496 }
497497
498- with (records[2 ]!! ) {
498+ with (records[2 ]) {
499499 assertThat(id).isEqualTo(3 )
500500 assertThat(firstName).isEqualTo(" Pebbles" )
501501 assertThat(lastName).isEqualTo(" Flintstone" )
@@ -558,7 +558,7 @@ class CanonicalSpringKotlinTest {
558558 }
559559
560560 assertThat(records).hasSize(3 )
561- with (records[0 ]!! ) {
561+ with (records[0 ]) {
562562 assertThat(id).isEqualTo(1 )
563563 assertThat(firstName).isEqualTo(" Fred" )
564564 assertThat(lastName).isEqualTo(" Flintstone" )
@@ -568,7 +568,80 @@ class CanonicalSpringKotlinTest {
568568 assertThat(addressId).isEqualTo(1 )
569569 }
570570
571- with (records[2 ]!! ) {
571+ with (records[2 ]) {
572+ assertThat(id).isEqualTo(3 )
573+ assertThat(firstName).isEqualTo(" Pebbles" )
574+ assertThat(lastName).isEqualTo(" Flintstone" )
575+ assertThat(birthDate).isNotNull()
576+ assertThat(employed).isEqualTo(" No" )
577+ assertThat(occupation).isNull()
578+ assertThat(addressId).isEqualTo(1 )
579+ }
580+ }
581+
582+ @Test
583+ fun testRawSelectWithUnionAllAndDistinct () {
584+ val selectStatement = select(
585+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
586+ addressId
587+ ).from(Person ) {
588+ where(id, isEqualTo(1 ))
589+ union {
590+ select(
591+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
592+ addressId
593+ ).from(Person ) {
594+ where(id, isEqualTo(2 ))
595+ }
596+ }
597+ unionAll {
598+ selectDistinct(
599+ id.`as `(" A_ID" ), firstName, lastName, birthDate, employed, occupation,
600+ addressId
601+ ).from(Person , " p" ) {
602+ where(id, isEqualTo(3 ))
603+ }
604+ }
605+ }
606+
607+ val expected = " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
608+ " from Person " +
609+ " where id = :p1 " +
610+ " union " +
611+ " select id as A_ID, first_name, last_name, birth_date, employed, occupation, address_id " +
612+ " from Person " +
613+ " where id = :p2 " +
614+ " union all " +
615+ " select distinct p.id as A_ID, p.first_name, p.last_name, p.birth_date, p.employed, p.occupation, p.address_id " +
616+ " from Person p " +
617+ " where p.id = :p3"
618+
619+ assertThat(selectStatement.selectStatement).isEqualTo(expected)
620+
621+ val records = template.selectList(selectStatement) { rs, _ ->
622+ val record = PersonRecord ()
623+ record.id = rs.getInt(1 )
624+ record.firstName = rs.getString(2 )
625+ record.lastName = rs.getString(3 )
626+ record.birthDate = rs.getTimestamp(4 )
627+ record.employed = rs.getString(5 )
628+ record.occupation = rs.getString(6 )
629+ record.addressId = rs.getInt(7 )
630+ record
631+ }
632+
633+ assertThat(records).hasSize(3 )
634+ with (records[0 ]) {
635+ assertThat(id).isEqualTo(1 )
636+ assertThat(firstName).isEqualTo(" Fred" )
637+ assertThat(lastName).isEqualTo(" Flintstone" )
638+ assertThat(birthDate).isNotNull()
639+ assertThat(employed).isEqualTo(" Yes" )
640+ assertThat(occupation).isEqualTo(" Brontosaurus Operator" )
641+ assertThat(addressId).isEqualTo(1 )
642+ }
643+
644+ with (records[2 ]) {
572645 assertThat(id).isEqualTo(3 )
573646 assertThat(firstName).isEqualTo(" Pebbles" )
574647 assertThat(lastName).isEqualTo(" Flintstone" )
0 commit comments