You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@orc.apache.org by GitBox <gi...@apache.org> on 2022/08/29 03:51:55 UTC

[GitHub] [orc] sinkinben commented on issue #1237: The result is strange when casting `string` to `date` in ORC reading via spark (Schema Evolution)

sinkinben commented on issue #1237:
URL: https://github.com/apache/orc/issues/1237#issuecomment-1229729122

   Hi, @dongjoon-hyun , many thx for you reply.
   
   I have made more tests after I set the conf `spark.sql.orc.impl`.
   
   ```shell
   scala> :paste
   // Entering paste mode (ctrl-D to finish)
   
   val data = Seq(
       ("", "2002-01-01"),
       ("", "2022-08-29"),
       ("", "2022-08-31")
   )
   val cols = Seq("str", "date_str")
   val df=spark.createDataFrame(data).toDF(cols:_*).repartition(1)
   df.printSchema()
   df.show(100)
   df.write.mode("overwrite").orc("/tmp/orc/data.orc")
   
   // Exiting paste mode, now interpreting.
   
   root
    |-- str: string (nullable = true)
    |-- date_str: string (nullable = true)
   
   +---+----------+
   |str|  date_str|
   +---+----------+
   |   |2002-01-01|
   |   |2022-08-29|
   |   |2022-08-31|
   +---+----------+
   
   data: Seq[(String, String)] = List(("",2002-01-01), ("",2022-08-29), ("",2022-08-31))
   cols: Seq[String] = List(str, date_str)
   df: org.apache.spark.sql.Dataset[org.apache.spark.sql.Row] = [str: string, date_str: string]
   
   scala> sql("set spark.sql.orc.impl=hive")
   res1: org.apache.spark.sql.DataFrame = [key: string, value: string]
   
   scala> var df = spark.read.schema("date_str date").orc("/tmp/orc/data.orc"); df.show()
   +--------+
   |date_str|
   +--------+
   |    null|
   |    null|
   |    null|
   +--------+
   
   df: org.apache.spark.sql.DataFrame = [date_str: date]
   ```
   
   These three cases are valid date, but why are they converted to `null`s?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@orc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org