@@ -335,7 +335,6 @@ writeLines(mockLinesMapType, mapTypeJsonPath)
335335test_that(" Collect DataFrame with complex types" , {
336336 # ArrayType
337337 df <- read.json(sqlContext , complexTypeJsonPath )
338-
339338 ldf <- collect(df )
340339 expect_equal(nrow(ldf ), 3 )
341340 expect_equal(ncol(ldf ), 3 )
@@ -490,19 +489,15 @@ test_that("insertInto() on a registered table", {
490489 unlink(parquetPath2 )
491490})
492491
493- test_that(" table () returns a new DataFrame" , {
492+ test_that(" tableToDF () returns a new DataFrame" , {
494493 df <- read.json(sqlContext , jsonPath )
495494 registerTempTable(df , " table1" )
496- tabledf <- table (sqlContext , " table1" )
495+ tabledf <- tableToDF (sqlContext , " table1" )
497496 expect_is(tabledf , " DataFrame" )
498497 expect_equal(count(tabledf ), 3 )
498+ tabledf2 <- tableToDF(sqlContext , " table1" )
499+ expect_equal(count(tabledf2 ), 3 )
499500 dropTempTable(sqlContext , " table1" )
500-
501- # nolint start
502- # Test base::table is working
503- # a <- letters[1:3]
504- # expect_equal(class(table(a, sample(a))), "table")
505- # nolint end
506501})
507502
508503test_that(" toRDD() returns an RRDD" , {
@@ -734,7 +729,7 @@ test_that("head() and first() return the correct data", {
734729 expect_equal(ncol(testFirst ), 2 )
735730})
736731
737- test_that(" distinct() and unique on DataFrames" , {
732+ test_that(" distinct(), unique() and dropDuplicates() on DataFrames" , {
738733 lines <- c(" {\" name\" :\" Michael\" }" ,
739734 " {\" name\" :\" Andy\" , \" age\" :30}" ,
740735 " {\" name\" :\" Justin\" , \" age\" :19}" ,
@@ -750,6 +745,42 @@ test_that("distinct() and unique on DataFrames", {
750745 uniques2 <- unique(df )
751746 expect_is(uniques2 , " DataFrame" )
752747 expect_equal(count(uniques2 ), 3 )
748+
749+ # Test dropDuplicates()
750+ df <- createDataFrame(
751+ sqlContext ,
752+ list (
753+ list (2 , 1 , 2 ), list (1 , 1 , 1 ),
754+ list (1 , 2 , 1 ), list (2 , 1 , 2 ),
755+ list (2 , 2 , 2 ), list (2 , 2 , 1 ),
756+ list (2 , 1 , 1 ), list (1 , 1 , 2 ),
757+ list (1 , 2 , 2 ), list (1 , 2 , 1 )),
758+ schema = c(" key" , " value1" , " value2" ))
759+ result <- collect(dropDuplicates(df ))
760+ expected <- rbind.data.frame(
761+ c(1 , 1 , 1 ), c(1 , 1 , 2 ), c(1 , 2 , 1 ),
762+ c(1 , 2 , 2 ), c(2 , 1 , 1 ), c(2 , 1 , 2 ),
763+ c(2 , 2 , 1 ), c(2 , 2 , 2 ))
764+ names(expected ) <- c(" key" , " value1" , " value2" )
765+ expect_equivalent(
766+ result [order(result $ key , result $ value1 , result $ value2 ),],
767+ expected )
768+
769+ result <- collect(dropDuplicates(df , c(" key" , " value1" )))
770+ expected <- rbind.data.frame(
771+ c(1 , 1 , 1 ), c(1 , 2 , 1 ), c(2 , 1 , 2 ), c(2 , 2 , 2 ))
772+ names(expected ) <- c(" key" , " value1" , " value2" )
773+ expect_equivalent(
774+ result [order(result $ key , result $ value1 , result $ value2 ),],
775+ expected )
776+
777+ result <- collect(dropDuplicates(df , " key" ))
778+ expected <- rbind.data.frame(
779+ c(1 , 1 , 1 ), c(2 , 1 , 2 ))
780+ names(expected ) <- c(" key" , " value1" , " value2" )
781+ expect_equivalent(
782+ result [order(result $ key , result $ value1 , result $ value2 ),],
783+ expected )
753784})
754785
755786test_that(" sample on a DataFrame" , {
0 commit comments