Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-31735][SQL] Include date/timestamp in the summary report #28554

Closed
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ object StatFunctions extends Logging {
}

val selectedCols = ds.logicalPlan.output
.filter(a => a.dataType.isInstanceOf[NumericType] || a.dataType.isInstanceOf[StringType])
Copy link
Member

@dongjoon-hyun dongjoon-hyun May 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep this whitelist style instead of allowing all, @Fokko ? You can add the missing type here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I've just updated the list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @Fokko . Could you update the PR title and description accordingly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated both the PR and commit, please let me know if this works for you

Copy link
Member

@dongjoon-hyun dongjoon-hyun May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove Even something less common such as arrays are sortable: and its example in the PR description?

.filter(a => a.dataType.isInstanceOf[NumericType]
|| a.dataType.isInstanceOf[StringType]
|| a.dataType.isInstanceOf[DateType]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's write a UT. Does it work BTW? Looks at least mean and date type won't work here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm working on getting the test suite running on my machine, so I need some time. I don't think that the mean will be the issue, this is just the element in the middle of the sorted collection, however, the stddev will be tricky. For the StringType this is just null.

|| a.dataType.isInstanceOf[TimestampType])

val aggExprs = statisticFns.flatMap { func =>
selectedCols.map(c => Column(Cast(func(c), StringType)).as(c.name))
Expand Down
32 changes: 16 additions & 16 deletions sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -832,30 +832,30 @@ class DataFrameSuite extends QueryTest
}

private lazy val person2: DataFrame = Seq(
("Bob", 16, 176),
("Alice", 32, 164),
("David", 60, 192),
("Amy", 24, 180)).toDF("name", "age", "height")
("Bob", 16, 176, new Date(2020, 1, 1)),
("Alice", 32, 164, new Date(2020, 1, 5)),
("David", 60, 192, new Date(2020, 1, 19)),
("Amy", 24, 180, new Date(2020, 1, 25))).toDF("name", "age", "height", "birthday")

test("describe") {
val describeResult = Seq(
Row("count", "4", "4", "4"),
Row("mean", null, "33.0", "178.0"),
Row("stddev", null, "19.148542155126762", "11.547005383792516"),
Row("min", "Alice", "16", "164"),
Row("max", "David", "60", "192"))
Row("count", "4", "4", "4", "4"),
Row("mean", null, "33.0", "178.0", "2020-1-25"),
Row("stddev", null, "19.148542155126762", "11.547005383792516", null),
Row("min", "Alice", "16", "164", "2020-1-1"),
Row("max", "David", "60", "192", "2020-1-25"))

val emptyDescribeResult = Seq(
Row("count", "0", "0", "0"),
Row("mean", null, null, null),
Row("stddev", null, null, null),
Row("min", null, null, null),
Row("max", null, null, null))
Row("count", "0", "0", "0", "0"),
Row("mean", null, null, null, null),
Row("stddev", null, null, null, null),
Row("min", null, null, null, null),
Row("max", null, null, null, null))

def getSchemaAsSeq(df: DataFrame): Seq[String] = df.schema.map(_.name)

val describeAllCols = person2.describe()
assert(getSchemaAsSeq(describeAllCols) === Seq("summary", "name", "age", "height"))
assert(getSchemaAsSeq(describeAllCols) === Seq("summary", "name", "age", "height", "birthday"))
checkAnswer(describeAllCols, describeResult)
// All aggregate value should have been cast to string
describeAllCols.collect().foreach { row =>
Expand All @@ -875,7 +875,7 @@ class DataFrameSuite extends QueryTest
checkAnswer(describeNoCol, describeResult.map { case Row(s, _, _, _) => Row(s)} )

val emptyDescription = person2.limit(0).describe()
assert(getSchemaAsSeq(emptyDescription) === Seq("summary", "name", "age", "height"))
assert(getSchemaAsSeq(emptyDescription) === Seq("summary", "name", "age", "height", "birthday"))
checkAnswer(emptyDescription, emptyDescribeResult)
}

Expand Down