@@ -108,6 +108,32 @@ test_that("create DataFrame from RDD", {
108108 expect_equal(count(df ), 10 )
109109 expect_equal(columns(df ), c(" a" , " b" ))
110110 expect_equal(dtypes(df ), list (c(" a" , " int" ), c(" b" , " string" )))
111+
112+ df <- jsonFile(sqlContext , jsonPathNa )
113+ hiveCtx <- tryCatch({
114+ newJObject(" org.apache.spark.sql.hive.test.TestHiveContext" , ssc )
115+ }, error = function (err ) {
116+ skip(" Hive is not build with SparkSQL, skipped" )
117+ })
118+ sql(hiveCtx , " CREATE TABLE people (name string, age double, height float)" )
119+ insertInto(df , " people" )
120+ expect_equal(sql(hiveCtx , " SELECT age from people WHERE name = 'Bob'" ), c(16 ))
121+ expect_equal(sql(hiveCtx , " SELECT height from people WHERE name ='Bob'" ), c(176.5 ))
122+
123+ schema <- structType(structField(" name" , " string" ), structField(" age" , " integer" ),
124+ structField(" height" , " float" ))
125+ df2 <- createDataFrame(sqlContext , df.toRDD , schema )
126+ expect_equal(columns(df2 ), c(" name" , " age" , " height" ))
127+ expect_equal(dtypes(df2 ), list (c(" name" , " string" ), c(" age" , " int" ), c(" height" , " float" )))
128+ expect_equal(collect(where(df2 , df2 $ name == " Bob" )), c(" Bob" , 16 , 176.5 ))
129+
130+ localDF <- data.frame (name = c(" John" , " Smith" , " Sarah" ), age = c(19 , 23 , 18 ), height = c(164.10 , 181.4 , 173.7 ))
131+ df <- createDataFrame(sqlContext , localDF , schema )
132+ expect_is(df , " DataFrame" )
133+ expect_equal(count(df ), 3 )
134+ expect_equal(columns(df ), c(" name" , " age" , " height" ))
135+ expect_equal(dtypes(df ), list (c(" name" , " string" ), c(" age" , " int" ), c(" height" , " float" )))
136+ expect_equal(collect(where(df , df $ name == " John" )), c(" John" , 19 , 164.10 ))
111137})
112138
113139test_that(" convert NAs to null type in DataFrames" , {
0 commit comments