sql - JOOQ: Result.getValues() returns list with null entry -
I have a many-to-do interrogated several relatives and to map the many results of an entry in an object the wanted. To do this, I bring results into groups by using a unique identifier and extract the required data from each grouped result. For many-to-many data, for all the available values, general data, I only get access to the data of the first entry:
Maps & LT; String, result & lt; Record2 & LT; String, string & gt; & Gt; groupedResults = create.select (LOC.NAME, GROUP.GROUP_) .from (LOC) .leftOuterJoin (LOC2GROUP) .on (Tables.LOC2GROUP.LOC_ID.eq (LOC.LOC_ID)) .leftOuterJoin (Group) .on (LOC2GROUP. GROUP_ID.eq (GROUP.GROUP_ID). .Fetch () InGroups (LOC.NAME); Collection & lt; Loc & gt; Rate = New Arrestist & lt; People & gt; (); (Results from & lt; Record2 & LT; String, String & gt; & gt; Results: groupedResults.values ()) {loc. Loc = new loc. (Result.getValue (0, LOCATION.NAME) , Result.getValues (Tables.GROUP.GROUP_)); Ret.add (loc); } Now, I can have more than one group in each entry, but there is no requirement in it, without any group set the following will be a valid entry:
| Name | Group | | Simple | {Null} Strangely, I noticed that Result.getValues () returns a list that contains null in such a situation, rather than blank
Is this intention and, if so, = "Text">
Using OUTER JOIN means that your result set can essentially change the values from the LOC table, but GROUP The table does not have any values There is some valid example output from the query: + ------ + -------- + | Name | Group | + ------ + -------- + | One | X | | One | Y | B X | | C. {Null} | & Lt; - There is a value in the LoC, but there is no value in GROUP ------------ ---- + Now, when you call jOOQ On that result, inGroups () , jOOQ looks at just 3 groups: a , b , and c , which gives you the following mAP JSON as (pseudo notation): { "a ":" {{Name}: "a", "group": "{{" name ":" b "," group ":" a "," group ":" x "}, {" name " "" "[" Name ":" c "," group ": null}]} P> Just because the value of zero in one of the columns does not mean that there should be no semantics in the zero value during closing. The fact is that This is a column ( group ) only the only column in which you are interested, does not change the fact that grouping results are records, not single values. I hope Does that make sense?
There is currently no way to support that The data structure that you actually see is:
{"a": ["x", "y"], "b" : ["X"], "c": []} but it should be
Or, you're using PostgreSQL or HSQLDB, instead of you can use ::
easier to write PostgreSQL or HSQLDB solution> Results & lt; Record2 & lt; String, string []> & Gt; Result = create.select (LOC.NAME, arrayAgg (GROUP.GROUP_)) .on .from (LOC) .leftOuterJoin (LOC2GROUP) .on (Tables.LOC2GROUP.LOC_ID.eq (LOC.LOC_ID)) .leftOuterJoin (Group) (LOC2GROUP.GROUP_ID.eq (GROUP.GROUP_ID)) .groupBy (LOC.NAME) .fetch (); DSL.arrayAgg () will be part of jOOQ 3.5, but you can create jOOQ function yourself: @Support ({SQLDialect.POSTGRES}) protected protected & lt; T & gt; From the field & lt; T []> Srniag (field & lt; T & gt; field) {return DSL.field ( "array_agg ({0})", field. GetDataType (). GetArrayDataType (), field); }
Comments
Post a Comment