Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-19727

Spark SQL round function modifies original column

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.2.0
    • Component/s: SQL
    • Labels:
      None

      Description

      import org.apache.spark.sql.functions
      
      case class MyRow(value : BigDecimal)
      val values = List(MyRow(BigDecimal.valueOf(1.23456789)))
      val dataFrame = spark.createDataFrame(values)
      dataFrame.show()
      dataFrame.withColumn("value_rounded", functions.round(dataFrame.col("value"))).show()
      

      This produces output:

      +--------------------+
      |               value|
      +--------------------+
      |1.234567890000000000|
      +--------------------+
      
      +--------------------+-------------+
      |               value|value_rounded|
      +--------------------+-------------+
      |1.000000000000000000|            1|
      +--------------------+-------------+
      

      Same problem occurs when I use round function to filter dataFrame.

        Attachments

          Activity

            People

            • Assignee:
              wojtek-szymanski Wojciech Szymanski
              Reporter:
              sbogutyn SÅ‚awomir Bogutyn
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: