Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions R/pkg/inst/tests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,12 @@ test_that("parquetFile works with multiple input paths", {
test_that("describe() on a DataFrame", {
df <- jsonFile(sqlCtx, jsonPath)
stats <- describe(df, "age")
expect_true(collect(stats)[1, "summary"] == "count")
expect_true(collect(stats)[2, "age"] == 24.5)
expect_true(collect(stats)[3, "age"] == 5.5)
expect_equal(collect(stats)[1, "summary"], "count")
expect_equal(collect(stats)[2, "age"], "24.5")
expect_equal(collect(stats)[3, "age"], "5.5")
stats <- describe(df)
expect_true(collect(stats)[4, "name"] == "Andy")
expect_true(collect(stats)[5, "age"] == 30.0)
expect_equal(collect(stats)[4, "name"], "Andy")
expect_equal(collect(stats)[5, "age"], "30")
})

unlink(parquetPath)
Expand Down
6 changes: 3 additions & 3 deletions sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ class DataFrame private[sql](

val ret: Seq[Row] = if (outputCols.nonEmpty) {
val aggExprs = statistics.flatMap { case (_, colToAgg) =>
outputCols.map(c => Column(colToAgg(Column(c).expr)).as(c))
outputCols.map(c => Column(Cast(colToAgg(Column(c).expr), StringType)).as(c))
}

val row = agg(aggExprs.head, aggExprs.tail: _*).head().toSeq
Expand All @@ -1077,9 +1077,9 @@ class DataFrame private[sql](
statistics.map { case (name, _) => Row(name) }
}

// The first column is string type, and the rest are double type.
// All columns are string type
val schema = StructType(
StructField("summary", StringType) :: outputCols.map(StructField(_, DoubleType))).toAttributes
StructField("summary", StringType) :: outputCols.map(StructField(_, StringType))).toAttributes
LocalRelation(schema, ret)
}

Expand Down
17 changes: 11 additions & 6 deletions sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,14 @@ class DataFrameSuite extends QueryTest {
("Amy", 24, 180)).toDF("name", "age", "height")

val describeResult = Seq(
Row("count", 4, 4),
Row("mean", 33.0, 178.0),
Row("stddev", 16.583123951777, 10.0),
Row("min", 16, 164),
Row("max", 60, 192))
Row("count", "4", "4"),
Row("mean", "33.0", "178.0"),
Row("stddev", "16.583123951777", "10.0"),
Row("min", "16", "164"),
Row("max", "60", "192"))

val emptyDescribeResult = Seq(
Row("count", 0, 0),
Row("count", "0", "0"),
Row("mean", null, null),
Row("stddev", null, null),
Row("min", null, null),
Expand All @@ -388,6 +388,11 @@ class DataFrameSuite extends QueryTest {
val describeTwoCols = describeTestData.describe("age", "height")
assert(getSchemaAsSeq(describeTwoCols) === Seq("summary", "age", "height"))
checkAnswer(describeTwoCols, describeResult)
// All aggregate value should have been cast to string
describeTwoCols.collect().foreach { row =>
assert(row.get(1).isInstanceOf[String], "expected string but found " + row.get(1).getClass)
assert(row.get(2).isInstanceOf[String], "expected string but found " + row.get(2).getClass)
}

val describeAllCols = describeTestData.describe()
assert(getSchemaAsSeq(describeAllCols) === Seq("summary", "age", "height"))
Expand Down