Skip to content

Commit efb3597

Browse files
author
gepa
committed
Bind Short/BigDecimal values in Java and Spark table sinks
SqlTypeUtils now maps Short->SMALLINT and BigDecimal->NUMERIC for the generated DDL, but the sinks still bound those values via the String fallback. Complete the write path: - JavaTableSink: bind via setShort / setBigDecimal - SparkTableSink: map Short->ShortType and BigDecimal->DecimalType(38,18) so the Spark DataFrame writes SMALLINT / NUMERIC columns instead of text
1 parent 27b935b commit efb3597

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

wayang-platforms/wayang-java/src/main/java/org/apache/wayang/java/operators/JavaTableSink.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ private void setRecordValue(PreparedStatement ps, int index, Object value) throw
5959
ps.setDouble(index, (Double) value);
6060
} else if (value instanceof Float) {
6161
ps.setFloat(index, (Float) value);
62+
} else if (value instanceof Short) {
63+
ps.setShort(index, (Short) value);
64+
} else if (value instanceof java.math.BigDecimal) {
65+
ps.setBigDecimal(index, (java.math.BigDecimal) value);
6266
} else if (value instanceof Boolean) {
6367
ps.setBoolean(index, (Boolean) value);
6468
} else if (value instanceof java.sql.Date) {

wayang-platforms/wayang-spark/src/main/java/org/apache/wayang/spark/operators/SparkTableSink.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,14 @@ private org.apache.spark.sql.types.DataType getSparkDataType(Class<?> cls) {
146146
return DataTypes.IntegerType;
147147
if (cls == Long.class || cls == long.class)
148148
return DataTypes.LongType;
149+
if (cls == Short.class || cls == short.class)
150+
return DataTypes.ShortType;
149151
if (cls == Double.class || cls == double.class)
150152
return DataTypes.DoubleType;
151153
if (cls == Float.class || cls == float.class)
152154
return DataTypes.FloatType;
155+
if (cls == java.math.BigDecimal.class)
156+
return DataTypes.createDecimalType(38, 18);
153157
if (cls == Boolean.class || cls == boolean.class)
154158
return DataTypes.BooleanType;
155159
if (cls == java.sql.Date.class || cls == java.time.LocalDate.class)

0 commit comments

Comments
 (0)