From bb79c34c75b051e7826c9c3eb397ab8ab1b0e3d1 Mon Sep 17 00:00:00 2001 From: mozhenghua Date: Sat, 16 Jul 2022 11:43:54 +0800 Subject: [PATCH] add unsinged int process --- .../hdfswriter/SupportHiveDataType.java | 2 - .../com/qlangtech/tis/plugin/ds/DataType.java | 40 +++++++++++++------ .../tis/plugin/ds/DataXReaderColType.java | 3 +- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/SupportHiveDataType.java b/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/SupportHiveDataType.java index 815b143089..5f5282bebc 100644 --- a/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/SupportHiveDataType.java +++ b/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/SupportHiveDataType.java @@ -1,7 +1,5 @@ package com.alibaba.datax.plugin.writer.hdfswriter; -import java.util.Objects; - public enum SupportHiveDataType { TINYINT, diff --git a/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataType.java b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataType.java index 3647b7013d..fa67814446 100644 --- a/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataType.java +++ b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataType.java @@ -36,11 +36,30 @@ public class DataType implements Serializable { public final int type; public final int columnSize; + private final String typeName; // decimal 的小数位长度 private Integer decimalDigits; + public DataType(int type) { - this(type, -1); + this(type, StringUtils.EMPTY, -1); + } + + /** + * @param type java.sql.Types + * @param columnSize + */ + public DataType(int type, String typeName, int columnSize) { + this.type = type; + this.columnSize = columnSize; + this.typeName = typeName; + } + + /** + * is UNSIGNED + */ + public boolean isUnsigned() { + return StringUtils.containsIgnoreCase(this.typeName, "UNSIGNED"); } public DataXReaderColType getCollapse() { @@ -73,8 +92,13 @@ public DataXReaderColType getCollapse() { public T accept(TypeVisitor visitor) { switch (this.type) { - case Types.INTEGER: - return visitor.intType(this); + case Types.INTEGER: { + if (this.isUnsigned()) { + return visitor.bigInt(this); + } else { + return visitor.intType(this); + } + } case Types.TINYINT: return visitor.tinyIntType(this); case Types.SMALLINT: @@ -190,14 +214,6 @@ public void setDecimalDigits(Integer decimalDigits) { this.decimalDigits = decimalDigits; } - /** - * @param type java.sql.Types - * @param columnSize - */ - public DataType(int type, int columnSize) { - this.type = type; - this.columnSize = columnSize; - } public String getS() { return this.type + "," + this.columnSize @@ -216,7 +232,7 @@ public static DataType ds(String ser) { if (!matcher.matches()) { throw new IllegalStateException("val is illegal:" + ser); } - DataType type = new DataType(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2))); + DataType type = new DataType(Integer.parseInt(matcher.group(1)), StringUtils.EMPTY, Integer.parseInt(matcher.group(2))); String d = matcher.group(3); if (StringUtils.isNotEmpty(d)) { type.decimalDigits = Integer.parseInt(d); diff --git a/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataXReaderColType.java b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataXReaderColType.java index 0dbe20d58c..1c847e3220 100644 --- a/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataXReaderColType.java +++ b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/DataXReaderColType.java @@ -8,6 +8,7 @@ /** * https://github.com/alibaba/DataX/blob/master/mysqlreader/doc/mysqlreader.md#33-%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2 + * * @author: 百岁(baisui@qlangtech.com) * @create: 2022-02-19 09:12 **/ @@ -15,7 +16,7 @@ public enum DataXReaderColType { Long("long", new DataType(Types.BIGINT)), INT("int", new DataType(Types.INTEGER)), Double("double", new DataType(Types.DOUBLE)), - STRING("string", new DataType(Types.VARCHAR, 256)), + STRING("string", new DataType(Types.VARCHAR, "VARCHAR", 256)), Boolean("boolean", new DataType(Types.BOOLEAN)), Date("date", new DataType(Types.DATE)), Bytes("bytes", new DataType(Types.BLOB));