Skip to content
Snippets Groups Projects
Commit c78e2080 authored by Jakob Odersky's avatar Jakob Odersky Committed by Michael Armbrust
Browse files

[SPARK-12816][SQL] De-alias type when generating schemas

Call `dealias` on local types to fix schema generation for abstract type members, such as

```scala
type KeyValue = (Int, String)
```

Add simple test

Author: Jakob Odersky <jodersky@gmail.com>

Closes #10749 from jodersky/aliased-schema.
parent 4dbd3161
No related branches found
No related tags found
No related merge requests found
......@@ -642,7 +642,10 @@ trait ScalaReflection {
*
* @see SPARK-5281
*/
def localTypeOf[T: TypeTag]: `Type` = typeTag[T].in(mirror).tpe
def localTypeOf[T: TypeTag]: `Type` = {
val tag = implicitly[TypeTag[T]]
tag.in(mirror).tpe.normalize
}
/** Returns a catalyst DataType and its nullability for the given Scala Type using reflection. */
def schemaFor(tpe: `Type`): Schema = ScalaReflectionLock.synchronized {
......
......@@ -69,6 +69,10 @@ case class ComplexData(
case class GenericData[A](
genericField: A)
object GenericData {
type IntData = GenericData[Int]
}
case class MultipleConstructorsData(a: Int, b: String, c: Double) {
def this(b: String, a: Int) = this(a, b, c = 1.0)
}
......@@ -186,6 +190,10 @@ class ScalaReflectionSuite extends SparkFunSuite {
nullable = true))
}
test("type-aliased data") {
assert(schemaFor[GenericData[Int]] == schemaFor[GenericData.IntData])
}
test("convert PrimitiveData to catalyst") {
val data = PrimitiveData(1, 1, 1, 1, 1, 1, true)
val convertedData = InternalRow(1, 1.toLong, 1.toDouble, 1.toFloat, 1.toShort, 1.toByte, true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment