diff --git a/src/main/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrint.scala b/src/main/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrint.scala index a8f676c..6c8ce22 100644 --- a/src/main/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrint.scala +++ b/src/main/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrint.scala @@ -1,10 +1,9 @@ package com.github.mrpowers.spark.fast.tests import java.sql.Date - import com.github.mrpowers.spark.fast.tests.ufansi.EscapeAttr +import java.time.format.DateTimeFormatter import org.apache.commons.lang3.StringUtils -import org.apache.spark.sql.catalyst.util.DateTimeUtils object ArrayPrettyPrint { @@ -16,7 +15,7 @@ object ArrayPrettyPrint { case binary: Array[Byte] => binary.map("%02X".format(_)).mkString("[", " ", "]") case array: Array[_] => array.mkString("[", ", ", "]") case seq: Seq[_] => seq.mkString("[", ", ", "]") - case d: Date => DateTimeUtils.dateToString(DateTimeUtils.fromJavaDate(d)) + case d: Date => d.toLocalDate.format(DateTimeFormatter.ISO_DATE) case _ => cell.toString } if (truncate > 0 && str.length > truncate) { diff --git a/src/main/scala/com/github/mrpowers/spark/fast/tests/DataFramePrettyPrint.scala b/src/main/scala/com/github/mrpowers/spark/fast/tests/DataFramePrettyPrint.scala index fcce36d..d61b518 100644 --- a/src/main/scala/com/github/mrpowers/spark/fast/tests/DataFramePrettyPrint.scala +++ b/src/main/scala/com/github/mrpowers/spark/fast/tests/DataFramePrettyPrint.scala @@ -1,10 +1,10 @@ package com.github.mrpowers.spark.fast.tests import java.sql.Date - +import java.time.format.DateTimeFormatter import org.apache.commons.lang3.StringUtils -import org.apache.spark.sql.{DataFrame, Dataset} -import org.apache.spark.sql.catalyst.util.DateTimeUtils + +import org.apache.spark.sql.DataFrame object DataFramePrettyPrint { @@ -42,7 +42,7 @@ object DataFramePrettyPrint { "]" ) case d: Date => - DateTimeUtils.dateToString(DateTimeUtils.fromJavaDate(d)) + d.toLocalDate.format(DateTimeFormatter.ISO_DATE) case _ => cell.toString } if (truncate > 0 && str.length > truncate) { diff --git a/src/test/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrintTest.scala b/src/test/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrintTest.scala index 84204c3..ca3ed94 100644 --- a/src/test/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrintTest.scala +++ b/src/test/scala/com/github/mrpowers/spark/fast/tests/ArrayPrettyPrintTest.scala @@ -1,5 +1,7 @@ package com.github.mrpowers.spark.fast.tests +import java.sql.Date +import java.time.LocalDate import org.scalatest.FreeSpec class ArrayPrettyPrintTest extends FreeSpec { @@ -15,6 +17,13 @@ class ArrayPrettyPrintTest extends FreeSpec { println(ArrayPrettyPrint.showTwoColumnString(arr, 10)) } + "showTwoColumnDate" in { + val now = LocalDate.now() + val arr: Array[(Any, Any)] = + Array(("word1", "word2"), (Date.valueOf(now), Date.valueOf(now)), (Date.valueOf(now.plusDays(-1)), Date.valueOf(now))) + println(ArrayPrettyPrint.showTwoColumnString(arr, 10)) + } + "dumbshowTwoColumnString" in { val arr: Array[(Any, Any)] = Array(("word1", "word2"), ("hi", "there"), ("fun", "train")) val rowEqual = Array(true, false)