4

I am manually defining a Database XML schema to use the Jooq capabilities to generate the corresponding code from the definition. I am using Gradle to generate the code with Jooq:

jooq {
    version = '3.13.5'
    edition = nu.studer.gradle.jooq.JooqEdition.OSS
    configurations {
        crate {  
            generationTool {
                logging = org.jooq.meta.jaxb.Logging.INFO
                generator {
                    database {
                        name = 'org.jooq.meta.xml.XMLDatabase'
                        properties {
                            property {
                                key = 'dialect'
                                value = 'POSTGRES'
                            }
                            property {
                                key = 'xmlFile'
                                value = 'src/main/resources/crate_information_schema.xml'
                            }
                        }
                    }
                    target {
                        packageName = 'it.fox.crate'
                        directory = 'src/generated/crate'
                    }
                    strategy.name = "it.fox.generator.CrateGenerationStrategy"
                }
            }
        }
    }
}

and this is the XML file crate_information_schema.xml I am referencing:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<information_schema xmlns="http://www.jooq.org/xsd/jooq-meta-3.14.0.xsd">
    <schemata>
        <schema>
            <catalog_name></catalog_name>
            <schema_name>doc</schema_name>
            <comment></comment>
        </schema>
    </schemata>
    <tables>
        <table>
            <table_catalog></table_catalog>
            <table_schema>doc</table_schema>
            <table_name>events</table_name>
            <table_type>BASE TABLE</table_type>
            <comment></comment>
        </table>
    </tables>
    <columns>
        <column>
            <table_catalog></table_catalog>
            <table_schema>doc</table_schema>
            <table_name>events</table_name>
            <column_name>data_block['angularPositionArray']</column_name>
            <data_type>real_array</data_type>
            <character_maximum_length>0</character_maximum_length>
            <numeric_precision>19</numeric_precision>
            <numeric_scale>0</numeric_scale>
            <ordinal_position>1</ordinal_position>
            <is_nullable>false</is_nullable>
            <comment>angularPositionArray</comment>
        </column>
        <column>
            <table_catalog></table_catalog>
            <table_schema>doc</table_schema>
            <table_name>events</table_name>
            <column_name>data_block['eventId']</column_name>
            <data_type>bigint(20)</data_type>
            <character_maximum_length>0</character_maximum_length>
            <numeric_precision>19</numeric_precision>
            <numeric_scale>0</numeric_scale>
            <ordinal_position>1</ordinal_position>
            <is_nullable>false</is_nullable>
            <comment>eventId</comment>
        </column>
    </columns>
</information_schema>

The code generated is not good, because it indicate the Data Type used is unknown:

 /**
     * @deprecated Unknown data type. Please define an explicit {@link org.jooq.Binding} to specify how this type should be handled. Deprecation can be turned off using {@literal <deprecationOnUnknownTypes/>} in your code generator configuration.
     */
    @java.lang.Deprecated
    public final TableField<EventsRecord, Object> angularPositionArray = createField(DSL.name("data_block['angularPositionArray']"), org.jooq.impl.DefaultDataType.getDefaultDataType("\"real_array\"").nullable(false), this, "angularPositionArray");

I have a couple of questions:

  • which is the correct data type for Real Array?
  • where is the list of supported data type with the keys to use in the XML?

N.B. CrateDB is an unsupported DataBase but Jooq could talk to the DB using the Postgres driver, the only problem is to create manually the schema.

Stefano Bossi
  • 1,138
  • 1
  • 9
  • 19

1 Answers1

1

which is the correct data type for Real Array?

Use <data_type>REAL ARRAY</data_type> (with a whitespace, and upper case, see comments and issue #12611)

where is the list of supported data type with the keys to use in the XML?

It's the same as for any other code generation data source: All the types in SQLDataType are supported. The convention around array types is currently undocumented, but any of HSQLDB's or PostgreSQL's notations should work. The feature request to formally support array types as user defined types via standard SQL INFORMATION_SCHEMA.ELEMENT_TYPES is here: https://github.com/jOOQ/jOOQ/issues/8090

N.B. CrateDB is an unsupported DataBase but Jooq could talk to the DB using the Postgres driver, the only problem is to create manually the schema.

You can obviously use the XMLDatabase for this. I'm guessing you cannot use the JDBCDatabase, because the INFORMATION_SCHEMA is too different, and the PG_CATALOG schema doesn't exist? However, you could easily implement your own org.jooq.meta.Database, too, if that makes more sense.

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • Thanks, I have tried `real array` but I still have: ` @Deprecated public final TableField DATA_BLOCK_5b_27ANGULARPOSITIONARRAY_27_5d = createField(DSL.name("data_block['angularPositionArray']"), org.jooq.impl.DefaultDataType.getDefaultDataType("\"real array\"").nullable(false), this, "angularPositionArray"); ` and: ` 20:25:30 INFO Reading from: src/main/resources/crate_information_schema.xml [*] 20:25:30 INFO ARRAYs fetched : 0 (0 included, 0 excluded) ` Do you know why ? Regards – Stefano Bossi Nov 08 '21 at 19:30
  • While investigating, I've found a bug related to case sensitivity: https://github.com/jOOQ/jOOQ/issues/12611. It works for me with `REAL ARRAY`. It doesn't look like the same issue, though who knows. Perhaps, report a bug with a fully self contained reproducer here? https://github.com/jOOQ/jOOQ/issues/new/choose. There's a template to create such reproducers here: https://github.com/jOOQ/jOOQ-mcve – Lukas Eder Nov 09 '21 at 07:43
  • Still no success. I have created a real Postgres DB with a `phone_numbers real[]` column and used `org.jooq.codegen.XMLGenerator` to reverse the XML. The xml generator generate a `ARRAY` column specification not a `REAL ARRAY` one. The opposite with ARRAY create a `Object[]` and `REAL ARRAY` doesn't work. I am using 3.15.4 version. Do I have to wait the next one ? – Stefano Bossi Nov 09 '21 at 14:45
  • Please report a bug with details to reproduce. I don't have the full picture from your question. Keeping in mind that the issue to *formally* support array types in this XML format is not yet implemented: https://github.com/jOOQ/jOOQ/issues/8090, and that you're using an unsupported dialect, meaning that with such edge cases (such as array types), the dialect might get in the way, as the XML format also tries to mimick the output produced by e.g. `PostgresDatabase` or `H2Database` for the rest of the code generator to work. – Lukas Eder Nov 09 '21 at 15:14
  • 1
    The information schema for CrateDB should be similar, although not identical. Also we do have large parts of the PG_CATALOG schema implemented in CrateDB. I would also be happy to assist to get CrateDB fully compatible :) – proddata Nov 10 '21 at 15:16
  • @proddata: We're open to sponsored projects – Lukas Eder Nov 10 '21 at 15:36
  • Having CrateDB integrated with jooq will be wonderful ! – Stefano Bossi Nov 14 '21 at 15:27
  • @StefanoBossi: You can upvote here: https://github.com/jOOQ/jOOQ/issues/12629. But sponsoring will produce faster results :) – Lukas Eder Nov 15 '21 at 07:41