Improve internal calculation of orm query plan hash key (Require use of inline hints like +query(50) to be comma delimited with properties) (#2159)

* WIP Tidy DefaultOrmQuery planDescription()

* WIP Tidy DefaultOrmQuery planDescription()

* Refactor OrmQueryPropertiesParser with hints requiring comma delimiting (previously didn't)

* Refactor OrmQueryPropertiesParser (reuse inputProperties) and DRawSqlColumnsParser (to return Set)

* Refactor OrmQueryPropertiesParser - remove JunkMain

* Refactor OrmQueryDetail, OrmQueryProperties - properties
This commit is contained in:
Rob Bygrave authored and GitHub committed 2021-02-13 11:58:00 +13:00
1 parent 758f84f573
commit 8ac5467856
14 files changed
+137 -249

No files matched your search

@@ -177,7 +177,7 @@ public class BeanTypeTest {
beanType(Order.class).docStore().applyPath(orderQuery);
OrmQueryDetail detail = orderQuery.getDetail();
assertThat(detail.getChunk("customer", false).getSelectInclude()).containsExactly("id", "name");
assertThat(detail.getChunk("customer", false).getIncluded()).containsExactly("id", "name");
}
@Test(expected = IllegalStateException.class)
@@ -15,7 +15,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_empty() throws Exception {
public void when_empty() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("");
assertAllDefaults(res);
@@ -23,7 +23,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasStar() throws Exception {
public void when_hasStar() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("*");
assertAllDefaults(res);
@@ -31,7 +31,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasCache() throws Exception {
public void when_hasCache() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+cache");
assertThat(res.cache).isTrue();
@@ -39,7 +39,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasCache_first() throws Exception {
public void when_hasCache_first() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+cache,id");
assertThat(res.cache).isTrue();
@@ -47,7 +47,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasCache_last() throws Exception {
public void when_hasCache_last() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+cache");
assertThat(res.cache).isTrue();
@@ -55,7 +55,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasCache_middle() throws Exception {
public void when_hasCache_middle() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+cache, id");
assertThat(res.cache).isTrue();
@@ -63,7 +63,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasReadOnly() throws Exception {
public void when_hasReadOnly() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+readonly");
assertThat(res.readOnly).isTrue();
@@ -71,7 +71,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasLazy() throws Exception {
public void when_hasLazy() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy");
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(0);
@@ -79,7 +79,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasLazyValue() throws Exception {
public void when_hasLazyValue() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20)");
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
@@ -87,7 +87,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasLazyValue_last() throws Exception {
public void when_hasLazyValue_last() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+lazy(20)");
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
@@ -95,7 +95,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_hasLazyValue_first() throws Exception {
public void when_hasLazyValue_first() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20),id,name");
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
@@ -103,7 +103,7 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_allProperties() throws Exception {
public void when_allProperties() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+query(4),+lazy(5)");
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(5);
@@ -111,14 +111,21 @@ public class OrmQueryPropertiesParserTest {
}
@Test
public void when_everything_set() throws Exception {
public void when_everything_set() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id, name +readonly +lazy(20) +query(30) +cache");
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id, name, +readonly ,+lazy(20), +query(30) ,+cache");
assertThat(res.included).containsExactly("id", "name");
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
assertThat(res.fetchConfig.getQueryBatchSize()).isEqualTo(30);
assertThat(res.readOnly).isTrue();
assertThat(res.cache).isTrue();
assertThat(res.included).containsExactly("id", "name");
}
@Test
public void when_formula() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("a,MD5(id::text) as b,c");
assertThat(res.included).containsExactly("a", "MD5(id::text) as b", "c");
}
private void assertAllDefaults(OrmQueryPropertiesParser.Response res) {
@@ -10,11 +10,11 @@ public class OrmQueryPropertiesTest {
String append(String prefix, OrmQueryProperties p1) {
StringBuilder sb = new StringBuilder();
p1.append(prefix, sb);
p1.asStringDebug(prefix, sb);
return sb.toString();
}
@Test(expected = IllegalArgumentException.class)
@Test(expected = NullPointerException.class)
public void construct_with_propertySet_when_null() {
new OrmQueryProperties(null, (LinkedHashSet<String>) null);
}
@@ -2,7 +2,7 @@ package io.ebeaninternal.server.util;
import org.junit.Test;
import java.util.List;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
@@ -11,49 +11,49 @@ public class DSelectColumnsParserTest {
@Test
public void parse() {
List<String> cols = DSelectColumnsParser.parse("a,MD5(id::text) as b,c");
Set<String> cols = DSelectColumnsParser.parse("a,MD5(id::text) as b,c");
assertThat(cols).containsExactly("a", "MD5(id::text) as b", "c");
}
@Test
public void whitespace_is_trimmed() {
List<String> cols = DSelectColumnsParser.parse("a , MD5(id::text) as b , c ");
Set<String> cols = DSelectColumnsParser.parse("a , MD5(id::text) as b , c ");
assertThat(cols).containsExactly("a", "MD5(id::text) as b", "c");
}
@Test
public void nestedFunctions() {
List<String> cols = DSelectColumnsParser.parse("a , concat(id,'sd',inner(foo)) as b , c ");
Set<String> cols = DSelectColumnsParser.parse("a , concat(id,'sd',inner(foo)) as b , c ");
assertThat(cols).containsExactly("a", "concat(id,'sd',inner(foo)) as b", "c");
}
@Test
public void basic() {
List<String> cols = DSelectColumnsParser.parse("name , status , billingAddress ");
Set<String> cols = DSelectColumnsParser.parse("name , status , billingAddress ");
assertThat(cols).containsExactly("name", "status", "billingAddress");
}
@Test
public void basic_noWhitespace() {
List<String> cols = DSelectColumnsParser.parse("a,b,c");
Set<String> cols = DSelectColumnsParser.parse("a,b,c");
assertThat(cols).containsExactly("a", "b", "c");
}
@Test
public void formula_noWhitespace() {
List<String> cols = DSelectColumnsParser.parse("a,concat(x,y),c");
Set<String> cols = DSelectColumnsParser.parse("a,concat(x,y),c");
assertThat(cols).containsExactly("a", "concat(x,y)", "c");
}
@Test
public void with_logicalCast_andAsAlias() {
List<String> cols = DSelectColumnsParser.parse("name , concat(status,'-end')::String as fullName , billingAddress ");
Set<String> cols = DSelectColumnsParser.parse("name , concat(status,'-end')::String as fullName , billingAddress ");
assertThat(cols).containsExactly("name", "concat(status,'-end')::String as fullName", "billingAddress");
}
@@ -28,7 +28,7 @@ public class TestQueryJoin extends BaseTestCase {
Query<Order> query = Ebean.find(Order.class).select("status")
// .join("details","+query(10)")
.fetch("customer", "+lazy(10) name, status").fetch("customer.contacts").order().asc("id");
.fetch("customer", "+lazy(10), name, status").fetch("customer.contacts").order().asc("id");
// .join("customer.billingAddress");
List<Order> list = query.findList();