[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/spark/pull/7060


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread rxin
Github user rxin commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116827359
  
Thanks. Merging in master & branch-1.4.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread brkyvz
Github user brkyvz commented on a diff in the pull request:

https://github.com/apache/spark/pull/7060#discussion_r33499886
  
--- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameStatSuite.scala ---
@@ -65,22 +67,22 @@ class DataFrameStatSuite extends SparkFunSuite  {
   }
 
   test("crosstab") {
-val df = Seq((0, 0), (2, 1), (1, 0), (2, 0), (0, 0), (2, 0)).toDF("a", 
"b")
+val rng = new Random()
+val data = Seq.tabulate(25)(i => (rng.nextInt(5), rng.nextInt(10)))
+val df = data.toDF("a", "b")
 val crosstab = df.stat.crosstab("a", "b")
 val columnNames = crosstab.schema.fieldNames
 assert(columnNames(0) === "a_b")
-assert(columnNames(1) === "0")
-assert(columnNames(2) === "1")
-val rows: Array[Row] = crosstab.collect().sortBy(_.getString(0))
-assert(rows(0).get(0).toString === "0")
-assert(rows(0).getLong(1) === 2L)
-assert(rows(0).get(2) === 0L)
-assert(rows(1).get(0).toString === "1")
-assert(rows(1).getLong(1) === 1L)
-assert(rows(1).get(2) === 0L)
-assert(rows(2).get(0).toString === "2")
-assert(rows(2).getLong(1) === 2L)
-assert(rows(2).getLong(2) === 1L)
+// reduce by key
+val expected = data.map(t => (t, 1)).groupBy(_._1).mapValues(_.length)
+val rows = crosstab.collect()
+rows.foreach { row =>
+  val i = row.getString(0).toInt
+  for (col <- 1 to 9) {
+val j = columnNames(col).toInt
+assert(row.getLong(col) === expected.getOrElse((i, j), 0).toLong)
--- End diff --

That would need a lot of work, because we don't know the ordering of the 
rows and the columns


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread marmbrus
Github user marmbrus commented on a diff in the pull request:

https://github.com/apache/spark/pull/7060#discussion_r33497360
  
--- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameStatSuite.scala ---
@@ -65,22 +67,22 @@ class DataFrameStatSuite extends SparkFunSuite  {
   }
 
   test("crosstab") {
-val df = Seq((0, 0), (2, 1), (1, 0), (2, 0), (0, 0), (2, 0)).toDF("a", 
"b")
+val rng = new Random()
+val data = Seq.tabulate(25)(i => (rng.nextInt(5), rng.nextInt(10)))
+val df = data.toDF("a", "b")
 val crosstab = df.stat.crosstab("a", "b")
 val columnNames = crosstab.schema.fieldNames
 assert(columnNames(0) === "a_b")
-assert(columnNames(1) === "0")
-assert(columnNames(2) === "1")
-val rows: Array[Row] = crosstab.collect().sortBy(_.getString(0))
-assert(rows(0).get(0).toString === "0")
-assert(rows(0).getLong(1) === 2L)
-assert(rows(0).get(2) === 0L)
-assert(rows(1).get(0).toString === "1")
-assert(rows(1).getLong(1) === 1L)
-assert(rows(1).get(2) === 0L)
-assert(rows(2).get(0).toString === "2")
-assert(rows(2).getLong(1) === 2L)
-assert(rows(2).getLong(2) === 1L)
+// reduce by key
+val expected = data.map(t => (t, 1)).groupBy(_._1).mapValues(_.length)
+val rows = crosstab.collect()
+rows.foreach { row =>
+  val i = row.getString(0).toInt
+  for (col <- 1 to 9) {
+val j = columnNames(col).toInt
+assert(row.getLong(col) === expected.getOrElse((i, j), 0).toLong)
--- End diff --

Could we use `checkAnswer` here instead?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread AmplabJenkins
Github user AmplabJenkins commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116772162
  
Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread SparkQA
Github user SparkQA commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116772124
  
  [Test build #35993 has 
finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/35993/console)
 for   PR 7060 at commit 
[`0a65234`](https://github.com/apache/spark/commit/0a65234a1246ee879836aa223fa028dabaf41703).
 * This patch **passes all tests**.
 * This patch merges cleanly.
 * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread SparkQA
Github user SparkQA commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116736531
  
  [Test build #35993 has 
started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/35993/consoleFull)
 for   PR 7060 at commit 
[`0a65234`](https://github.com/apache/spark/commit/0a65234a1246ee879836aa223fa028dabaf41703).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread AmplabJenkins
Github user AmplabJenkins commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116735845
  
Merged build started.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread AmplabJenkins
Github user AmplabJenkins commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116735798
  
 Merged build triggered.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread rxin
Github user rxin commented on a diff in the pull request:

https://github.com/apache/spark/pull/7060#discussion_r33440758
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/stat/StatFunctions.scala 
---
@@ -119,14 +119,14 @@ private[sql] object StatFunctions extends Logging {
   rows.foreach { (row: Row) =>
 // row.get(0) is column 1
 // row.get(1) is column 2
-// row.get(3) is the frequency
+// row.get(2) is the frequency
 countsRow.setLong(distinctCol2.get(row.get(1)).get + 1, 
row.getLong(2))
   }
   // the value of col1 is the first value, the rest are the counts
   countsRow.setString(0, col1Item.toString)
   countsRow
 }.toSeq
-val headerNames = distinctCol2.map(r => StructField(r._1.toString, 
LongType)).toSeq
+val headerNames = distinctCol2.toSeq.sortBy(_._2).map(r => 
StructField(r._1.toString, LongType))
--- End diff --

i'd also add explicit type for distinctCol2, and explain what the tuples are


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-29 Thread rxin
Github user rxin commented on a diff in the pull request:

https://github.com/apache/spark/pull/7060#discussion_r33440738
  
--- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/stat/StatFunctions.scala 
---
@@ -119,14 +119,14 @@ private[sql] object StatFunctions extends Logging {
   rows.foreach { (row: Row) =>
 // row.get(0) is column 1
 // row.get(1) is column 2
-// row.get(3) is the frequency
+// row.get(2) is the frequency
 countsRow.setLong(distinctCol2.get(row.get(1)).get + 1, 
row.getLong(2))
   }
   // the value of col1 is the first value, the rest are the counts
   countsRow.setString(0, col1Item.toString)
   countsRow
 }.toSeq
-val headerNames = distinctCol2.map(r => StructField(r._1.toString, 
LongType)).toSeq
+val headerNames = distinctCol2.toSeq.sortBy(_._2).map(r => 
StructField(r._1.toString, LongType))
--- End diff --

maybe add inline comment explaining what _2 is?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-27 Thread SparkQA
Github user SparkQA commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116163783
  
  [Test build #35899 has 
finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/35899/console)
 for   PR 7060 at commit 
[`d96da7e`](https://github.com/apache/spark/commit/d96da7e955574b12587e10d69d6008115ebc6352).
 * This patch **passes all tests**.
 * This patch merges cleanly.
 * This patch adds no public classes.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-27 Thread AmplabJenkins
Github user AmplabJenkins commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116163791
  
Merged build finished. Test PASSed.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-27 Thread SparkQA
Github user SparkQA commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116138794
  
  [Test build #35899 has 
started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/35899/consoleFull)
 for   PR 7060 at commit 
[`d96da7e`](https://github.com/apache/spark/commit/d96da7e955574b12587e10d69d6008115ebc6352).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-27 Thread AmplabJenkins
Github user AmplabJenkins commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116137780
  
 Merged build triggered.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-27 Thread AmplabJenkins
Github user AmplabJenkins commented on the pull request:

https://github.com/apache/spark/pull/7060#issuecomment-116137825
  
Merged build started.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request: [SPARK-8681] fixed wrong ordering of columns i...

2015-06-27 Thread brkyvz
GitHub user brkyvz opened a pull request:

https://github.com/apache/spark/pull/7060

[SPARK-8681] fixed wrong ordering of columns in crosstab

I specifically randomized the test. What crosstab does is equivalent to a 
countByKey, therefore if this test fails again for any reason, we will know 
that we hit a corner case or something.

cc @rxin @marmbrus 

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/brkyvz/spark crosstab-fixes

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/spark/pull/7060.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #7060


commit d96da7e955574b12587e10d69d6008115ebc6352
Author: Burak Yavuz 
Date:   2015-06-27T20:35:02Z

fixed wrong ordering of columns in crosstab




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org