[ https://issues.apache.org/jira/browse/GROOVY-11713?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Per Nyfelt updated GROOVY-11713: -------------------------------- Description: The select portion of a ginq expression does not have a way to easily express "all alltributes" of an object. Given this test setup: class Employee \{ String mainSsn String coSsn String firstName BigDecimal salary LocalDate startDate } class Identifier \{ String customerId String lei } List employees = [ new Employee(mainSsn: '111', firstName: 'Rick', salary: 623.3, startDate: LocalDate.parse('2012-01-01')), new Employee(mainSsn: '222', coSsn: '444', firstName: 'Dan', salary: 515.2, startDate: LocalDate.parse('2013-09-23')), new Employee(mainSsn: '555', coSsn: '555', firstName: 'Michelle', salary: 611.0, startDate: LocalDate.parse('2014-11-15')), ] List identifiers = [ new Identifier(customerId: '2', lei: '111'), new Identifier(customerId: '3', lei: '222'), new Identifier(customerId: '4', lei: '333'), new Identifier(customerId: '5', lei: '444'), new Identifier(customerId: '6', lei: '555'), ] If this data was represented as tables in a database, i could wite the following SQL: select e.*, mcid.customerId as mainCustomerId, cocid.customerId as coCustomerId from e in employees left join mcid on e.mainSsn = mcid.lei left join cocid on e.coSsn = cocid.lei In ginq however, there is no support for wildcards or for a method that i can override that would expand an object into properties so i must name all attributes explicitly i.e.: def result = GQ \{ from e in employees leftjoin mcid in identifiers on e.mainSsn == mcid.lei leftjoin cocid in identifiers on e.coSsn == cocid.lei select e.mainSsn, e.coSsn, e.firstName, e.salary, e.startDate, mcid?.customerId as mainCustomerId, cocid?.customerId as coCustomerId } In this example, this is quite easy (not so many fields) but if a i have several object with 10+ fields, this becomes quite cumbersome. If there was a method (e.g. expand() that returns a certain type, such as a list of tuples or a Map, that qinq would understand then i could implement that method in the Employees class and write the above ginq expression as: def result = GQ \{ from e in employees leftjoin mcid in identifiers on e.mainSsn == mcid.lei leftjoin cocid in identifiers on e.coSsn == cocid.lei select expand(e), mcid?.customerId as mainCustomerId, cocid?.customerId as coCustomerId } Maybe even the default expand() method could base the attributes to include on getProperties() of the object which would probably be good enough for many cases. Adding support for this with an `expand` method would greatly enhance the user experience for these kind of cases. > Support wildcard like functionality in ginq > ------------------------------------------- > > Key: GROOVY-11713 > URL: https://issues.apache.org/jira/browse/GROOVY-11713 > Project: Groovy > Issue Type: Improvement > Reporter: Per Nyfelt > Priority: Major > > The select portion of a ginq expression does not have a way to easily express > "all alltributes" of an object. > Given this test setup: > class Employee \{ > String mainSsn > String coSsn > String firstName > BigDecimal salary > LocalDate startDate > } > class Identifier \{ > String customerId > String lei > } > List employees = [ > new Employee(mainSsn: '111', firstName: 'Rick', salary: 623.3, > startDate: LocalDate.parse('2012-01-01')), > new Employee(mainSsn: '222', coSsn: '444', firstName: 'Dan', salary: > 515.2, startDate: LocalDate.parse('2013-09-23')), > new Employee(mainSsn: '555', coSsn: '555', firstName: 'Michelle', > salary: 611.0, startDate: LocalDate.parse('2014-11-15')), > ] > List identifiers = [ > new Identifier(customerId: '2', lei: '111'), > new Identifier(customerId: '3', lei: '222'), > new Identifier(customerId: '4', lei: '333'), > new Identifier(customerId: '5', lei: '444'), > new Identifier(customerId: '6', lei: '555'), > ] > If this data was represented as tables in a database, i could wite the > following SQL: > select e.*, mcid.customerId as mainCustomerId, cocid.customerId as > coCustomerId > from e in employees > left join mcid on e.mainSsn = mcid.lei > left join cocid on e.coSsn = cocid.lei > > In ginq however, there is no support for wildcards or for a method that i can > override that would expand an object into properties so i must name all > attributes explicitly i.e.: > def result = GQ \{ > from e in employees > leftjoin mcid in identifiers on e.mainSsn == mcid.lei > leftjoin cocid in identifiers on e.coSsn == cocid.lei > select e.mainSsn, e.coSsn, e.firstName, e.salary, e.startDate, > mcid?.customerId as mainCustomerId, cocid?.customerId as coCustomerId > } > > In this example, this is quite easy (not so many fields) but if a i have > several object with 10+ fields, this becomes quite cumbersome. > If there was a method (e.g. expand() that returns a certain type, such as a > list of tuples or a Map, that qinq would understand then i could implement > that method in the Employees class and write the above ginq expression as: > def result = GQ \{ > from e in employees > leftjoin mcid in identifiers on e.mainSsn == mcid.lei > leftjoin cocid in identifiers on e.coSsn == cocid.lei > select expand(e), mcid?.customerId as mainCustomerId, > cocid?.customerId as coCustomerId > } > Maybe even the default expand() method could base the attributes to include > on getProperties() of the object which would probably be good enough for many > cases. > Adding support for this with an `expand` method would greatly enhance the > user experience for these kind of cases. -- This message was sent by Atlassian Jira (v8.20.10#820010)