[jOOQ/jOOQ#15732] Add code generation support for arrays
This commit is contained in:
parent
a5974f3865
commit
dd6b16512e
@ -541,6 +541,8 @@ class GenerationUtil {
|
||||
|
||||
|
||||
|
||||
case DUCKDB:
|
||||
return new BaseType(t.replaceFirst("(?i:array)|\\[\\]", ""), u);
|
||||
|
||||
|
||||
case POSTGRES:
|
||||
|
||||
@ -3472,6 +3472,7 @@ public abstract class AbstractDatabase implements Database {
|
||||
|
||||
|
||||
|
||||
case DUCKDB:
|
||||
case H2:
|
||||
case POSTGRES:
|
||||
case YUGABYTEDB:
|
||||
|
||||
@ -96,6 +96,8 @@ import org.jooq.meta.TableDefinition;
|
||||
import org.jooq.meta.UDTDefinition;
|
||||
import org.jooq.meta.XMLSchemaCollectionDefinition;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* The DuckDB database
|
||||
*
|
||||
@ -116,7 +118,11 @@ public class DuckDBDatabase extends AbstractDatabase implements ResultQueryDatab
|
||||
|
||||
@Override
|
||||
protected DSLContext create0() {
|
||||
return DSL.using(getConnection(), SQLDialect.DUCKDB);
|
||||
DSLContext ctx = DSL.using(getConnection(), SQLDialect.DUCKDB);
|
||||
|
||||
// Cannot fully qualify column references of table valued functions
|
||||
ctx.settings().setRenderSchema(false);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -13,7 +13,6 @@ import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.DefaultDataType;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.impl.TableImpl;
|
||||
import org.jooq.meta.duckdb.system.main.Main;
|
||||
@ -91,26 +90,16 @@ public class DuckdbConstraints extends TableImpl<Record> {
|
||||
public final TableField<Record, String> EXPRESSION = createField(DSL.name("expression"), SQLDataType.VARCHAR, this, "");
|
||||
|
||||
/**
|
||||
* @deprecated Unknown data type. If this is a qualified, user-defined type,
|
||||
* it may have been excluded from code generation. If this is a built-in
|
||||
* type, you can 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.
|
||||
* The column
|
||||
* <code>system.main.duckdb_constraints.constraint_column_indexes</code>.
|
||||
*/
|
||||
@Deprecated
|
||||
public final TableField<Record, Object> CONSTRAINT_COLUMN_INDEXES = createField(DSL.name("constraint_column_indexes"), DefaultDataType.getDefaultDataType("BIGINT[]"), this, "");
|
||||
public final TableField<Record, Long[]> CONSTRAINT_COLUMN_INDEXES = createField(DSL.name("constraint_column_indexes"), SQLDataType.BIGINT.array(), this, "");
|
||||
|
||||
/**
|
||||
* @deprecated Unknown data type. If this is a qualified, user-defined type,
|
||||
* it may have been excluded from code generation. If this is a built-in
|
||||
* type, you can 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.
|
||||
* The column
|
||||
* <code>system.main.duckdb_constraints.constraint_column_names</code>.
|
||||
*/
|
||||
@Deprecated
|
||||
public final TableField<Record, Object> CONSTRAINT_COLUMN_NAMES = createField(DSL.name("constraint_column_names"), DefaultDataType.getDefaultDataType("VARCHAR[]"), this, "");
|
||||
public final TableField<Record, String[]> CONSTRAINT_COLUMN_NAMES = createField(DSL.name("constraint_column_names"), SQLDataType.VARCHAR.array(), this, "");
|
||||
|
||||
private DuckdbConstraints(Name alias, Table<Record> aliased) {
|
||||
this(alias, aliased, (Field<?>[]) null, null);
|
||||
|
||||
@ -16,7 +16,6 @@ import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.DefaultDataType;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.impl.TableImpl;
|
||||
import org.jooq.meta.duckdb.system.main.Keys;
|
||||
@ -100,15 +99,9 @@ public class DuckdbTypes extends TableImpl<Record> {
|
||||
public final TableField<Record, Boolean> INTERNAL = createField(DSL.name("internal"), SQLDataType.BOOLEAN, this, "");
|
||||
|
||||
/**
|
||||
* @deprecated Unknown data type. If this is a qualified, user-defined type,
|
||||
* it may have been excluded from code generation. If this is a built-in
|
||||
* type, you can 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.
|
||||
* The column <code>system.main.duckdb_types.labels</code>.
|
||||
*/
|
||||
@Deprecated
|
||||
public final TableField<Record, Object> LABELS = createField(DSL.name("labels"), DefaultDataType.getDefaultDataType("VARCHAR[]"), this, "");
|
||||
public final TableField<Record, String[]> LABELS = createField(DSL.name("labels"), SQLDataType.VARCHAR.array(), this, "");
|
||||
|
||||
private DuckdbTypes(Name alias, Table<Record> aliased) {
|
||||
this(alias, aliased, (Field<?>[]) null, null);
|
||||
|
||||
@ -41,6 +41,7 @@ import static java.util.Collections.unmodifiableCollection;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.CLICKHOUSE;
|
||||
// ...
|
||||
import static org.jooq.SQLDialect.DUCKDB;
|
||||
import static org.jooq.SQLDialect.FIREBIRD;
|
||||
import static org.jooq.SQLDialect.H2;
|
||||
import static org.jooq.SQLDialect.HSQLDB;
|
||||
@ -140,28 +141,29 @@ import org.jetbrains.annotations.ApiStatus.Internal;
|
||||
@Internal
|
||||
public class DefaultDataType<T> extends AbstractDataTypeX<T> {
|
||||
|
||||
private static final Set<SQLDialect> ENCODED_TIMESTAMP_PRECISION = SQLDialect.supportedBy(HSQLDB, MARIADB);
|
||||
private static final Set<SQLDialect> NO_SUPPORT_TIMESTAMP_PRECISION = SQLDialect.supportedBy(FIREBIRD, MYSQL, SQLITE);
|
||||
private static final Set<SQLDialect> SUPPORT_POSTGRES_ARRAY_NOTATION = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB);
|
||||
private static final Set<SQLDialect> SUPPORT_HSQLDB_ARRAY_NOTATION = SQLDialect.supportedBy(H2, HSQLDB, POSTGRES, YUGABYTEDB);
|
||||
private static final Set<SQLDialect> SUPPORT_TRINO_ARRAY_NOTATION = SQLDialect.supportedBy(CLICKHOUSE, TRINO);
|
||||
private static final Set<SQLDialect> ENCODED_TIMESTAMP_PRECISION = SQLDialect.supportedBy(HSQLDB, MARIADB);
|
||||
private static final Set<SQLDialect> NO_SUPPORT_TIMESTAMP_PRECISION = SQLDialect.supportedBy(FIREBIRD, MYSQL, SQLITE);
|
||||
private static final Set<SQLDialect> SUPPORT_POSTGRES_PREFIX_ARRAY_NOTATION = SQLDialect.supportedBy(POSTGRES, YUGABYTEDB);
|
||||
private static final Set<SQLDialect> SUPPORT_POSTGRES_SUFFIX_ARRAY_NOTATION = SQLDialect.supportedBy(DUCKDB, POSTGRES, YUGABYTEDB);
|
||||
private static final Set<SQLDialect> SUPPORT_HSQLDB_ARRAY_NOTATION = SQLDialect.supportedBy(H2, HSQLDB, POSTGRES, YUGABYTEDB);
|
||||
private static final Set<SQLDialect> SUPPORT_TRINO_ARRAY_NOTATION = SQLDialect.supportedBy(CLICKHOUSE, TRINO);
|
||||
|
||||
/**
|
||||
* A pattern for data type name normalisation.
|
||||
*/
|
||||
private static final Pattern P_NORMALISE = Pattern.compile("\"|\\.|\\s|\\(\\w+(\\s*,\\s*\\w+)*\\)|(NOT\\s*NULL)?");
|
||||
private static final Pattern P_NORMALISE = Pattern.compile("\"|\\.|\\s|\\(\\w+(\\s*,\\s*\\w+)*\\)|(NOT\\s*NULL)?");
|
||||
|
||||
/**
|
||||
* A pattern to be used to replace all precision, scale, and length
|
||||
* information.
|
||||
*/
|
||||
private static final Pattern P_TYPE_NAME = Pattern.compile("\\([^)]*\\)");
|
||||
private static final Pattern P_TYPE_NAME = Pattern.compile("\\([^)]*\\)");
|
||||
|
||||
/**
|
||||
* A pattern to be used to extract all precision, scale, and length
|
||||
* information.
|
||||
*/
|
||||
private static final Pattern P_PRECISION_SCALE = Pattern.compile("\\(\\s*(\\d+)(?:\\s*,\\s*(\\d+))?\\s*\\)");
|
||||
private static final Pattern P_PRECISION_SCALE = Pattern.compile("\\(\\s*(\\d+)(?:\\s*,\\s*(\\d+))?\\s*\\)");
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Data type caches
|
||||
@ -712,12 +714,12 @@ public class DefaultDataType<T> extends AbstractDataTypeX<T> {
|
||||
result = TYPES_BY_NAME[SQLDialect.DEFAULT.ordinal()].get("INTEGER");
|
||||
|
||||
// [#4065] PostgreSQL reports array types as _typename, e.g. _varchar
|
||||
else if (arrayCheck && SUPPORT_POSTGRES_ARRAY_NOTATION.contains(dialect) && typeName.charAt(0) == '_')
|
||||
else if (arrayCheck && SUPPORT_POSTGRES_PREFIX_ARRAY_NOTATION.contains(dialect) && typeName.charAt(0) == '_')
|
||||
result = getDataType(dialect, typeName.substring(1)).getArrayDataType();
|
||||
|
||||
// [#8545] CockroachDB is a little different from PostgreSQL. We're reading crdb_sql_type rather
|
||||
// than data_type / udt_name from information_schema.columns
|
||||
else if (arrayCheck && SUPPORT_POSTGRES_ARRAY_NOTATION.contains(dialect) && typeName.endsWith("[]"))
|
||||
else if (arrayCheck && SUPPORT_POSTGRES_SUFFIX_ARRAY_NOTATION.contains(dialect) && typeName.endsWith("[]"))
|
||||
result = getDataType(dialect, typeName.substring(0, typeName.length() - 2)).getArrayDataType();
|
||||
|
||||
// [#6466] HSQLDB reports array types as XYZARRAY. H2 should, too
|
||||
|
||||
Loading…
Reference in New Issue
Block a user