GitHub user HyukjinKwon opened a pull request:

    https://github.com/apache/spark/pull/15361

    [SPARK-17765][SQL] Support for writing out user-defined type in ORC 
datasource

    ## What changes were proposed in this pull request?
    
    `OrcStruct` is being created based on string from`DataType.catalogString`. 
For user-defined type, it seems it returns `sqlType.simpleString` for 
`catalogString` by default[1]. However, during type-dispatching to match the 
output with the schema, it tries to cast to, for example, `StructType`[2]. 
    
    So, running the codes below (`MyDenseVector` was borrowed[3]) :
    
    ```scala
    val data = Seq((1, new UDT.MyDenseVector(Array(0.25, 2.25, 4.25))))
    val udtDF = data.toDF("id", "vectors")
    udtDF.write.orc("/tmp/test.orc")
    ```
    
    ends up throwing an exception as below:
    
    ```
    java.lang.ClassCastException: org.apache.spark.sql.UDT$MyDenseVectorUDT 
cannot be cast to org.apache.spark.sql.types.ArrayType
        at 
org.apache.spark.sql.hive.HiveInspectors$class.wrapperFor(HiveInspectors.scala:381)
        at 
org.apache.spark.sql.hive.orc.OrcSerializer.wrapperFor(OrcFileFormat.scala:164)
    ...
    ```
    
    
[1]https://github.com/apache/spark/blob/dfdcab00c7b6200c22883baa3ebc5818be09556f/sql/catalyst/src/main/scala/org/apache/spark/sql/types/UserDefinedType.scala#L95
    
[2]https://github.com/apache/spark/blob/d2dc8c4a162834818190ffd82894522c524ca3e5/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveInspectors.scala#L326
    
[3]https://github.com/apache/spark/blob/2bfed1a0c5be7d0718fd574a4dad90f4f6b44be7/sql/core/src/test/scala/org/apache/spark/sql/UserDefinedTypeSuite.scala#L38-L70
    
    ## How was this patch tested?
    
    Unit tests in `OrcQuerySuite`.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/HyukjinKwon/spark SPARK-17765

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/15361.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #15361
    
----
commit 948a5ca6204460bda0eeefc85ca326c626a707f8
Author: hyukjinkwon <[email protected]>
Date:   2016-10-05T10:27:54Z

    Support for writing out user-defined type in ORC datasource

----


---
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