修改问题、添加监管数据报送模块
这个提交包含在:
+10
-1
@@ -28,10 +28,19 @@ public final class UnifiedIngestionApi {
|
||||
public record SourceSelection(long sourceId, long sourceVersion, String sourceName,
|
||||
String sourceDatabase, String table) { }
|
||||
public record DraftRequest(List<SourceSelection> items, StorageResourceType targetType) { }
|
||||
public record FieldCompatibility(String field, String nativeType, String conversion, String error) { }
|
||||
public record DraftItem(long sourceId, long sourceVersion, String sourceName, String sourceDatabase,
|
||||
String sourceTable, String targetTable, String sourceFingerprint,
|
||||
List<ColumnDefinition> columns, List<BatchFieldMappingCommand> mappings,
|
||||
String errorSummary, String sourceTableComment, String sourceTableCommentState) {
|
||||
String errorSummary, String sourceTableComment, String sourceTableCommentState,
|
||||
List<FieldCompatibility> fieldCompatibility) {
|
||||
public DraftItem(long sourceId, long sourceVersion, String sourceName, String sourceDatabase,
|
||||
String sourceTable, String targetTable, String sourceFingerprint,
|
||||
List<ColumnDefinition> columns, List<BatchFieldMappingCommand> mappings, String errorSummary,
|
||||
String sourceTableComment, String sourceTableCommentState) {
|
||||
this(sourceId, sourceVersion, sourceName, sourceDatabase, sourceTable, targetTable, sourceFingerprint,
|
||||
columns, mappings, errorSummary, sourceTableComment, sourceTableCommentState, List.of());
|
||||
}
|
||||
public DraftItem(long sourceId, long sourceVersion, String sourceName, String sourceDatabase,
|
||||
String sourceTable, String targetTable, String sourceFingerprint,
|
||||
List<ColumnDefinition> columns, List<BatchFieldMappingCommand> mappings, String errorSummary) {
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package cn.aixunkeji.datagov.integration.api.datasource;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import static cn.aixunkeji.datagov.integration.api.datasource.DataSourceObjects.*;
|
||||
|
||||
/** Explicit value-preserving carriers for types without a common Hive/Doris scalar type.
|
||||
* Native metadata is retained in the execution snapshot; this never casts to a bounded string.
|
||||
*/
|
||||
public final class BatchTextTypes {
|
||||
private BatchTextTypes() { }
|
||||
public record Carrier(String expression, boolean binary, String description) { }
|
||||
|
||||
public static Carrier carrier(Column c, String identifier) {
|
||||
if (c == null) return null;
|
||||
String raw = c.nativeType() == null ? c.type() : c.nativeType();
|
||||
if (raw == null) return null;
|
||||
raw = raw.toUpperCase(Locale.ROOT).trim();
|
||||
String dialect = raw.contains(":") ? raw.substring(0, raw.indexOf(':')) : "MYSQL";
|
||||
String type = raw.contains(":") ? raw.substring(raw.indexOf(':') + 1) : raw;
|
||||
String base = type.replaceAll("\\([^)]*\\)", "").replace(" UNSIGNED", "").trim().replaceAll("\\s+", " ");
|
||||
String x = identifier;
|
||||
if (dialect.equals("MYSQL")) {
|
||||
if (Set.of("TINYTEXT", "TEXT", "MEDIUMTEXT", "LONGTEXT", "STRING").contains(base)) return text(x, "文本完整保存");
|
||||
if (Set.of("BINARY", "VARBINARY", "TINYBLOB", "BLOB", "MEDIUMBLOB", "LONGBLOB").contains(base)) return text("HEX("+x+")", "二进制保存为十六进制,可逆还原");
|
||||
if (Set.of("GEOMETRY", "POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION", "GEOMCOLLECTION").contains(base))
|
||||
return text("HEX("+x+")", "空间数据保存为含SRID的MySQL内部二进制十六进制");
|
||||
if (Set.of("JSON", "ENUM", "SET", "TIME").contains(base) || wideDecimal(base,c,type))
|
||||
return text("CAST("+x+" AS CHAR CHARACTER SET utf8mb4)", "原始值以文本保存,不保留源类型约束");
|
||||
if (base.equals("BIT") && !Integer.valueOf(1).equals(dimension(c,type)))
|
||||
return text("CAST(CAST("+x+" AS UNSIGNED) AS CHAR)", "位值保存为无符号十进制文本,位宽保留在源结构");
|
||||
} else if (dialect.equals("SQLSERVER")) {
|
||||
if (Set.of("TEXT", "NTEXT", "XML").contains(base) ||
|
||||
Set.of("VARCHAR", "NVARCHAR").contains(base) && (type.contains("MAX") || c.precision()!=null && c.precision()>65535))
|
||||
return text("CONVERT(nvarchar(max),"+x+")", "文本/XML完整保存");
|
||||
if (base.equals("IMAGE") || base.equals("VARBINARY") && (type.contains("MAX") || c.precision()==null || c.precision()>8000))
|
||||
return text("CONVERT(varchar(max),"+x+",2)", "二进制保存为十六进制,可逆还原");
|
||||
if (Set.of("GEOMETRY", "GEOGRAPHY").contains(base))
|
||||
return text("CONVERT(varchar(max),"+x+".Serialize(),2)", "空间对象完整序列化为十六进制(含SRID)");
|
||||
if (base.equals("HIERARCHYID")) return text(x+".ToString()", "层级路径保存为文本");
|
||||
} else if (dialect.equals("ORACLE") || dialect.equals("DAMENG")) {
|
||||
if (Set.of("CLOB", "NCLOB", "TEXT", "LONG", "LONGVARCHAR").contains(base)) return text(x, "大文本完整保存");
|
||||
if (Set.of("BLOB", "LONG RAW", "LONGVARBINARY").contains(base)) return binary(x);
|
||||
if (dialect.equals("ORACLE") && base.equals("RAW")) return text("RAWTOHEX("+x+")", "二进制保存为十六进制,可逆还原");
|
||||
if (dialect.equals("DAMENG") && Set.of("BINARY", "VARBINARY", "RAW").contains(base) &&
|
||||
(c.precision()==null || c.precision()>16383)) return binary(x);
|
||||
if (Set.of("NUMBER", "NUMERIC", "DECIMAL").contains(base) &&
|
||||
(c.precision()==null || c.precision()<1 || c.precision()>38 || c.scale()==null || c.scale()<0 || c.scale()>c.precision()))
|
||||
return text("TO_CHAR("+x+",'TM9','NLS_NUMERIC_CHARACTERS=''.,''')", "数值保存为完整精度文本");
|
||||
if (base.startsWith("TIMESTAMP") && (base.contains("TIME ZONE") || c.scale()==null || c.scale()>6)) {
|
||||
String format = "YYYY-MM-DD\"T\"HH24:MI:SS.FF9"+(base.contains("TIME ZONE") ? " TZH:TZM" : "");
|
||||
return text("TO_CHAR("+x+",'"+format+"')", "时间保存为含小数秒/时区的文本");
|
||||
}
|
||||
if (base.startsWith("INTERVAL")) return text("TO_CHAR("+x+")", "时间间隔保存为文本");
|
||||
if (Set.of("ROWID", "UROWID").contains(base)) return text("TO_CHAR("+x+")", "行标识保存为文本");
|
||||
if (base.equals("XMLTYPE")) return text("XMLSERIALIZE(CONTENT "+x+" AS CLOB)", "XML完整保存");
|
||||
if (base.equals("JSON")) return text("JSON_SERIALIZE("+x+" RETURNING CLOB)", "JSON完整保存为文本");
|
||||
if (dialect.equals("DAMENG") && base.equals("DATE")) return text("TO_CHAR("+x+",'YYYY-MM-DD HH24:MI:SS')", "日期时间保存为文本,保留兼容模式下的时分秒");
|
||||
if (dialect.equals("DAMENG") && (base.equals("TIME") || base.startsWith("TIME "))) return text("CAST("+x+" AS VARCHAR(64))", "时间保存为完整精度文本");
|
||||
} else if (dialect.equals("KINGBASE")) {
|
||||
if (Set.of("VARCHAR", "CHARACTER VARYING", "CHAR", "BPCHAR").contains(base) &&
|
||||
(c.precision()==null || c.precision()<1 || c.precision()>65535))
|
||||
return text("CAST("+x+" AS TEXT)", "无界或大容量字符字段完整保存为文本");
|
||||
if (Set.of("BYTEA", "BLOB", "RAW", "BINARY", "VARBINARY").contains(base)) return binary(x);
|
||||
if (Set.of("TEXT", "CLOB", "NCLOB", "JSON", "JSONB", "XML", "UUID", "BOOL", "BOOLEAN", "REAL", "FLOAT4", "FLOAT8", "DOUBLE PRECISION", "FLOAT", "TIMESTAMP", "TIMESTAMPTZ", "TIMESTAMP WITHOUT TIME ZONE", "TIMESTAMP WITH TIME ZONE", "TIME", "TIMETZ", "TIME WITHOUT TIME ZONE", "TIME WITH TIME ZONE", "INTERVAL", "MONEY", "INET", "CIDR", "MACADDR", "MACADDR8", "BIT", "VARBIT", "BIT VARYING", "POINT", "LINE", "LSEG", "BOX", "PATH", "POLYGON", "CIRCLE", "TSVECTOR", "TSQUERY", "INT4RANGE", "INT8RANGE", "NUMRANGE", "TSRANGE", "TSTZRANGE", "DATERANGE").contains(base) ||
|
||||
base.startsWith("_") || base.endsWith("[]") ||
|
||||
Set.of("NUMERIC", "DECIMAL", "NUMBER").contains(base) && (c.precision()==null || c.precision()<1 || c.precision()>38 || c.scale()==null || c.scale()<0 || c.scale()>c.precision()))
|
||||
return text("CAST("+x+" AS TEXT)", "使用数据库完整文本表示,保留值及精度");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Integer dimension(Column c, String type) {
|
||||
var m=java.util.regex.Pattern.compile("^[A-Z]+\\(([0-9]+)").matcher(type);
|
||||
return m.find() ? Integer.valueOf(m.group(1)) : c.precision();
|
||||
}
|
||||
private static boolean wideDecimal(String base, Column c, String type) {
|
||||
if (!Set.of("DECIMAL", "NUMERIC").contains(base)) return false;
|
||||
Integer p=dimension(c,type);
|
||||
return p!=null && p>38 && p<=65;
|
||||
}
|
||||
private static Carrier text(String expression, String description) { return new Carrier(expression,false,description); }
|
||||
private static Carrier binary(String expression) { return new Carrier(expression,true,"二进制通过采集引擎完整编码为十六进制,可逆还原"); }
|
||||
public static MysqlTargetType mapping(Column c, TargetEngine engine) {
|
||||
Carrier carrier=carrier(c,"field");
|
||||
return carrier==null ? null : new MysqlTargetType(c.name(),c.nativeType()==null?c.type():c.nativeType(),engine,true,"STRING","string",null,null);
|
||||
}
|
||||
}
|
||||
+4
@@ -97,6 +97,10 @@ public final class DataSourceObjects {
|
||||
String errorCode, String errorSummary) implements java.io.Serializable { }
|
||||
|
||||
public static MysqlTargetType mysqlTargetType(Column column, TargetEngine engine) {
|
||||
if (column != null && engine != null && column.name() != null && !column.name().isBlank()) {
|
||||
MysqlTargetType text = BatchTextTypes.mapping(column, engine);
|
||||
if (text != null) return text;
|
||||
}
|
||||
if (column != null && engine != null && column.nativeType() != null &&
|
||||
column.nativeType().startsWith(KingbaseBatchTypes.PREFIX)) {
|
||||
return KingbaseBatchTypes.targetType(column, engine);
|
||||
|
||||
在新工单中引用
屏蔽一个用户