diff --git a/jOOQ-test/src/org/jooq/test/_/testcases/ExoticTests.java b/jOOQ-test/src/org/jooq/test/_/testcases/ExoticTests.java index d25026c7ea..21d60c74fc 100644 --- a/jOOQ-test/src/org/jooq/test/_/testcases/ExoticTests.java +++ b/jOOQ-test/src/org/jooq/test/_/testcases/ExoticTests.java @@ -44,6 +44,8 @@ import static org.jooq.impl.Factory.connectByIsLeaf; import static org.jooq.impl.Factory.connectByRoot; import static org.jooq.impl.Factory.count; import static org.jooq.impl.Factory.field; +import static org.jooq.impl.Factory.fieldByName; +import static org.jooq.impl.Factory.inline; import static org.jooq.impl.Factory.level; import static org.jooq.impl.Factory.lower; import static org.jooq.impl.Factory.max; @@ -268,6 +270,60 @@ extends BaseTest r1 = + create().select() + .from(TBookToBookStore() + .pivot(max(TBookToBookStore_STOCK()).as("max"), + count(TBookToBookStore_STOCK()).as("cnt")) + .on(TBookToBookStore_BOOK_STORE_NAME()) + .in("Orell Füssli", + "Ex Libris", + "Buchhandlung im Volkshaus") + .as("pivot_table", "book_id", "of_max", "of_cnt", + "ex_max", "ex_cnt", + "bv_max", "bv_cnt")) + .orderBy(val(1).asc()) + .fetch(); + + assertEquals(3, r1.size()); + assertEquals(7, r1.getFields().size()); + assertEquals(asList(1, 2, 3), r1.getValues("book_id", Integer.class)); + assertEquals(asList(10, 10, 10), r1.getValues("of_max", Integer.class)); + assertEquals(asList(1, 1, 1), r1.getValues("of_cnt", Integer.class)); + assertEquals(asList(1, null, 2), r1.getValues("ex_max", Integer.class)); + assertEquals(asList(1, 0, 1), r1.getValues("ex_cnt", Integer.class)); + assertEquals(asList(null, null, 1), r1.getValues("bv_max", Integer.class)); + assertEquals(asList(0, 0, 1), r1.getValues("bv_cnt", Integer.class)); + + create().select() + .from(table(select(level().as("lvl")).connectBy(level().le(inline(5)))) + .pivot(max(fieldByName("lvl"))) + .on(fieldByName("lvl")) + .in(1, 2, 3, 4, 5) + .as("t", "a", "b", "c", "d", "e")) + .fetch(); + } + @Test public void testRelationalDivision() throws Exception { diff --git a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java index b81289fc0f..25790cf49d 100644 --- a/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java +++ b/jOOQ-test/src/org/jooq/test/jOOQAbstractTest.java @@ -1564,6 +1564,11 @@ public abstract class jOOQAbstractTest< new AliasTests(this).testAliasingJoins(); } + @Test + public void testAliasingPivot() throws Exception { + new ExoticTests(this).testAliasingPivot(); + } + // @Test // TODO [#579] re-enable this test when fixing this bug public void testUnaliasedSubqueryProjections() throws Exception { new SelectTests(this).testUnaliasedSubqueryProjections();