Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Cast to string type instead
  • Loading branch information
JoshRosen committed May 18, 2015
commit 2974bd52b5fdc8517cf0568301108cea9ebfc2d6
6 changes: 3 additions & 3 deletions R/pkg/inst/tests/test_sparkSQL.R
Original file line number Diff line number Diff line change
Expand Up @@ -758,11 +758,11 @@ 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_true(collect(stats)[2, "age"] == "24.5")
expect_true(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_true(collect(stats)[5, "age"] == "30.0")
})

unlink(parquetPath)
Expand Down
6 changes: 3 additions & 3 deletions python/pyspark/sql/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,11 @@ def describe(self, *cols):
+-------+---+
|summary|age|
+-------+---+
| count|2.0|
| count| 2|
| mean|3.5|
| stddev|1.5|
| min|2.0|
| max|5.0|
| min| 2|
| max| 5|
+-------+---+
"""
jdf = self._jdf.describe(self._jseq(cols))
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(Cast(colToAgg(Column(c).expr), DoubleType)).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
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,10 +388,10 @@ 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 double, including `count`
// All aggregate value should have been cast to string
describeTwoCols.collect().foreach { row =>
assert(row.get(1).isInstanceOf[Double], "expected double but found " + row.get(1).getClass)
assert(row.get(2).isInstanceOf[Double], "expected double but found " + row.get(2).getClass)
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()
Expand Down