Skip to content

Commit 3fa0df5

Browse files
committed
Provide easier ways to construct a StructType.
1 parent 16be3e5 commit 3fa0df5

File tree

1 file changed

+7
-3
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types

1 file changed

+7
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types/dataTypes.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,18 @@ case class StructField(name: String, dataType: DataType, nullable: Boolean) {
273273
}
274274

275275
object StructType {
276-
def fromAttributes(attributes: Seq[Attribute]): StructType = {
276+
def fromAttributes(attributes: Seq[Attribute]): StructType =
277277
StructType(attributes.map(a => StructField(a.name, a.dataType, a.nullable)))
278-
}
279278

280279
private def validateFields(fields: Seq[StructField]): Boolean =
281280
fields.map(field => field.name).distinct.size == fields.size
282281

283-
// def apply(fields: Seq[StructField]) = new StructType(fields.toIndexedSeq)
282+
def apply[A <: String: ClassTag, B <: DataType: ClassTag](fields: (A, B)*): StructType =
283+
StructType(fields.map(field => StructField(field._1, field._2, true)))
284+
285+
def apply[A <: String: ClassTag, B <: DataType: ClassTag, C <: Boolean: ClassTag](
286+
fields: (A, B, C)*): StructType =
287+
StructType(fields.map(field => StructField(field._1, field._2, field._3)))
284288
}
285289

286290
case class StructType(fields: Seq[StructField]) extends DataType {

0 commit comments

Comments
 (0)