mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-01 15:37:14 +00:00
#1333 - ENH: Support "dynamic formula" with findSingleAttributeList() ... e.g. .select("concat(lastName,', ',firstName)")
This commit is contained in:
1 parent
05b8adbf6e
commit
c1c85b67c2
12 files changed
+266
-100
No files matched your search
@@ -46,7 +46,7 @@ public class DeployPropertyParserTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void combined_withAtColumn() {
|
||||
assertThat(adddressParser().parse("concat(line1, line2, '-EA')")).isEqualTo("concat(${}line_1, ${}line_2, '-EA')");
|
||||
assertThat(addressParser().parse("concat(line1, line2, '-EA')")).isEqualTo("concat(${}line_1, ${}line_2, '-EA')");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,11 +55,11 @@ public class DeployPropertyParserTest extends BaseTestCase {
|
||||
}
|
||||
|
||||
private DeployPropertyParser parser() {
|
||||
return descriptor.createDeployPropertyParser();
|
||||
return descriptor.parser();
|
||||
}
|
||||
|
||||
private DeployPropertyParser adddressParser() {
|
||||
return addressBeanDescriptor.createDeployPropertyParser();
|
||||
|
||||
private DeployPropertyParser addressParser() {
|
||||
return addressBeanDescriptor.parser();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +1,45 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebeaninternal.server.query.SqlTreeProperty;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FormulaPropertyPathTest extends BaseTestCase {
|
||||
|
||||
//private BeanDescriptor<Customer> customerDesc = getBeanDescriptor(Customer.class);
|
||||
private BeanDescriptor<Customer> customerDesc = getBeanDescriptor(Customer.class);
|
||||
|
||||
@Test
|
||||
public void isFormula() {
|
||||
|
||||
assertFormula("max(foo)", "max", "foo");
|
||||
assertFormula("min(bar)", "min", "bar");
|
||||
assertFormula("avg(baz)", "avg", "baz");
|
||||
assertFormula("max(version)", "max", "version");
|
||||
assertFormula("min(name)", "min", "name");
|
||||
assertFormula("avg(id)", "avg", "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFormula_count() {
|
||||
assertFormula("count(moo)", "count", "moo");
|
||||
assertFormula("count(distinct joo)", "count", "joo");
|
||||
assertFormula("count(status)", "count", "status");
|
||||
assertFormula("count(distinct name)", "count", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concat() {
|
||||
|
||||
assertFormula("concat(name,'-end')", "concat", "name,'-end'");
|
||||
}
|
||||
|
||||
private void assertFormula(String input, String aggType, String baseProperty) {
|
||||
|
||||
FormulaPropertyPath propertyPath = new FormulaPropertyPath(input);
|
||||
FormulaPropertyPath propertyPath = new FormulaPropertyPath(customerDesc, input);
|
||||
|
||||
assertThat(propertyPath.isFormula()).isTrue();
|
||||
assertThat(propertyPath.basePropertyName()).isEqualTo(baseProperty);
|
||||
assertThat(propertyPath.aggType()).isEqualTo(aggType);
|
||||
|
||||
SqlTreeProperty treeProperty = propertyPath.build();
|
||||
|
||||
assertThat(treeProperty).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package io.ebeaninternal.server.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DSelectColumnsParserTest {
|
||||
|
||||
@Test
|
||||
public void parse() {
|
||||
|
||||
List<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 ");
|
||||
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 ");
|
||||
assertThat(cols).containsExactly("a", "concat(id,'sd',inner(foo)) as b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() {
|
||||
|
||||
List<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");
|
||||
assertThat(cols).containsExactly("a", "b", "c");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formula_noWhitespace() {
|
||||
|
||||
List<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 ");
|
||||
assertThat(cols).containsExactly("name", "concat(status,'-end')::String as fullName", "billingAddress");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user