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]

Reply via email to