-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-16792][SQL] Dataset containing a Case Class with a List type causes a CompileException (converting sequence to list) #16240
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
Changes from 4 commits
c47f189
8c15b47
b04f46e
c4c0129
96f9d9d
b530bf5
f75a8f1
21d9e97
c45bee4
efd0801
2ad7eb0
68810c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,31 +100,76 @@ abstract class SQLImplicits { | |
| // Seqs | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newIntSeqEncoder: Encoder[Seq[Int]] = ExpressionEncoder() | ||
| implicit def newIntSeqEncoder[T <: Seq[Int] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newLongSeqEncoder: Encoder[Seq[Long]] = ExpressionEncoder() | ||
| implicit def newLongSeqEncoder[T <: Seq[Long] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newDoubleSeqEncoder: Encoder[Seq[Double]] = ExpressionEncoder() | ||
| implicit def newDoubleSeqEncoder[T <: Seq[Double] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newFloatSeqEncoder: Encoder[Seq[Float]] = ExpressionEncoder() | ||
| implicit def newFloatSeqEncoder[T <: Seq[Float] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newByteSeqEncoder: Encoder[Seq[Byte]] = ExpressionEncoder() | ||
| implicit def newByteSeqEncoder[T <: Seq[Byte] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newShortSeqEncoder: Encoder[Seq[Short]] = ExpressionEncoder() | ||
| implicit def newShortSeqEncoder[T <: Seq[Short] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newBooleanSeqEncoder: Encoder[Seq[Boolean]] = ExpressionEncoder() | ||
| implicit def newBooleanSeqEncoder[T <: Seq[Boolean] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newStringSeqEncoder: Encoder[Seq[String]] = ExpressionEncoder() | ||
| implicit def newStringSeqEncoder[T <: Seq[String] : TypeTag]: Encoder[T] = ExpressionEncoder() | ||
|
|
||
| /** @since 1.6.1 */ | ||
| implicit def newProductSeqEncoder[A <: Product : TypeTag]: Encoder[Seq[A]] = ExpressionEncoder() | ||
| implicit def newProductSeqEncoder[A <: Product : TypeTag, T <: Seq[A] : TypeTag]: Encoder[T] = | ||
|
||
| ExpressionEncoder() | ||
|
|
||
| // Seqs with product (List) disambiguation | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newIntSeqWithProductEncoder[T <: Seq[Int] with Product : TypeTag]: Encoder[T] = | ||
| newIntSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newLongSeqWithProductEncoder[T <: Seq[Long] with Product : TypeTag]: Encoder[T] = | ||
| newLongSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newDoubleListEncoder[T <: Seq[Double] with Product : TypeTag]: Encoder[T] = | ||
|
||
| newDoubleSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newFloatSeqWithProductEncoder[T <: Seq[Float] with Product : TypeTag]: Encoder[T] = | ||
| newFloatSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newByteSeqWithProductEncoder[T <: Seq[Byte] with Product : TypeTag]: Encoder[T] = | ||
| newByteSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newShortSeqWithProductEncoder[T <: Seq[Short] with Product : TypeTag]: Encoder[T] = | ||
| newShortSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newBooleanSeqWithProductEncoder[T <: Seq[Boolean] with Product : TypeTag] | ||
| : Encoder[T] = | ||
| newBooleanSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newStringSeqWithProductEncoder[T <: Seq[String] with Product : TypeTag]: Encoder[T] = | ||
| newStringSeqEncoder | ||
|
|
||
| /** @since 2.2.0 */ | ||
| implicit def newProductSeqWithProductEncoder | ||
| [A <: Product : TypeTag, T <: Seq[A] with Product : TypeTag]: Encoder[T] = | ||
| newProductSeqEncoder[A, T] | ||
|
|
||
| // Workaround for implicit resolution problem for Seq.toDS (only supports Seq) | ||
| implicit def newProductSeqOnlyEncoder[A <: Product : TypeTag]: Encoder[Seq[A]] = | ||
| newProductSeqEncoder[A, Seq[A]] | ||
|
|
||
| // Arrays | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,34 @@ class DatasetPrimitiveSuite extends QueryTest with SharedSQLContext { | |
| checkDataset(Seq(Array(Tuple1(1))).toDS(), Array(Tuple1(1))) | ||
| } | ||
|
|
||
| test("arbitrary sequences") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also test nested sequences, e.g.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some sequence-product combination tests. |
||
| import scala.collection.immutable.Queue | ||
| checkDataset(Seq(Queue(1)).toDS(), Queue(1)) | ||
| checkDataset(Seq(Queue(1.toLong)).toDS(), Queue(1.toLong)) | ||
| checkDataset(Seq(Queue(1.toDouble)).toDS(), Queue(1.toDouble)) | ||
| checkDataset(Seq(Queue(1.toFloat)).toDS(), Queue(1.toFloat)) | ||
| checkDataset(Seq(Queue(1.toByte)).toDS(), Queue(1.toByte)) | ||
| checkDataset(Seq(Queue(1.toShort)).toDS(), Queue(1.toShort)) | ||
| checkDataset(Seq(Queue(true)).toDS(), Queue(true)) | ||
| checkDataset(Seq(Queue("test")).toDS(), Queue("test")) | ||
| // Implicit resolution problem - encoder needs to be provided explicitly | ||
| implicit val queueEncoder = newProductSeqEncoder[Tuple1[Int], Queue[Tuple1[Int]]] | ||
| checkDataset(Seq(Queue(Tuple1(1))).toDS(), Queue(Tuple1(1))) | ||
|
|
||
| import scala.collection.mutable.ArrayBuffer | ||
| checkDataset(Seq(ArrayBuffer(1)).toDS(), ArrayBuffer(1)) | ||
| checkDataset(Seq(ArrayBuffer(1.toLong)).toDS(), ArrayBuffer(1.toLong)) | ||
| checkDataset(Seq(ArrayBuffer(1.toDouble)).toDS(), ArrayBuffer(1.toDouble)) | ||
| checkDataset(Seq(ArrayBuffer(1.toFloat)).toDS(), ArrayBuffer(1.toFloat)) | ||
| checkDataset(Seq(ArrayBuffer(1.toByte)).toDS(), ArrayBuffer(1.toByte)) | ||
| checkDataset(Seq(ArrayBuffer(1.toShort)).toDS(), ArrayBuffer(1.toShort)) | ||
| checkDataset(Seq(ArrayBuffer(true)).toDS(), ArrayBuffer(true)) | ||
| checkDataset(Seq(ArrayBuffer("test")).toDS(), ArrayBuffer("test")) | ||
| // Implicit resolution problem - encoder needs to be provided explicitly | ||
| implicit val arrayBufferEncoder = newProductSeqEncoder[Tuple1[Int], ArrayBuffer[Tuple1[Int]]] | ||
| checkDataset(Seq(ArrayBuffer(Tuple1(1))).toDS(), ArrayBuffer(Tuple1(1))) | ||
| } | ||
|
|
||
| test("package objects") { | ||
| import packageobject._ | ||
| checkDataset(Seq(PackageClass(1)).toDS(), PackageClass(1)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spark code style discourage the usage of
TryandSuccess, can you refactor your code a little bit? i.e. movecls.getDeclaredMethod("canBuildFrom", classOf[ClassTag[_]])out of theInvokecode block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I tried looking up the code style you mentioned, but only found the Databricks' Scala Code Style Guide. And that is not mentioned in the Spark docs as far as I know.