Skip to content

Commit

Permalink
Add two apply methods which will be used to extract StructField(s) fr…
Browse files Browse the repository at this point in the history
…om a StructType.
  • Loading branch information
yhuai committed Jul 11, 2014
1 parent 949d6bb commit eca7d04
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ object StructType {
case class StructType(fields: Seq[StructField]) extends DataType {
require(StructType.validateFields(fields), "Found fields with the same name.")

def apply(name: String): StructField = {
fields.find(f => f.name == name).orNull
}

def apply(names: String*): StructType = {
val nameSet = names.toSet
StructType(fields.filter(f => nameSet.contains(f.name)))
}

def toAttributes = fields.map(f => AttributeReference(f.name, f.dataType, f.nullable)())

def schemaString: String = {
Expand Down

0 comments on commit eca7d04

Please sign in to comment.