in seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/phoenix/PhoenixTypeConverter.java [170:374]
public BasicTypeDefine reconvert(Column column) {
BasicTypeDefine.BasicTypeDefineBuilder builder =
BasicTypeDefine.builder()
.name(column.getName())
.nullable(column.isNullable())
.comment(column.getComment())
.defaultValue(column.getDefaultValue());
switch (column.getDataType().getSqlType()) {
case BOOLEAN:
builder.columnType(PHOENIX_BOOLEAN);
builder.dataType(PHOENIX_BOOLEAN);
break;
case TINYINT:
builder.columnType(PHOENIX_TINYINT);
builder.dataType(PHOENIX_TINYINT);
case SMALLINT:
builder.columnType(PHOENIX_SMALLINT);
builder.dataType(PHOENIX_SMALLINT);
break;
case INT:
builder.columnType(PHOENIX_INTEGER);
builder.dataType(PHOENIX_INTEGER);
break;
case BIGINT:
builder.columnType(PHOENIX_BIGINT);
builder.dataType(PHOENIX_BIGINT);
break;
case FLOAT:
builder.columnType(PHOENIX_FLOAT);
builder.dataType(PHOENIX_FLOAT);
break;
case DOUBLE:
builder.columnType(PHOENIX_DOUBLE);
builder.dataType(PHOENIX_DOUBLE);
break;
case DECIMAL:
DecimalType decimalType = (DecimalType) column.getDataType();
long precision = decimalType.getPrecision();
int scale = decimalType.getScale();
if (precision <= 0) {
precision = DEFAULT_PRECISION;
scale = DEFAULT_SCALE;
log.warn(
"The decimal column {} type decimal({},{}) is out of range, "
+ "which is precision less than 0, "
+ "it will be converted to decimal({},{})",
column.getName(),
decimalType.getPrecision(),
decimalType.getScale(),
precision,
scale);
} else if (precision > MAX_PRECISION) {
scale = (int) Math.max(0, scale - (precision - MAX_PRECISION));
precision = MAX_PRECISION;
log.warn(
"The decimal column {} type decimal({},{}) is out of range, "
+ "which exceeds the maximum precision of {}, "
+ "it will be converted to decimal({},{})",
column.getName(),
decimalType.getPrecision(),
decimalType.getScale(),
MAX_PRECISION,
precision,
scale);
}
if (scale < 0) {
scale = 0;
log.warn(
"The decimal column {} type decimal({},{}) is out of range, "
+ "which is scale less than 0, "
+ "it will be converted to decimal({},{})",
column.getName(),
decimalType.getPrecision(),
decimalType.getScale(),
precision,
scale);
} else if (scale > MAX_SCALE) {
scale = MAX_SCALE;
log.warn(
"The decimal column {} type decimal({},{}) is out of range, "
+ "which exceeds the maximum scale of {}, "
+ "it will be converted to decimal({},{})",
column.getName(),
decimalType.getPrecision(),
decimalType.getScale(),
MAX_SCALE,
precision,
scale);
}
builder.columnType(String.format("%s(%s,%s)", PHOENIX_DECIMAL, precision, scale));
builder.dataType(PHOENIX_DECIMAL);
builder.precision(precision);
builder.scale(scale);
break;
case BYTES:
builder.columnType(PHOENIX_BINARY);
builder.dataType(PHOENIX_BINARY);
break;
case STRING:
if (column.getColumnLength() == null || column.getColumnLength() <= 0) {
builder.columnType(String.format("%s", PHOENIX_VARCHAR));
} else if (column.getColumnLength() <= Integer.MAX_VALUE) {
builder.columnType(
String.format("%s(%s)", PHOENIX_VARCHAR, column.getColumnLength()));
} else if (column.getColumnLength() > Integer.MAX_VALUE) {
builder.columnType(String.format("%s(%s)", PHOENIX_VARCHAR, Integer.MAX_VALUE));
}
builder.dataType(PHOENIX_VARCHAR);
break;
case DATE:
builder.columnType(PHOENIX_DATE);
builder.dataType(PHOENIX_DATE);
break;
case TIME:
Integer timeScale = column.getScale();
if (timeScale != null && timeScale > MAX_TIME_SCALE) {
timeScale = MAX_TIME_SCALE;
log.warn(
"The time column {} type time({}) is out of range, "
+ "which exceeds the maximum scale of {}, "
+ "it will be converted to time({})",
column.getName(),
column.getScale(),
MAX_SCALE,
timeScale);
}
if (timeScale != null && timeScale > 0) {
builder.columnType(String.format("%s(%s)", PHOENIX_TIME, timeScale));
} else {
builder.columnType(PHOENIX_TIME);
}
builder.dataType(PHOENIX_TIME);
builder.scale(timeScale);
break;
case TIMESTAMP:
Integer timestampScale = column.getScale();
if (timestampScale != null && timestampScale > MAX_TIMESTAMP_SCALE) {
timestampScale = MAX_TIMESTAMP_SCALE;
log.warn(
"The timestamp column {} type timestamp({}) is out of range, "
+ "which exceeds the maximum scale of {}, "
+ "it will be converted to timestamp({})",
column.getName(),
column.getScale(),
MAX_TIMESTAMP_SCALE,
timestampScale);
}
if (timestampScale != null && timestampScale > 0) {
builder.columnType(String.format("%s(%s)", PHOENIX_TIMESTAMP, timestampScale));
} else {
builder.columnType(PHOENIX_TIMESTAMP);
}
builder.dataType(PHOENIX_TIMESTAMP);
builder.scale(timestampScale);
break;
case ARRAY:
ArrayType arrayType = (ArrayType) column.getDataType();
SeaTunnelDataType elementType = arrayType.getElementType();
switch (elementType.getSqlType()) {
case BOOLEAN:
builder.columnType(PHOENIX_BOOLEAN + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_BOOLEAN + " " + PHOENIX_ARRAY);
break;
case TINYINT:
builder.columnType(PHOENIX_TINYINT + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_TINYINT + " " + PHOENIX_ARRAY);
break;
case SMALLINT:
builder.columnType(PHOENIX_SMALLINT + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_SMALLINT + " " + PHOENIX_ARRAY);
break;
case INT:
builder.columnType(PHOENIX_INTEGER + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_INTEGER + " " + PHOENIX_ARRAY);
break;
case BIGINT:
builder.columnType(PHOENIX_BIGINT + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_BIGINT + " " + PHOENIX_ARRAY);
break;
case FLOAT:
builder.columnType(PHOENIX_FLOAT + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_FLOAT + " " + PHOENIX_ARRAY);
break;
case DOUBLE:
builder.columnType(PHOENIX_DOUBLE + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_DOUBLE + " " + PHOENIX_ARRAY);
break;
case STRING:
builder.columnType(PHOENIX_VARCHAR + " " + PHOENIX_ARRAY);
builder.dataType(PHOENIX_VARCHAR + " " + PHOENIX_ARRAY);
break;
default:
throw CommonError.convertToConnectorTypeError(
PHOENIX, elementType.getSqlType().name(), column.getName());
}
break;
default:
throw CommonError.convertToConnectorTypeError(
PHOENIX, column.getDataType().getSqlType().name(), column.getName());
}
return builder.build();
}