Skip to content

[SQL] support udt to hive types conversion (hive->udt is not supported) #3164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ object HiveMetastoreTypes extends RegexParsers {
case d: DecimalType => HiveShim.decimalMetastoreString(d)
case TimestampType => "timestamp"
case NullType => "void"
case udt: UserDefinedType[_] => toMetastoreType(udt.sqlType)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, should this place first? just as in ScalaReflection

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering doesn't matter here. I put it to the last so people know that it won't change any existing behavior.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package org.apache.spark.sql.hive

import org.scalatest.FunSuite

import org.apache.spark.sql.catalyst.types.{DataType, StructType}
import org.apache.spark.sql.catalyst.types.StructType
import org.apache.spark.sql.test.ExamplePointUDT

class HiveMetastoreCatalogSuite extends FunSuite {

Expand All @@ -29,4 +30,10 @@ class HiveMetastoreCatalogSuite extends FunSuite {
val datatype = HiveMetastoreTypes.toDataType(metastr)
assert(datatype.isInstanceOf[StructType])
}

test("udt to metastore type conversion") {
val udt = new ExamplePointUDT
assert(HiveMetastoreTypes.toMetastoreType(udt) ===
HiveMetastoreTypes.toMetastoreType(udt.sqlType))
}
}