This is an automated email from the ASF dual-hosted git repository.

wuchunfu pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-seatunnel.git


The following commit(s) were added to refs/heads/dev by this push:
     new 39d4a6f  [Bug][Connector] Clickhouse sink doesn't handle sql output 
data types correctly (#1381)
39d4a6f is described below

commit 39d4a6fc67f6d4ab3e48af6b4b254e5bf358f5e4
Author: TrickyZerg <[email protected]>
AuthorDate: Fri Mar 4 14:17:45 2022 +0800

    [Bug][Connector] Clickhouse sink doesn't handle sql output data types 
correctly (#1381)
    
    * [ST-1368][fix] Clickhouse sink doesn't handle sql output data types 
correctly
    fix decimal cast to double/float throw error bug
    This closes #1368
    
    * [ST-1368][fix] Clickhouse sink doesn't handle sql output data types 
correctly
    fix decimal cast to double/float throw error bug
    This closes #1368
---
 .../org/apache/seatunnel/spark/sink/Clickhouse.scala   | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git 
a/seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
 
b/seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
index 338778c..c1d6445 100644
--- 
a/seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
+++ 
b/seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
@@ -354,8 +354,22 @@ class Clickhouse extends SparkBatchSink {
         statement.setInt(index + 1, item.getAs[Int](fieldIndex))
       case "UInt32" | "UInt64" | "Int64" =>
         statement.setLong(index + 1, item.getAs[Long](fieldIndex))
-      case "Float32" => statement.setFloat(index + 1, 
item.getAs[Float](fieldIndex))
-      case "Float64" => statement.setDouble(index + 1, 
item.getAs[Double](fieldIndex))
+      case "Float32" =>
+        val value = item.get(fieldIndex)
+        value match {
+          case decimal: BigDecimal =>
+            statement.setFloat(index + 1, decimal.floatValue())
+          case _ =>
+            statement.setFloat(index + 1, value.asInstanceOf[Float])
+        }
+      case "Float64" =>
+        val value = item.get(fieldIndex)
+        value match {
+          case decimal: BigDecimal =>
+            statement.setDouble(index + 1, decimal.doubleValue())
+          case _ =>
+            statement.setDouble(index + 1, value.asInstanceOf[Double])
+        }
       case Clickhouse.arrayPattern(_) =>
         statement.setArray(index + 1, item.getAs[java.sql.Array](fieldIndex))
       case "Decimal" => statement.setBigDecimal(index + 1, 
item.getAs[BigDecimal](fieldIndex))

Reply via email to