Skip to content

Commit 8db3244

Browse files
committed
schema also needs to support float. add test case.
1 parent 0dcc992 commit 8db3244

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

R/pkg/R/schema.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ structField.character <- function(x, type, nullable = TRUE) {
123123
}
124124
options <- c("byte",
125125
"integer",
126+
"float",
126127
"double",
127128
"numeric",
128129
"character",

R/pkg/inst/tests/test_sparkSQL.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ 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+
localDF <- data.frame(name=c("John", "Smith", "Sarah"), age=c(19, 23, 18), height=c(164.10, 181.4, 173.7))
113+
schema <- structType(structField("name", "string"), structField("age", "integer"), structField("height", "float"))
114+
df <- createDataFrame(sqlContext, localDF, schema)
115+
expect_is(df, "DataFrame")
116+
expect_equal(count(df), 3)
117+
expect_equal(columns(df), c("name", "age", "height"))
118+
expect_equal(dtypes(df), list(c("name", "string"), c("age", "double"), c("height", "double")))
111119
})
112120

113121
test_that("convert NAs to null type in DataFrames", {

sql/core/src/main/scala/org/apache/spark/sql/api/r/SQLUtils.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ private[r] object SQLUtils {
4747
dataType match {
4848
case "byte" => org.apache.spark.sql.types.ByteType
4949
case "integer" => org.apache.spark.sql.types.IntegerType
50+
case "float" => org.apache.spark.sql.types.FloatType
5051
case "double" => org.apache.spark.sql.types.DoubleType
5152
case "numeric" => org.apache.spark.sql.types.DoubleType
5253
case "character" => org.apache.spark.sql.types.StringType

0 commit comments

Comments
 (0)