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-16429][SQL] Include StringType columns in describe() #14095

Closed
wants to merge 4 commits into from
Closed

[SPARK-16429][SQL] Include StringType columns in describe() #14095

wants to merge 4 commits into from

Conversation

dongjoon-hyun
Copy link
Member

@dongjoon-hyun dongjoon-hyun commented Jul 7, 2016

What changes were proposed in this pull request?

Currently, Spark describe supports StringType. However, describe() returns a dataset for only all numeric columns. This PR aims to include StringType columns in describe(), describe without argument.

Background

scala> spark.read.json("examples/src/main/resources/people.json").describe("age", "name").show()
+-------+------------------+-------+
|summary|               age|   name|
+-------+------------------+-------+
|  count|                 2|      3|
|   mean|              24.5|   null|
| stddev|7.7781745930520225|   null|
|    min|                19|   Andy|
|    max|                30|Michael|
+-------+------------------+-------+

Before

scala> spark.read.json("examples/src/main/resources/people.json").describe().show()
+-------+------------------+
|summary|               age|
+-------+------------------+
|  count|                 2|
|   mean|              24.5|
| stddev|7.7781745930520225|
|    min|                19|
|    max|                30|
+-------+------------------+

After

scala> spark.read.json("examples/src/main/resources/people.json").describe().show()
+-------+------------------+-------+                                            
|summary|               age|   name|
+-------+------------------+-------+
|  count|                 2|      3|
|   mean|              24.5|   null|
| stddev|7.7781745930520225|   null|
|    min|                19|   Andy|
|    max|                30|Michael|
+-------+------------------+-------+

How was this patch tested?

Pass the Jenkins with a update testcase.

@@ -228,6 +228,15 @@ class Dataset[T] private[sql](
}
}

private[sql] def aggregatableColumns: Seq[Expression] = {
Copy link
Contributor

Choose a reason for hiding this comment

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

private rather than private sql?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be better.

@dongjoon-hyun
Copy link
Member Author

Thank you for fast review, @rxin . I updated it.

@SparkQA
Copy link

SparkQA commented Jul 7, 2016

Test build #61929 has finished for PR 14095 at commit df2edd7.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member Author

Oh, it's a documented behavior.

Computes statistics for **numeric** columns

@SparkQA
Copy link

SparkQA commented Jul 7, 2016

Test build #61930 has finished for PR 14095 at commit b6673cb.

  • This patch fails PySpark unit tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun dongjoon-hyun changed the title [SPARK-16429][SQL] Include StringType columns in Scala/Python describe() [SPARK-16429][SQL] Include StringType columns in describe() Jul 7, 2016
@rxin
Copy link
Contributor

rxin commented Jul 8, 2016

Can you fix Python?

@dongjoon-hyun
Copy link
Member Author

Oh, sure!

@rxin
Copy link
Contributor

rxin commented Jul 8, 2016

And also update the documentation.

@dongjoon-hyun
Copy link
Member Author

Of course!

@dongjoon-hyun
Copy link
Member Author

I fixed Python/R and the docs accordingly, and tested locally.

.filter(f => f.dataType.isInstanceOf[NumericType] || f.dataType.isInstanceOf[StringType])
.map { n =>
queryExecution.analyzed.resolveQuoted(n.name, sparkSession.sessionState.analyzer.resolver)
.get
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible that this would fail?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ur, this is an direct extension of line 225 of existing numericColumns.

https://github.com/apache/spark/pull/14095/files#diff-7a46f10c3cedbf013cf255564d9483cdR225

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean the failure of resolveQuoted?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will not fail because the names come from schema.fields.

@SparkQA
Copy link

SparkQA commented Jul 8, 2016

Test build #61962 has finished for PR 14095 at commit 8915adb.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@dongjoon-hyun
Copy link
Member Author

Hi, @rxin .
It's ready for review again.

@SparkQA
Copy link

SparkQA commented Jul 8, 2016

Test build #61965 has finished for PR 14095 at commit fa4d3b4.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@rxin
Copy link
Contributor

rxin commented Jul 8, 2016

Thanks - merging in master.

@asfgit asfgit closed this in 142df48 Jul 8, 2016
@dongjoon-hyun
Copy link
Member Author

Thank you for merging, @rxin .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants