Skip to content

Commit

Permalink
formatting and address TODO comment
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Feb 15, 2024
1 parent eda04f9 commit 5963296
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions spark/src/test/scala/org/apache/comet/CometCastSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@

package org.apache.comet

import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import java.nio.file.Files

import scala.util.Random

import org.apache.spark.sql.{CometTestBase, DataFrame, SaveMode}
import org.apache.spark.sql.execution.adaptive.AdaptiveSparkPlanHelper
import org.apache.spark.sql.functions.col
import org.apache.spark.sql.types.{DataType, DataTypes}

import scala.util.Random

class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
import testImplicits._

private val tempDir = Files.createTempDirectory("CometCastSuite")

ignore("cast long to short") {
castTest(generateLongs, DataTypes.ShortType)
}
Expand All @@ -46,7 +50,9 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
}

ignore("cast string to bool") {
castTest(Seq("TRUE", "True", "true", "FALSE", "False", "false", "1", "0", "").toDF("a"), DataTypes.BooleanType)
castTest(
Seq("TRUE", "True", "true", "FALSE", "False", "false", "1", "0", "").toDF("a"),
DataTypes.BooleanType)
fuzzCastFromString("truefalseTRUEFALSEyesno10 \t\r\n", 8, DataTypes.BooleanType)
}

Expand Down Expand Up @@ -83,7 +89,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {

private def genString(r: Random, chars: String, maxLen: Int): String = {
val len = r.nextInt(maxLen)
Range(0,len).map(_ => chars.charAt(r.nextInt(chars.length))).mkString
Range(0, len).map(_ => chars.charAt(r.nextInt(chars.length))).mkString
}

private def fuzzCastFromString(chars: String, maxLen: Int, toType: DataType) {
Expand All @@ -99,8 +105,7 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
}

private def roundtripParquet(df: DataFrame): DataFrame = {
// TODO create true temp file and delete after test completes
val filename = s"/tmp/castTest_${System.currentTimeMillis()}.parquet"
val filename = tempDir.resolve(s"castTest_${System.currentTimeMillis()}.parquet").toString
df.write.mode(SaveMode.Overwrite).parquet(filename)
spark.read.parquet(filename)
}
Expand Down

0 comments on commit 5963296

Please sign in to comment.