Skip to content

Commit

Permalink
Support for writing out user-defined type in ORC datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
HyukjinKwon committed Oct 5, 2016
1 parent 89516c1 commit 948a5ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
Expand Up @@ -246,6 +246,9 @@ private[hive] trait HiveInspectors {
* Wraps with Hive types based on object inspector.
*/
protected def wrapperFor(oi: ObjectInspector, dataType: DataType): Any => Any = oi match {
case _ if dataType.isInstanceOf[UserDefinedType[_]] =>
val sqlType = dataType.asInstanceOf[UserDefinedType[_]].sqlType
wrapperFor(oi, sqlType)
case x: ConstantObjectInspector =>
(o: Any) =>
x.getWritableConstantValue
Expand Down
Expand Up @@ -91,6 +91,16 @@ class OrcQuerySuite extends QueryTest with BeforeAndAfterAll with OrcTest {
}
}

test("Read/write UserDefinedType") {
withTempPath { path =>
val data = Seq((1, new UDT.MyDenseVector(Array(0.25, 2.25, 4.25))))
val udtDF = data.toDF("id", "vectors")
udtDF.write.orc(path.getAbsolutePath)
val readBack = spark.read.schema(udtDF.schema).orc(path.getAbsolutePath)
checkAnswer(udtDF, readBack)
}
}

test("Creating case class RDD table") {
val data = (1 to 100).map(i => (i, s"val_$i"))
sparkContext.parallelize(data).toDF().createOrReplaceTempView("t")
Expand Down

0 comments on commit 948a5ca

Please sign in to comment.