Unverified Commit 8efccada authored by aiwenmo's avatar aiwenmo Committed by GitHub

[Fix-803] [Client] Fix TypeConvert-ColumnType Enumeration usage error (#878)

Co-authored-by: 's avatarwenmo <32723967+wenmo@users.noreply.github.com>
parent 28034d48
...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder { ...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder {
protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) { protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) {
for (Column column : columns) { for (Column column : columns) {
columnNameList.add(column.getName()); columnNameList.add(column.getName());
columnTypeList.add(getLogicalType(column.getJavaType())); columnTypeList.add(getLogicalType(column));
} }
} }
public LogicalType getLogicalType(ColumnType columnType) { public LogicalType getLogicalType(Column column) {
switch (columnType) { switch (column.getJavaType()) {
case STRING: case STRING:
return new VarCharType(); return new VarCharType();
case BOOLEAN: case BOOLEAN:
...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder { ...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder {
case JAVA_LANG_DOUBLE: case JAVA_LANG_DOUBLE:
return new DoubleType(); return new DoubleType();
case DECIMAL: case DECIMAL:
if (columnType.getPrecision() == null || columnType.getPrecision() == 0) { if (column.getPrecision() == null || column.getPrecision() == 0) {
return new DecimalType(38, columnType.getScale()); return new DecimalType(38, column.getScale());
} else { } else {
return new DecimalType(columnType.getPrecision(), columnType.getScale()); return new DecimalType(column.getPrecision(), column.getScale());
} }
case INT: case INT:
case INTEGER: case INTEGER:
......
...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder { ...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder {
protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) { protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) {
for (Column column : columns) { for (Column column : columns) {
columnNameList.add(column.getName()); columnNameList.add(column.getName());
columnTypeList.add(getLogicalType(column.getJavaType())); columnTypeList.add(getLogicalType(column));
} }
} }
public LogicalType getLogicalType(ColumnType columnType) { public LogicalType getLogicalType(Column column) {
switch (columnType) { switch (column.getJavaType()) {
case STRING: case STRING:
return new VarCharType(); return new VarCharType();
case BOOLEAN: case BOOLEAN:
...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder { ...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder {
case JAVA_LANG_DOUBLE: case JAVA_LANG_DOUBLE:
return new DoubleType(); return new DoubleType();
case DECIMAL: case DECIMAL:
if (columnType.getPrecision() == null || columnType.getPrecision() == 0) { if (column.getPrecision() == null || column.getPrecision() == 0) {
return new DecimalType(38, columnType.getScale()); return new DecimalType(38, column.getScale());
} else { } else {
return new DecimalType(columnType.getPrecision(), columnType.getScale()); return new DecimalType(column.getPrecision(), column.getScale());
} }
case INT: case INT:
case INTEGER: case INTEGER:
......
...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder { ...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder {
protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) { protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) {
for (Column column : columns) { for (Column column : columns) {
columnNameList.add(column.getName()); columnNameList.add(column.getName());
columnTypeList.add(getLogicalType(column.getJavaType())); columnTypeList.add(getLogicalType(column));
} }
} }
public LogicalType getLogicalType(ColumnType columnType) { public LogicalType getLogicalType(Column column) {
switch (columnType) { switch (column.getJavaType()) {
case STRING: case STRING:
return new VarCharType(); return new VarCharType();
case BOOLEAN: case BOOLEAN:
...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder { ...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder {
case JAVA_LANG_DOUBLE: case JAVA_LANG_DOUBLE:
return new DoubleType(); return new DoubleType();
case DECIMAL: case DECIMAL:
if (columnType.getPrecision() == null || columnType.getPrecision() == 0) { if (column.getPrecision() == null || column.getPrecision() == 0) {
return new DecimalType(38, columnType.getScale()); return new DecimalType(38, column.getScale());
} else { } else {
return new DecimalType(columnType.getPrecision(), columnType.getScale()); return new DecimalType(column.getPrecision(), column.getScale());
} }
case INT: case INT:
case INTEGER: case INTEGER:
......
...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder { ...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder {
protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) { protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) {
for (Column column : columns) { for (Column column : columns) {
columnNameList.add(column.getName()); columnNameList.add(column.getName());
columnTypeList.add(getLogicalType(column.getJavaType())); columnTypeList.add(getLogicalType(column));
} }
} }
public LogicalType getLogicalType(ColumnType columnType) { public LogicalType getLogicalType(Column column) {
switch (columnType) { switch (column.getJavaType()) {
case STRING: case STRING:
return new VarCharType(); return new VarCharType();
case BOOLEAN: case BOOLEAN:
...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder { ...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder {
case JAVA_LANG_DOUBLE: case JAVA_LANG_DOUBLE:
return new DoubleType(); return new DoubleType();
case DECIMAL: case DECIMAL:
if (columnType.getPrecision() == null || columnType.getPrecision() == 0) { if (column.getPrecision() == null || column.getPrecision() == 0) {
return new DecimalType(38, columnType.getScale()); return new DecimalType(38, column.getScale());
} else { } else {
return new DecimalType(columnType.getPrecision(), columnType.getScale()); return new DecimalType(column.getPrecision(), column.getScale());
} }
case INT: case INT:
case INTEGER: case INTEGER:
......
...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder { ...@@ -212,12 +212,12 @@ public abstract class AbstractSinkBuilder {
protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) { protected void buildColumn(List<String> columnNameList, List<LogicalType> columnTypeList, List<Column> columns) {
for (Column column : columns) { for (Column column : columns) {
columnNameList.add(column.getName()); columnNameList.add(column.getName());
columnTypeList.add(getLogicalType(column.getJavaType())); columnTypeList.add(getLogicalType(column));
} }
} }
public LogicalType getLogicalType(ColumnType columnType) { public LogicalType getLogicalType(Column column) {
switch (columnType) { switch (column.getJavaType()) {
case STRING: case STRING:
return new VarCharType(); return new VarCharType();
case BOOLEAN: case BOOLEAN:
...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder { ...@@ -239,10 +239,10 @@ public abstract class AbstractSinkBuilder {
case JAVA_LANG_DOUBLE: case JAVA_LANG_DOUBLE:
return new DoubleType(); return new DoubleType();
case DECIMAL: case DECIMAL:
if (columnType.getPrecision() == null || columnType.getPrecision() == 0) { if (column.getPrecision() == null || column.getPrecision() == 0) {
return new DecimalType(38, columnType.getScale()); return new DecimalType(38, column.getScale());
} else { } else {
return new DecimalType(columnType.getPrecision(), columnType.getScale()); return new DecimalType(column.getPrecision(), column.getScale());
} }
case INT: case INT:
case INTEGER: case INTEGER:
......
...@@ -75,7 +75,7 @@ public class FlinkBaseUtil { ...@@ -75,7 +75,7 @@ public class FlinkBaseUtil {
sb.append("` (\n"); sb.append("` (\n");
List<String> pks = new ArrayList<>(); List<String> pks = new ArrayList<>();
for (int i = 0; i < table.getColumns().size(); i++) { for (int i = 0; i < table.getColumns().size(); i++) {
String type = table.getColumns().get(i).getJavaType().getFlinkType(); String type = table.getColumns().get(i).getFlinkType();
sb.append(" "); sb.append(" ");
if (i > 0) { if (i > 0) {
sb.append(","); sb.append(",");
......
...@@ -52,4 +52,16 @@ public class Column implements Serializable { ...@@ -52,4 +52,16 @@ public class Column implements Serializable {
private String characterSet; private String characterSet;
private String collation; private String collation;
public String getFlinkType() {
String flinkType = javaType.getFlinkType();
if (flinkType.equals("DECIMAL")) {
if (precision == null || precision == 0) {
return flinkType + "(" + 38 + "," + scale + ")";
} else {
return flinkType + "(" + precision + "," + scale + ")";
}
} else {
return flinkType;
}
}
} }
...@@ -60,49 +60,17 @@ public enum ColumnType { ...@@ -60,49 +60,17 @@ public enum ColumnType {
private String javaType; private String javaType;
private String flinkType; private String flinkType;
private Integer precision;
private Integer scale;
ColumnType(String javaType, String flinkType) { ColumnType(String javaType, String flinkType) {
this.javaType = javaType; this.javaType = javaType;
this.flinkType = flinkType; this.flinkType = flinkType;
} }
public ColumnType setPrecisionAndScale(Integer precision, Integer scale) {
this.precision = precision;
this.scale = scale;
return this;
}
public String getJavaType() { public String getJavaType() {
return javaType; return javaType;
} }
public String getFlinkType() { public String getFlinkType() {
if (flinkType.equals("DECIMAL")) { return flinkType;
if (precision == null || precision == 0) {
return flinkType + "(" + 38 + "," + scale + ")";
} else {
return flinkType + "(" + precision + "," + scale + ")";
}
} else {
return flinkType;
}
}
public Integer getPrecision() {
return precision;
}
public void setPrecision(Integer precision) {
this.precision = precision;
}
public Integer getScale() {
return scale;
}
public void setScala(Integer scale) {
this.scale = scale;
} }
} }
...@@ -107,7 +107,7 @@ public class Table implements Serializable, Comparable<Table> { ...@@ -107,7 +107,7 @@ public class Table implements Serializable, Comparable<Table> {
sb.append("CREATE TABLE IF NOT EXISTS " + tableName + " (\n"); sb.append("CREATE TABLE IF NOT EXISTS " + tableName + " (\n");
List<String> pks = new ArrayList<>(); List<String> pks = new ArrayList<>();
for (int i = 0; i < columns.size(); i++) { for (int i = 0; i < columns.size(); i++) {
String type = columns.get(i).getJavaType().getFlinkType(); String type = columns.get(i).getFlinkType();
sb.append(" "); sb.append(" ");
if (i > 0) { if (i > 0) {
sb.append(","); sb.append(",");
...@@ -158,7 +158,7 @@ public class Table implements Serializable, Comparable<Table> { ...@@ -158,7 +158,7 @@ public class Table implements Serializable, Comparable<Table> {
sb.append("CREATE TABLE IF NOT EXISTS " + name + " (\n"); sb.append("CREATE TABLE IF NOT EXISTS " + name + " (\n");
List<String> pks = new ArrayList<>(); List<String> pks = new ArrayList<>();
for (int i = 0; i < columns.size(); i++) { for (int i = 0; i < columns.size(); i++) {
String type = columns.get(i).getJavaType().getFlinkType(); String type = columns.get(i).getFlinkType();
sb.append(" "); sb.append(" ");
if (i > 0) { if (i > 0) {
sb.append(","); sb.append(",");
......
...@@ -92,7 +92,6 @@ public class ClickHouseTypeConvert implements ITypeConvert { ...@@ -92,7 +92,6 @@ public class ClickHouseTypeConvert implements ITypeConvert {
columnType = ColumnType.INT; columnType = ColumnType.INT;
} }
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -92,7 +92,6 @@ public class DorisTypeConvert implements ITypeConvert { ...@@ -92,7 +92,6 @@ public class DorisTypeConvert implements ITypeConvert {
columnType = ColumnType.DOUBLE; columnType = ColumnType.DOUBLE;
} }
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -94,7 +94,6 @@ public class HiveTypeConvert implements ITypeConvert { ...@@ -94,7 +94,6 @@ public class HiveTypeConvert implements ITypeConvert {
columnType = ColumnType.DOUBLE; columnType = ColumnType.DOUBLE;
} }
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -84,7 +84,6 @@ public class MySqlTypeConvert implements ITypeConvert { ...@@ -84,7 +84,6 @@ public class MySqlTypeConvert implements ITypeConvert {
columnType = ColumnType.INT; columnType = ColumnType.INT;
} }
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -72,7 +72,6 @@ public class OracleTypeConvert implements ITypeConvert { ...@@ -72,7 +72,6 @@ public class OracleTypeConvert implements ITypeConvert {
} else if (t.contains("blob")) { } else if (t.contains("blob")) {
columnType = ColumnType.BYTES; columnType = ColumnType.BYTES;
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -79,7 +79,6 @@ public class PhoenixTypeConvert implements ITypeConvert { ...@@ -79,7 +79,6 @@ public class PhoenixTypeConvert implements ITypeConvert {
} else if (t.contains("date")) { } else if (t.contains("date")) {
columnType = ColumnType.DATE; columnType = ColumnType.DATE;
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -90,7 +90,6 @@ public class PostgreSqlTypeConvert implements ITypeConvert { ...@@ -90,7 +90,6 @@ public class PostgreSqlTypeConvert implements ITypeConvert {
} else if (t.contains("array")) { } else if (t.contains("array")) {
columnType = ColumnType.T; columnType = ColumnType.T;
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
...@@ -80,7 +80,6 @@ public class SqlServerTypeConvert implements ITypeConvert { ...@@ -80,7 +80,6 @@ public class SqlServerTypeConvert implements ITypeConvert {
} else if (t.contains("timestamp") || t.contains("binary") || t.contains("varbinary") || t.contains("image")) { } else if (t.contains("timestamp") || t.contains("binary") || t.contains("varbinary") || t.contains("image")) {
columnType = ColumnType.BYTES; columnType = ColumnType.BYTES;
} }
columnType.setPrecisionAndScale(column.getPrecision(), column.getScale());
return columnType; return columnType;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment