Skip to content

Commit eca7d04

Browse files
committed
Add two apply methods which will be used to extract StructField(s) from a StructType.
1 parent 949d6bb commit eca7d04

File tree

1 file changed

+9
-0
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/types

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,15 @@ object StructType {
292292
case class StructType(fields: Seq[StructField]) extends DataType {
293293
require(StructType.validateFields(fields), "Found fields with the same name.")
294294

295+
def apply(name: String): StructField = {
296+
fields.find(f => f.name == name).orNull
297+
}
298+
299+
def apply(names: String*): StructType = {
300+
val nameSet = names.toSet
301+
StructType(fields.filter(f => nameSet.contains(f.name)))
302+
}
303+
295304
def toAttributes = fields.map(f => AttributeReference(f.name, f.dataType, f.nullable)())
296305

297306
def schemaString: String = {

0 commit comments

Comments
 (0)