Skip to content

Commit

Permalink
add unsinged int process
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Jul 16, 2022
1 parent 73fbd74 commit bb79c34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.alibaba.datax.plugin.writer.hdfswriter;

import java.util.Objects;

public enum SupportHiveDataType {

TINYINT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -73,8 +92,13 @@ public DataXReaderColType getCollapse() {

public <T> T accept(TypeVisitor<T> 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:
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@

/**
* 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: 百岁([email protected]
* @create: 2022-02-19 09:12
**/
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));
Expand Down

0 comments on commit bb79c34

Please sign in to comment.