spark-instrumented-optimizer/R/pkg/inst/tests/testthat
wm624@hotmail.com 0f30cdedbd [SPARK-16883][SPARKR] SQL decimal type is not properly cast to number when collecting SparkDataFrame
## What changes were proposed in this pull request?

(Please fill in changes proposed in this fix)

registerTempTable(createDataFrame(iris), "iris")
str(collect(sql("select cast('1' as double) as x, cast('2' as decimal) as y  from iris limit 5")))

'data.frame':	5 obs. of  2 variables:
 $ x: num  1 1 1 1 1
 $ y:List of 5
  ..$ : num 2
  ..$ : num 2
  ..$ : num 2
  ..$ : num 2
  ..$ : num 2

The problem is that spark returns `decimal(10, 0)` col type, instead of `decimal`. Thus, `decimal(10, 0)` is not handled correctly. It should be handled as "double".

As discussed in JIRA thread, we can have two potential fixes:
1). Scala side fix to add a new case when writing the object back; However, I can't use spark.sql.types._ in Spark core due to dependency issues. I don't find a way of doing type case match;

2). SparkR side fix: Add a helper function to check special type like `"decimal(10, 0)"` and replace it with `double`, which is PRIMITIVE type. This special helper is generic for adding new types handling in the future.

I open this PR to discuss pros and cons of both approaches. If we want to do Scala side fix, we need to find a way to match the case of DecimalType and StructType in Spark Core.

## How was this patch tested?

(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)

Manual test:
> str(collect(sql("select cast('1' as double) as x, cast('2' as decimal) as y  from iris limit 5")))
'data.frame':	5 obs. of  2 variables:
 $ x: num  1 1 1 1 1
 $ y: num  2 2 2 2 2
R Unit tests

Author: wm624@hotmail.com <wm624@hotmail.com>

Closes #14613 from wangmiao1981/type.
2016-09-02 01:47:17 -07:00
..
jarTest.R [SPARK-10683][SPARK-16510][SPARKR] Move SparkR include jar test to SparkSubmitSuite 2016-07-19 19:28:08 -07:00
packageInAJarTest.R [SPARKR][MINOR] R examples and test updates 2016-07-13 13:33:34 -07:00
test_binary_function.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_binaryFile.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_broadcast.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_client.R [MINOR] [SPARKR] Update data-manipulation.R to use native csv reader 2016-05-09 09:58:36 -07:00
test_context.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_includePackage.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_jvm_api.R [SPARK-16581][SPARKR] Fix JVM API tests in SparkR 2016-08-31 16:56:41 -07:00
test_mllib.R [SPARK-17241][SPARKR][MLLIB] SparkR spark.glm should have configurable regularization parameter 2016-08-31 21:39:31 -07:00
test_parallelize_collect.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_rdd.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_Serde.R [SPARK-16027][SPARKR] Fix R tests SparkSession init/stop 2016-07-17 19:02:21 -07:00
test_shuffle.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_sparkSQL.R [SPARK-16883][SPARKR] SQL decimal type is not properly cast to number when collecting SparkDataFrame 2016-09-02 01:47:17 -07:00
test_take.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_textFile.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_utils.R [SPARK-16519][SPARKR] Handle SparkR RDD generics that create warnings in R CMD check 2016-08-16 11:19:18 -07:00
test_Windows.R [SPARK-8603][SPARKR] Use shell() instead of system2() for SparkR on Windows 2016-05-26 20:55:06 -07:00