Skip to content

Commit 2974bd5

Browse files
committed
Cast to string type instead
1 parent f206580 commit 2974bd5

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

R/pkg/inst/tests/test_sparkSQL.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,11 @@ test_that("describe() on a DataFrame", {
758758
df <- jsonFile(sqlCtx, jsonPath)
759759
stats <- describe(df, "age")
760760
expect_true(collect(stats)[1, "summary"] == "count")
761-
expect_true(collect(stats)[2, "age"] == 24.5)
762-
expect_true(collect(stats)[3, "age"] == 5.5)
761+
expect_true(collect(stats)[2, "age"] == "24.5")
762+
expect_true(collect(stats)[3, "age"] == "5.5")
763763
stats <- describe(df)
764764
expect_true(collect(stats)[4, "name"] == "Andy")
765-
expect_true(collect(stats)[5, "age"] == 30.0)
765+
expect_true(collect(stats)[5, "age"] == "30.0")
766766
})
767767

768768
unlink(parquetPath)

python/pyspark/sql/dataframe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,11 +599,11 @@ def describe(self, *cols):
599599
+-------+---+
600600
|summary|age|
601601
+-------+---+
602-
| count|2.0|
602+
| count| 2|
603603
| mean|3.5|
604604
| stddev|1.5|
605-
| min|2.0|
606-
| max|5.0|
605+
| min| 2|
606+
| max| 5|
607607
+-------+---+
608608
"""
609609
jdf = self._jdf.describe(self._jseq(cols))

sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ class DataFrame private[sql](
10631063

10641064
val ret: Seq[Row] = if (outputCols.nonEmpty) {
10651065
val aggExprs = statistics.flatMap { case (_, colToAgg) =>
1066-
outputCols.map(c => Column(Cast(colToAgg(Column(c).expr), DoubleType)).as(c))
1066+
outputCols.map(c => Column(Cast(colToAgg(Column(c).expr), StringType)).as(c))
10671067
}
10681068

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

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

sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ class DataFrameSuite extends QueryTest {
370370
("Amy", 24, 180)).toDF("name", "age", "height")
371371

372372
val describeResult = Seq(
373-
Row("count", 4, 4),
374-
Row("mean", 33.0, 178.0),
375-
Row("stddev", 16.583123951777, 10.0),
376-
Row("min", 16, 164),
377-
Row("max", 60, 192))
373+
Row("count", "4", "4"),
374+
Row("mean", "33.0", "178.0"),
375+
Row("stddev", "16.583123951777", "10.0"),
376+
Row("min", "16", "164"),
377+
Row("max", "60", "192"))
378378

379379
val emptyDescribeResult = Seq(
380-
Row("count", 0, 0),
380+
Row("count", "0", "0"),
381381
Row("mean", null, null),
382382
Row("stddev", null, null),
383383
Row("min", null, null),
@@ -388,10 +388,10 @@ class DataFrameSuite extends QueryTest {
388388
val describeTwoCols = describeTestData.describe("age", "height")
389389
assert(getSchemaAsSeq(describeTwoCols) === Seq("summary", "age", "height"))
390390
checkAnswer(describeTwoCols, describeResult)
391-
// All aggregate value should have been cast to double, including `count`
391+
// All aggregate value should have been cast to string
392392
describeTwoCols.collect().foreach { row =>
393-
assert(row.get(1).isInstanceOf[Double], "expected double but found " + row.get(1).getClass)
394-
assert(row.get(2).isInstanceOf[Double], "expected double but found " + row.get(2).getClass)
393+
assert(row.get(1).isInstanceOf[String], "expected string but found " + row.get(1).getClass)
394+
assert(row.get(2).isInstanceOf[String], "expected string but found " + row.get(2).getClass)
395395
}
396396

397397
val describeAllCols = describeTestData.describe()

0 commit comments

Comments
 (0)