DBZ-804 Exporting non floating point NUMBER columns (scale = 0) as Decimal
This commit is contained in:
parent
6c899c2de4
commit
fbaa2b92f8
@ -213,12 +213,22 @@ else if (ctx.datatype().native_datatype_element().FLOAT() != null ||
|
||||
.jdbcType(Types.FLOAT)
|
||||
.type("FLOAT")
|
||||
.length(126);
|
||||
|
||||
// TODO float's precision is about bits not decimal digits; should be ok for now to over-size
|
||||
if (precisionPart != null) {
|
||||
setPrecision(precisionPart, columnEditor);
|
||||
}
|
||||
}
|
||||
else if (ctx.datatype().native_datatype_element().REAL() != null) {
|
||||
columnEditor
|
||||
.jdbcType(Types.FLOAT)
|
||||
.type("FLOAT")
|
||||
.length(63);
|
||||
|
||||
// TODO float's precision is about bits not decimal digits; should be ok for now to over-size
|
||||
if (precisionPart != null) {
|
||||
setPrecision(precisionPart, columnEditor);
|
||||
}
|
||||
}
|
||||
else if (ctx.datatype().native_datatype_element().NUMBER() != null) {
|
||||
columnEditor
|
||||
@ -228,6 +238,10 @@ else if (ctx.datatype().native_datatype_element().NUMBER() != null) {
|
||||
if (precisionPart == null) {
|
||||
columnEditor.length(38);
|
||||
}
|
||||
else {
|
||||
setPrecision(precisionPart, columnEditor);
|
||||
setScale(precisionPart, columnEditor);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported column type: " + ctx.datatype().native_datatype_element().getText());
|
||||
@ -295,6 +309,19 @@ private int getVarCharDefaultLength() {
|
||||
return 4000;
|
||||
}
|
||||
|
||||
private void setPrecision(Precision_partContext precisionPart, ColumnEditor columnEditor) {
|
||||
columnEditor.length(Integer.valueOf(precisionPart.numeric(0).getText()));
|
||||
}
|
||||
|
||||
private void setScale(Precision_partContext precisionPart, ColumnEditor columnEditor) {
|
||||
if (precisionPart.numeric().size() > 1) {
|
||||
columnEditor.scale(Integer.valueOf(precisionPart.numeric(1).getText()));
|
||||
}
|
||||
else {
|
||||
columnEditor.scale(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exitOut_of_line_constraint(Out_of_line_constraintContext ctx) {
|
||||
if(ctx.PRIMARY() != null) {
|
||||
|
@ -46,7 +46,7 @@ public abstract class AbstractOracleDatatypesTest extends AbstractConnectorTest
|
||||
*/
|
||||
static final String PRECISION_PARAMETER_KEY = "connect.decimal.precision";
|
||||
|
||||
private static final Schema INTEGER_SCHEMA = Decimal.builder(0).optional().parameter(PRECISION_PARAMETER_KEY, "38").build();
|
||||
private static final Schema NUMBER_SCHEMA = Decimal.builder(0).optional().parameter(PRECISION_PARAMETER_KEY, "38").build();
|
||||
|
||||
private static final String DDL_STRING = "create table debezium.type_string (" +
|
||||
" id int not null, " +
|
||||
@ -74,6 +74,8 @@ public abstract class AbstractOracleDatatypesTest extends AbstractConnectorTest
|
||||
" val_int int, " +
|
||||
" val_integer integer, " +
|
||||
" val_smallint smallint, " +
|
||||
" val_number_38_no_scale number(38), " +
|
||||
" val_number_38_scale_0 number(38, 0), " +
|
||||
" primary key (id)" +
|
||||
")";
|
||||
|
||||
@ -106,9 +108,11 @@ public abstract class AbstractOracleDatatypesTest extends AbstractConnectorTest
|
||||
);
|
||||
|
||||
private static final List<SchemaAndValueField> EXPECTED_INT = Arrays.asList(
|
||||
new SchemaAndValueField("VAL_INT", INTEGER_SCHEMA, new BigDecimal("1")),
|
||||
new SchemaAndValueField("VAL_INTEGER", INTEGER_SCHEMA, new BigDecimal("22")),
|
||||
new SchemaAndValueField("VAL_SMALLINT", INTEGER_SCHEMA, new BigDecimal("333"))
|
||||
new SchemaAndValueField("VAL_INT", NUMBER_SCHEMA, new BigDecimal("1")),
|
||||
new SchemaAndValueField("VAL_INTEGER", NUMBER_SCHEMA, new BigDecimal("22")),
|
||||
new SchemaAndValueField("VAL_SMALLINT", NUMBER_SCHEMA, new BigDecimal("333")),
|
||||
new SchemaAndValueField("VAL_NUMBER_38_NO_SCALE", NUMBER_SCHEMA, new BigDecimal("4444")),
|
||||
new SchemaAndValueField("VAL_NUMBER_38_SCALE_0", NUMBER_SCHEMA, new BigDecimal("5555"))
|
||||
);
|
||||
|
||||
private static final List<SchemaAndValueField> EXPECTED_TIME = Arrays.asList(
|
||||
@ -292,7 +296,7 @@ protected static void insertFpTypes() throws SQLException {
|
||||
}
|
||||
|
||||
protected static void insertIntTypes() throws SQLException {
|
||||
connection.execute("INSERT INTO debezium.type_int VALUES (1, 1, 22, 333)");
|
||||
connection.execute("INSERT INTO debezium.type_int VALUES (1, 1, 22, 333, 4444, 5555)");
|
||||
connection.execute("COMMIT");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user