mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
Yugabyte - use distinct on clause with Yugabyte (like Postgres)
This commit is contained in:
1 parent
2cd769d00f
commit
94951a5476
12 files changed
+28
-24
No files matched your search
@@ -195,6 +195,10 @@ public abstract class BaseTestCase {
|
||||
return Platform.DB2 == platform();
|
||||
}
|
||||
|
||||
public boolean platformDistinctOn() {
|
||||
return isPostgresCompatible();
|
||||
}
|
||||
|
||||
public boolean isPostgresCompatible() {
|
||||
return isPostgres() || isYugabyte();
|
||||
}
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ public class IsEmptyExpressionQueryTest extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sqlOf(query)).contains("select distinct on (t0.id) t0.id from o_customer t0 join contact u1 on u1.customer_id = t0.id where not exists (select 1 from contact_note x where x.contact_id = u1.id)");
|
||||
|
||||
} else {
|
||||
@@ -140,7 +140,7 @@ public class IsEmptyExpressionQueryTest extends BaseTestCase {
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sqlOf(query)).contains("select distinct on (t0.id) t0.id from o_customer t0 join contact u1 on u1.customer_id = t0.id where exists (select 1 from contact_note x where x.contact_id = u1.id)");
|
||||
|
||||
} else {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 join o_order u1 on u1.kcustomer_id = t0.id and u1.order_date is not null join o_order_detail u2 on u2.order_id = u1.id and u2.id > 0 join o_product u3 on u3.id = u2.product_id where u3.name = ?";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
|
||||
@@ -54,7 +54,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id and u1.order_date is not null left join o_order_detail u2 on u2.order_id = u1.id and u2.id > 0 left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ?)";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
} else {
|
||||
@@ -75,7 +75,7 @@ public class TestImplicitJoinOnParentRelationship extends BaseTestCase {
|
||||
|
||||
query.findList();
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
String expectedSql = "select distinct on (t0.id) t0.id, t0.name from o_customer t0 left join o_order u1 on u1.kcustomer_id = t0.id and u1.order_date is not null left join o_order_detail u2 on u2.order_id = u1.id and u2.id > 0 left join o_product u3 on u3.id = u2.product_id where (u3.name = ? or t0.id = ?)";
|
||||
assertThat(sqlOf(query, 1)).contains(expectedSql);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TestManyWhereJoin extends BaseTestCase {
|
||||
// join o_order u1 on u1.kcustomer_id = t0.id
|
||||
// where u1.status = ? ; --bind(NEW)
|
||||
|
||||
if (isPostgres()) {
|
||||
if (isPostgresCompatible()) {
|
||||
assertThat(sql).contains("select distinct on (t0.id) t0.id, ");
|
||||
} else {
|
||||
assertThat(sql).contains("select distinct t0.id");
|
||||
@@ -70,7 +70,7 @@ public class TestManyWhereJoin extends BaseTestCase {
|
||||
// where t1.order_date is not null and u1.status = ?
|
||||
// order by t0.id; --bind(NEW)
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sql).contains("select distinct on (t0.id, t1.id) t0.id, t0.status,");
|
||||
} else {
|
||||
assertThat(sql).contains("select distinct t0.id, t0.status, t1.id, t1.status,");
|
||||
@@ -101,7 +101,7 @@ public class TestManyWhereJoin extends BaseTestCase {
|
||||
// where u1.product_id = ?
|
||||
// order by t0.cretime; --bind(1)
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sql).contains("select distinct on (t0.cretime, t0.id) t0.id, t0.status,");
|
||||
} else {
|
||||
assertThat(sql).contains("select distinct t0.id, t0.status,");
|
||||
@@ -135,7 +135,7 @@ public class TestManyWhereJoin extends BaseTestCase {
|
||||
// where u1.product_id = ?
|
||||
// order by t0.cretime
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sql).contains("select distinct on (t0.cretime, t0.id) t0.id, t0.status,");
|
||||
} else {
|
||||
assertThat(sql).contains("select distinct t0.id, t0.status,");
|
||||
@@ -171,7 +171,7 @@ public class TestManyWhereJoin extends BaseTestCase {
|
||||
// where t1.id > 0 and u1.product_id = ?
|
||||
// order by t0.cretime, t0.id, t1.id asc, t1.order_qty asc, t1.cretime desc; --bind(1)
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sql).contains("select distinct on (t0.cretime, t0.id, t1.id, t1.order_qty, t1.cretime) t0.id, t0.status,");
|
||||
} else {
|
||||
assertThat(sql).contains("select distinct t0.id, t0.status,");
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TestDisjunctWhereOuterOnMany extends BaseTestCase {
|
||||
assertEquals(2, list.size());
|
||||
assertEquals(2, rowCount);
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
String expectedSql = "select distinct on (t0.id) t0.id, t0.name, t0.description, t0.version from uuone t0 left join uutwo u1 on u1.master_id = t0.id where (t0.name = ? or u1.name = ?)";
|
||||
assertSql(query).contains(expectedSql);
|
||||
|
||||
|
||||
@@ -115,7 +115,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase {
|
||||
.where().isNotNull("order.shipments.order.totalAmount").query();
|
||||
|
||||
shipQuery.findList();
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(shipQuery.getGeneratedSql()).contains("select distinct on (t0.id) t0.id from or_order_ship t0");
|
||||
} else {
|
||||
assertSql(shipQuery.getGeneratedSql()).contains("select distinct t0.id from or_order_ship t0 ");
|
||||
|
||||
@@ -49,7 +49,7 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
||||
query.findList();
|
||||
|
||||
String sql = sqlOf(query);
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(sql).contains("select distinct on (t0.user_name, t0.userid) t0.userid,");
|
||||
} else if (isH2()) {
|
||||
assertThat(sql).contains("select distinct t0.userid, t0.user_name, t0.user_type_id from muser t0");
|
||||
@@ -133,7 +133,7 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
||||
assertEquals(1, list.size());
|
||||
assertEquals(user1, list.get(0));
|
||||
String generatedSql = query.getGeneratedSql();
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(generatedSql).contains("select distinct on (t1.name, t0.user_name, t0.userid) t0.userid"); // using distinct
|
||||
|
||||
} else {
|
||||
@@ -168,7 +168,7 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
||||
// order by t1.name; --bind(A)
|
||||
|
||||
generatedSql = query.getGeneratedSql();
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(generatedSql).contains("select distinct on (t1.name, t0.userid) t0.userid"); // using distinct
|
||||
} else {
|
||||
assertThat(generatedSql).contains("select distinct t0.userid"); // using distinct
|
||||
|
||||
@@ -36,7 +36,7 @@ public class TestOrderByWithDistinctTake2 extends BaseTestCase {
|
||||
// where lower(u1.first_name) like ?
|
||||
// order by t0.name; --bind(r%)
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(generatedSql).contains("select distinct on (t0.name, t0.id) t0.id, t0.name");
|
||||
|
||||
} else {
|
||||
@@ -59,7 +59,7 @@ public class TestOrderByWithDistinctTake2 extends BaseTestCase {
|
||||
|
||||
String generatedSql = sqlOf(query);
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(generatedSql).contains("select distinct on (t0.name, t0.id) t0.id, t0.name, t0.id");
|
||||
} else {
|
||||
assertThat(generatedSql).contains("select distinct t0.id, t0.name, t0.id");
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TestQueryConversationRowCount extends BaseTestCase {
|
||||
// where t0.group_id = ? and ((t0.open = ? and u1.user_id = ? ) or t0.open = ? )
|
||||
// order by t0.when_created desc;
|
||||
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(generatedSql).contains("select distinct on (t0.when_created, t0.id) t0.id, t0.title, t0.isopen");
|
||||
|
||||
} else {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TestQueryRowCountWithMany extends BaseTestCase {
|
||||
// order by t0.cretime, t0.id, t1.id asc, t1.order_qty asc, t1.cretime desc; --bind(1)
|
||||
|
||||
String generatedSql = sqlOf(query, 1);
|
||||
if (isPostgres()) {
|
||||
if (platformDistinctOn()) {
|
||||
assertThat(generatedSql).contains("select distinct on (t0.cretime, t0.id, t1.id, t1.order_qty, t1.cretime) t0.id, t0.status,"); // need the distinct
|
||||
|
||||
} else {
|
||||
|
||||
@@ -18,12 +18,12 @@ ebean.encryptKeyManager=org.tests.basic.encrypt.BasicEncyptKeyManager
|
||||
#ebean.autoTune.profiling=true
|
||||
#ebean.autoTune.profilingUpdateFrequency=5
|
||||
|
||||
ebean.ddl.generate=true
|
||||
ebean.ddl.run=true
|
||||
#ebean.ddl.generate=true
|
||||
#ebean.ddl.run=true
|
||||
ebean.ddl.header=-- Generated by ebean ${version} at ${timestamp}
|
||||
ebean.packages=org.tests,org.etest
|
||||
datasource.default=h2
|
||||
#datasource.default=yugabyte
|
||||
#datasource.default=h2
|
||||
datasource.default=yugabyte
|
||||
#datasource.h2.capturestacktrace=true
|
||||
|
||||
#ebean.dumpMetricsOnShutdown=true
|
||||
|
||||
Reference in new issue
Block a user