File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
sql/core/src/test/scala/org/apache/spark/sql Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -29,20 +29,22 @@ class DataFrameStatSuite extends FunSuite {
2929 def toLetter (i : Int ): String = (i + 97 ).toChar.toString
3030
3131 test(" crosstab" ) {
32- val df = sqlCtx.sparkContext.parallelize(( 1 to 6 ).map (i => (i % 3 , i % 2 ) )).toDF(" a" , " b" )
32+ val df = Seq .tabulate( 8 ) (i => (i % 3 , i % 2 )).toDF(" a" , " b" )
3333 val crosstab = df.stat.crosstab(" a" , " b" )
3434 val columnNames = crosstab.schema.fieldNames
3535 assert(columnNames(0 ) === " a_b" )
3636 assert(columnNames(1 ) === " 0" )
3737 assert(columnNames(2 ) === " 1" )
3838 val rows : Array [Row ] = crosstab.collect()
39- var count : Integer = 0
40- rows.foreach { row =>
41- assert(row.get(0 ).toString === count.toString)
42- assert(row.getLong(1 ) === 1L )
43- assert(row.getLong(2 ) === 1L )
44- count += 1
45- }
39+ assert(rows(0 ).get(0 ).toString === " 0" )
40+ assert(rows(0 ).getLong(1 ) === 2L )
41+ assert(rows(0 ).getLong(2 ) === 1L )
42+ assert(rows(1 ).get(0 ).toString === " 1" )
43+ assert(rows(1 ).getLong(1 ) === 1L )
44+ assert(rows(1 ).getLong(2 ) === 2L )
45+ assert(rows(2 ).get(0 ).toString === " 2" )
46+ assert(rows(2 ).getLong(1 ) === 1L )
47+ assert(rows(2 ).getLong(2 ) === 1L )
4648 }
4749
4850 test(" Frequent Items" ) {
You can’t perform that action at this time.
0 commit comments