jooq

jOOQ bitwise aggregation operations on bytes[] / binary column


I have a binary(48) column on a table and want to XOR that column in a group (bit_xor in MySQL, bit_xor_agg in H2).

I tried to use jOOQ's bitXorAgg() but it only accepts a field of type ? extends Number whereas my field is of type bytes[] (well, in reality, the bytes are encapsulated in a value object and the field is of the same type as the VO).

Is there a way to use bitXorAgg() with types other than Number?


Solution

  • You can either assume that jOOQ's internals will not make any data type specific conversions and just coerce data type before and after aggregation (a bit risky):

    bitXorAgg(field.coerce(INTEGER)).coerce(VARBINARY)
    

    Or use a plain SQL template expression:

    DSL.field("bit_xor_agg({0})", field.getDataType(), field);