From fe30cb3fa25c936c7f1801b884c0099f2b255052 Mon Sep 17 00:00:00 2001 From: mozhenghua Date: Mon, 5 Sep 2022 18:00:36 +0800 Subject: [PATCH] intend to remove BasicTISSinkFactory.DTOSinkFunc --- .../plugin/writer/hdfswriter/HdfsColMeta.java | 13 ++++++- .../com/qlangtech/tis/plugin/ds/ColMeta.java | 34 +++++++++++++++++++ .../com/qlangtech/tis/plugin/ds/DataType.java | 21 ++++++++---- .../tis/plugin/ds/IColMetaGetter.java | 26 ++++++++++++++ 4 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 datax-config/src/main/java/com/qlangtech/tis/plugin/ds/ColMeta.java create mode 100644 datax-config/src/main/java/com/qlangtech/tis/plugin/ds/IColMetaGetter.java diff --git a/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/HdfsColMeta.java b/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/HdfsColMeta.java index 339c216e37..ee34ff421c 100644 --- a/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/HdfsColMeta.java +++ b/datax-config/src/main/java/com/alibaba/datax/plugin/writer/hdfswriter/HdfsColMeta.java @@ -2,6 +2,7 @@ import com.alibaba.datax.common.util.Configuration; import com.qlangtech.tis.plugin.ds.DataType; +import com.qlangtech.tis.plugin.ds.IColMetaGetter; import java.io.Serializable; import java.util.ArrayList; @@ -12,7 +13,7 @@ * @author: 百岁(baisui@qlangtech.com) * @create: 2022-02-18 15:47 **/ -public class HdfsColMeta implements Serializable { +public class HdfsColMeta implements Serializable, IColMetaGetter { public static final String KEY_COLUMN = "column"; public static final String KEY_NAME = "name"; @@ -50,6 +51,16 @@ public HdfsColMeta(String colName, Boolean nullable, Boolean pk, DataType dataTy this.pk = pk; } + @Override + public boolean isPk() { + return this.pk; + } + + @Override + public DataType getType() { + return this.type; + } + public String getName() { return this.colName; } diff --git a/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/ColMeta.java b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/ColMeta.java new file mode 100644 index 0000000000..fe697fa625 --- /dev/null +++ b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/ColMeta.java @@ -0,0 +1,34 @@ +package com.qlangtech.tis.plugin.ds; + +import java.io.Serializable; + +/** + * @author: 百岁(baisui@qlangtech.com) + * @create: 2022-08-25 17:45 + **/ +public class ColMeta implements IColMetaGetter, Serializable { + public final String name; + public final DataType type; + public final boolean pk; + + public ColMeta(String name, DataType type, boolean pk) { + this.name = name; + this.type = type; + this.pk = pk; + } + + @Override + public boolean isPk() { + return this.pk; + } + + @Override + public String getName() { + return name; + } + + @Override + public DataType getType() { + return type; + } +} 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 fa67814446..d43770e64a 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,7 +36,7 @@ public class DataType implements Serializable { public final int type; public final int columnSize; - private final String typeName; + public final String typeName; // decimal 的小数位长度 private Integer decimalDigits; @@ -46,8 +46,9 @@ public DataType(int type) { } /** - * @param type java.sql.Types + * @param type * @param columnSize + * @see java.sql.Types */ public DataType(int type, String typeName, int columnSize) { this.type = type; @@ -71,7 +72,9 @@ public DataXReaderColType getCollapse() { return DataXReaderColType.Long; case Types.FLOAT: case Types.DOUBLE: + case Types.REAL: case Types.DECIMAL: + case Types.NUMERIC: return DataXReaderColType.Double; case Types.DATE: case Types.TIME: @@ -93,11 +96,7 @@ public DataXReaderColType getCollapse() { public T accept(TypeVisitor visitor) { switch (this.type) { case Types.INTEGER: { - if (this.isUnsigned()) { - return visitor.bigInt(this); - } else { - return visitor.intType(this); - } + return visitor.intType(this); } case Types.TINYINT: return visitor.tinyIntType(this); @@ -106,10 +105,12 @@ public T accept(TypeVisitor visitor) { case Types.BIGINT: return visitor.bigInt(this); case Types.FLOAT: + case Types.REAL: return visitor.floatType(this); case Types.DOUBLE: return visitor.doubleType(this); case Types.DECIMAL: + case Types.NUMERIC: return visitor.decimalType(this); case Types.DATE: return visitor.dateType(this); @@ -118,6 +119,7 @@ public T accept(TypeVisitor visitor) { case Types.TIMESTAMP: return visitor.timestampType(this); case Types.BIT: + return visitor.boolType(this); case Types.BOOLEAN: return visitor.bitType(this); case Types.BLOB: @@ -244,6 +246,7 @@ public static DataType ds(String ser) { public String toString() { return "{" + "type=" + type + + ",typeName=" + this.typeName + ", columnSize=" + columnSize + ", decimalDigits=" + decimalDigits + '}'; @@ -287,5 +290,9 @@ default T tinyIntType(DataType dataType) { default T smallIntType(DataType dataType) { return intType(dataType); } + + default T boolType(DataType dataType) { + return bitType(dataType); + } } } diff --git a/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/IColMetaGetter.java b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/IColMetaGetter.java new file mode 100644 index 0000000000..d4bda8e6dd --- /dev/null +++ b/datax-config/src/main/java/com/qlangtech/tis/plugin/ds/IColMetaGetter.java @@ -0,0 +1,26 @@ +package com.qlangtech.tis.plugin.ds; + +import java.io.Serializable; + +/** + * @author: 百岁(baisui@qlangtech.com) + * @create: 2022-08-25 21:05 + **/ +public interface IColMetaGetter { + + public static IColMetaGetter create(String name, DataType type) { + return create(name, type, false); + } + + public static IColMetaGetter create(String name, DataType type, boolean pk) { + return new ColMeta(name, type, pk); + } + + public String getName(); + + public DataType getType(); + + public boolean isPk(); + + +}