Github user CHOIJAEHONG1 commented on the pull request:
https://github.com/apache/spark/pull/7494#issuecomment-124172706
Adding a zero doesn't solve the problem either. It seems to have the same
effect as the one without it.
But, the below works in which the locale is "C", not UTF-8.
I set test strings' encoding to UTF-8 and conver them to the native form
with enc2native(). The testcase passed.
Also, It is not necessary to use the convertToNative() under UTF-8 locale.
The testcase passed without it.
```
readString <- function(con) {
stringLen <- readInt(con)
raw <- readBin(con, raw(), stringLen, endian = "big")
string <- rawToChar(raw)
Encoding(string) <- "UTF-8"
enc2native(string)
}
```
```
convertToNative <- function(s) {
Encoding(s) <- "UTF-8"
enc2native(s)
}
test_that("collect() support Unicode characters", {
lines <- c("{\"name\":\"ìë
íì¸ì\"}",
"{\"name\":\"æ¨å¥½\", \"age\":30}",
"{\"name\":\"ããã«ã¡ã¯\", \"age\":19}",
"{\"name\":\"Xin chà o\"}")
jsonPath <- tempfile(pattern="sparkr-test", fileext=".tmp")
writeLines(lines, jsonPath)
df <- read.df(sqlContext, jsonPath, "json")
rdf <- collect(df)
print(head(rdf))
print(convertToNative("ìë
íì¸ì"))
expect_true(is.data.frame(rdf))
expect_equal(rdf$name[1], convertToNative("ìë
íì¸ì"))
expect_equal(rdf$name[2], convertToNative("æ¨å¥½"))
expect_equal(rdf$name[3], convertToNative("ããã«ã¡ã¯"))
expect_equal(rdf$name[4], convertToNative("Xin chà o"))
df1 <- createDataFrame(sqlContext, rdf)
print(head(df1))
expect_equal(collect(where(df1, df1$name ==
convertToNative("æ¨å¥½")))$name, convertToNative("æ¨å¥½"))
})
```
```
$) export LC_ALL=C
$) ./run-tests.sh
```
```
SparkSQL functions : age name
1 NA <U+C548><U+B155><U+D558><U+C138><U+C694>
2 30 <U+60A8><U+597D>
3 19 <U+3053><U+3093><U+306B><U+3061><U+306F>
4 NA Xin ch<U+00E0>o
[1] "<U+C548><U+B155><U+D558><U+C138><U+C694>"
..... age name
1 NA <U+C548><U+B155><U+D558><U+C138><U+C694>
2 30 <U+60A8><U+597D>
3 19 <U+3053><U+3093><U+306B><U+3061><U+306F>
4 NA Xin ch<U+00E0>o
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]