You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/03/03 05:47:44 UTC

[GitHub] [incubator-seatunnel] BenJFan opened a new pull request #1381: [ST-1368][fix] Clickhouse sink doesn't handle sql output data types correctly

BenJFan opened a new pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381


   fix decimal cast to double/float throw error bug
   This closes #1368
   
   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/incubator-seatunnel/issues).
   
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
   
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   
   -->
   
   ## Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [ ] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in you PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/developement/NewLicenseGuide.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] BenJFan commented on a change in pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
BenJFan commented on a change in pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381#discussion_r819279601



##########
File path: seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
##########
@@ -222,8 +222,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])
+        }

Review comment:
       This problem is sink to clickhouse user want the data type is double/float. But ours data type is decimal




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] BenJFan commented on a change in pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
BenJFan commented on a change in pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381#discussion_r819288920



##########
File path: seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
##########
@@ -222,8 +222,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])
+        }

Review comment:
       > > This problem is sink to clickhouse user want the data type is double/float. But ours data type is decimal
   > 
   > Okay, see, can we add `decimal` too?
   
   sorry, I find clickhouse sink already have decimal. See Clickhouse.scala:243




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] wuchunfu merged pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
wuchunfu merged pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] wuchunfu commented on pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381#issuecomment-1058869338


   Well done, looking forward to your next contribution


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] wuchunfu commented on a change in pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on a change in pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381#discussion_r819280687



##########
File path: seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
##########
@@ -222,8 +222,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])
+        }

Review comment:
       > This problem is sink to clickhouse user want the data type is double/float. But ours data type is decimal
   
   Okay, see, can we add `decimal` too?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] wuchunfu commented on a change in pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
wuchunfu commented on a change in pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381#discussion_r819276184



##########
File path: seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
##########
@@ -222,8 +222,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])
+        }

Review comment:
       @BenJFan `Clickhouse` seems to have a `Decimal` data type, haven't tried to use this?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-seatunnel] BenJFan commented on a change in pull request #1381: [Bug][Connector] Clickhouse sink doesn't handle sql output data types correctly

Posted by GitBox <gi...@apache.org>.
BenJFan commented on a change in pull request #1381:
URL: https://github.com/apache/incubator-seatunnel/pull/1381#discussion_r819281325



##########
File path: seatunnel-connectors/seatunnel-connector-spark-clickhouse/src/main/scala/org/apache/seatunnel/spark/sink/Clickhouse.scala
##########
@@ -222,8 +222,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])
+        }

Review comment:
       > 
   
   OK, I will do it




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org