@@ -647,11 +647,11 @@ test_that("sample on a DataFrame", {
647647  sampled  <-  sample(df , FALSE , 1.0 )
648648  expect_equal(nrow(collect(sampled )), count(df ))
649649  expect_is(sampled , " DataFrame" 
650-   sampled2  <-  sample(df , FALSE , 0.1 ) 
650+   sampled2  <-  sample(df , FALSE , 0.1 ,  0 )  #  set seed for predictable result 
651651  expect_true(count(sampled2 ) <  3 )
652652
653653  #  Also test sample_frac
654-   sampled3  <-  sample_frac(df , FALSE , 0.1 ) 
654+   sampled3  <-  sample_frac(df , FALSE , 0.1 ,  0 )  #  set seed for predictable result 
655655  expect_true(count(sampled3 ) <  3 )
656656})
657657
@@ -875,9 +875,9 @@ test_that("column binary mathfunctions", {
875875  expect_equal(collect(select(df , shiftRight(df $ b , 1 )))[4 , 1 ], 4 )
876876  expect_equal(collect(select(df , shiftRightUnsigned(df $ b , 1 )))[4 , 1 ], 4 )
877877  expect_equal(class(collect(select(df , rand()))[2 , 1 ]), " numeric" 
878-   expect_equal(collect(select(df , rand(1 )))[1 , 1 ], 0.45  , tolerance  =  0.01 )
878+   expect_equal(collect(select(df , rand(1 )))[1 , 1 ], 0.134  , tolerance  =  0.01 )
879879  expect_equal(class(collect(select(df , randn()))[2 , 1 ]), " numeric" 
880-   expect_equal(collect(select(df , randn(1 )))[1 , 1 ], - 0.0111 , tolerance  =  0.01 )
880+   expect_equal(collect(select(df , randn(1 )))[1 , 1 ], - 1.03 , tolerance  =  0.01 )
881881})
882882
883883test_that(" string operators" 
@@ -1458,17 +1458,18 @@ test_that("sampleBy() on a DataFrame", {
14581458  fractions  <-  list (" 0" =  0.1 , " 1" =  0.2 )
14591459  sample  <-  sampleBy(df , " key" fractions , 0 )
14601460  result  <-  collect(orderBy(count(groupBy(sample , " key" " key" 
1461-   expect_identical(as.list(result [1 , ]), list (key  =  " 0" count  =  2 ))
1462-   expect_identical(as.list(result [2 , ]), list (key  =  " 1" count  =  10 ))
1461+   expect_identical(as.list(result [1 , ]), list (key  =  " 0" count  =  3 ))
1462+   expect_identical(as.list(result [2 , ]), list (key  =  " 1" count  =  7 ))
14631463})
14641464
14651465test_that(" SQL error message is returned from JVM" 
14661466  retError  <-  tryCatch(sql(sqlContext , " select * from blah" error  =  function (e ) e )
14671467  expect_equal(grepl(" Table not found: blah" retError ), TRUE )
14681468})
14691469
1470+ irisDF  <-  createDataFrame(sqlContext , iris )
1471+ 
14701472test_that(" Method as.data.frame as a synonym for collect()" 
1471-   irisDF  <-  createDataFrame(sqlContext , iris )
14721473  expect_equal(as.data.frame(irisDF ), collect(irisDF ))
14731474  irisDF2  <-  irisDF [irisDF $ Species  ==  " setosa" 
14741475  expect_equal(as.data.frame(irisDF2 ), collect(irisDF2 ))
@@ -1503,6 +1504,27 @@ test_that("with() on a DataFrame", {
15031504  expect_equal(nrow(sum2 ), 35 )
15041505})
15051506
1507+ test_that(" Method coltypes() to get R's data types of a DataFrame" 
1508+   expect_equal(coltypes(irisDF ), c(rep(" numeric" 4 ), " character" 
1509+ 
1510+   data  <-  data.frame (c1 = c(1 ,2 ,3 ),
1511+                      c2 = c(T ,F ,T ),
1512+                      c3 = c(" 2015/01/01 10:00:00" " 2015/01/02 10:00:00" " 2015/01/03 10:00:00" 
1513+ 
1514+   schema  <-  structType(structField(" c1" " byte" 
1515+                        structField(" c3" " boolean" 
1516+                        structField(" c4" " timestamp" 
1517+ 
1518+   #  Test primitive types
1519+   DF  <-  createDataFrame(sqlContext , data , schema )
1520+   expect_equal(coltypes(DF ), c(" integer" " logical" " POSIXct" 
1521+ 
1522+   #  Test complex types
1523+   x  <-  createDataFrame(sqlContext , list (list (as.environment(
1524+     list (" a" = " b" " c" = " d" " e" = " f" 
1525+   expect_equal(coltypes(x ), " map<string,string>" 
1526+ })
1527+ 
15061528unlink(parquetPath )
15071529unlink(jsonPath )
15081530unlink(jsonPathNa )
0 commit comments