org.apache.spark.sql.types
Class StructType

Object
  extended by org.apache.spark.sql.types.DataType
      extended by org.apache.spark.sql.types.StructType
All Implemented Interfaces:
java.io.Serializable, scala.collection.generic.FilterMonadic<StructField,scala.collection.Seq<StructField>>, scala.collection.generic.GenericTraversableTemplate<StructField,scala.collection.Seq>, scala.collection.generic.HasNewBuilder<StructField,scala.collection.Seq<StructField>>, scala.collection.GenIterable<StructField>, scala.collection.GenIterableLike<StructField,scala.collection.Seq<StructField>>, scala.collection.GenSeq<StructField>, scala.collection.GenSeqLike<StructField,scala.collection.Seq<StructField>>, scala.collection.GenTraversable<StructField>, scala.collection.GenTraversableLike<StructField,scala.collection.Seq<StructField>>, scala.collection.GenTraversableOnce<StructField>, scala.collection.Iterable<StructField>, scala.collection.IterableLike<StructField,scala.collection.Seq<StructField>>, scala.collection.Parallelizable<StructField,scala.collection.parallel.ParSeq<StructField>>, scala.collection.Seq<StructField>, scala.collection.SeqLike<StructField,scala.collection.Seq<StructField>>, scala.collection.Traversable<StructField>, scala.collection.TraversableLike<StructField,scala.collection.Seq<StructField>>, scala.collection.TraversableOnce<StructField>, scala.Equals, scala.Function1<Object,StructField>, scala.PartialFunction<Object,StructField>, scala.Product

public class StructType
extends DataType
implements scala.collection.Seq<StructField>, scala.Product, scala.Serializable

:: DeveloperApi :: A StructType object can be constructed by


 StructType(fields: Seq[StructField])
 
For a StructType object, one or multiple StructFields can be extracted by names. If multiple StructFields are extracted, a StructType object will be returned. If a provided name does not have a matching field, it will be ignored. For the case of extracting a single StructField, a null will be returned. Example:

 import org.apache.spark.sql._

 val struct =
   StructType(
     StructField("a", IntegerType, true) ::
     StructField("b", LongType, false) ::
     StructField("c", BooleanType, false) :: Nil)

 // Extract a single StructField.
 val singleField = struct("b")
 // singleField: StructField = StructField(b,LongType,false)

 // This struct does not have a field called "d". null will be returned.
 val nonExisting = struct("d")
 // nonExisting: StructField = null

 // Extract multiple StructFields. Field names are provided in a set.
 // A StructType object will be returned.
 val twoFields = struct(Set("b", "c"))
 // twoFields: StructType =
 //   StructType(List(StructField(b,LongType,false), StructField(c,BooleanType,false)))

 // Any names without matching fields will be ignored.
 // For the case shown below, "d" will be ignored and
 // it is treated as struct(Set("b", "c")).
 val ignoreNonExisting = struct(Set("b", "c", "d"))
 // ignoreNonExisting: StructType =
 //   StructType(List(StructField(b,LongType,false), StructField(c,BooleanType,false)))
 

A Row object is used as a value of the StructType. Example:


 import org.apache.spark.sql._

 val innerStruct =
   StructType(
     StructField("f1", IntegerType, true) ::
     StructField("f2", LongType, false) ::
     StructField("f3", BooleanType, false) :: Nil)

 val struct = StructType(
   StructField("a", innerStruct, true) :: Nil)

 // Create a Row with the schema defined by struct
 val row = Row(Row(1, 2, true))
 // row: Row = {@link 1,2,true}
 

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface scala.PartialFunction
scala.PartialFunction.AndThen<A,B,C>, scala.PartialFunction.Lifted<A,B>, scala.PartialFunction.OrElse<A,B>, scala.PartialFunction.Unlifted<A,B>
 
Nested classes/interfaces inherited from interface scala.collection.SeqLike
scala.collection.SeqLike.CombinationsItr, scala.collection.SeqLike.PermutationsItr
 
Nested classes/interfaces inherited from interface scala.collection.TraversableLike
scala.collection.TraversableLike.WithFilter
 
Nested classes/interfaces inherited from interface scala.collection.TraversableOnce
scala.collection.TraversableOnce.BufferedCanBuildFrom<A,Coll extends scala.collection.TraversableOnce<Object>>, scala.collection.TraversableOnce.FlattenOps<A>, scala.collection.TraversableOnce.ForceImplicitAmbiguity, scala.collection.TraversableOnce.MonadOps<A>, scala.collection.TraversableOnce.OnceCanBuildFrom<A>
 
Constructor Summary
StructType(StructField[] fields)
           
 
Method Summary
 StructField apply(int fieldIndex)
           
 StructType apply(scala.collection.immutable.Set<String> names)
          Returns a StructType containing StructFields of the given names, preserving the original order of fields.
 StructField apply(String name)
          Extracts a StructField of the given name.
 int defaultSize()
          The default size of a value of the StructType is the total default sizes of all field types.
 int fieldIndex(String name)
          Returns index of a given field
 String[] fieldNames()
          Returns all field names in an array.
 StructField[] fields()
           
 scala.collection.Iterator<StructField> iterator()
           
 int length()
           
 void printTreeString()
           
 String simpleString()
          Readable string representation for the type.
 String treeString()
           
 
Methods inherited from class org.apache.spark.sql.types.DataType
fromCaseClassString, fromJson, json, prettyJson, typeName
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface scala.collection.Seq
companion, seq
 
Methods inherited from interface scala.PartialFunction
andThen, applyOrElse, isDefinedAt, lift, orElse, runWith
 
Methods inherited from interface scala.Function1
andThen$mcDD$sp, andThen$mcDF$sp, andThen$mcDI$sp, andThen$mcDJ$sp, andThen$mcFD$sp, andThen$mcFF$sp, andThen$mcFI$sp, andThen$mcFJ$sp, andThen$mcID$sp, andThen$mcIF$sp, andThen$mcII$sp, andThen$mcIJ$sp, andThen$mcJD$sp, andThen$mcJF$sp, andThen$mcJI$sp, andThen$mcJJ$sp, andThen$mcVD$sp, andThen$mcVF$sp, andThen$mcVI$sp, andThen$mcVJ$sp, andThen$mcZD$sp, andThen$mcZF$sp, andThen$mcZI$sp, andThen$mcZJ$sp, apply, apply$mcDD$sp, apply$mcDF$sp, apply$mcDI$sp, apply$mcDJ$sp, apply$mcFD$sp, apply$mcFF$sp, apply$mcFI$sp, apply$mcFJ$sp, apply$mcID$sp, apply$mcIF$sp, apply$mcII$sp, apply$mcIJ$sp, apply$mcJD$sp, apply$mcJF$sp, apply$mcJI$sp, apply$mcJJ$sp, apply$mcVD$sp, apply$mcVF$sp, apply$mcVI$sp, apply$mcVJ$sp, apply$mcZD$sp, apply$mcZF$sp, apply$mcZI$sp, apply$mcZJ$sp, compose, compose$mcDD$sp, compose$mcDF$sp, compose$mcDI$sp, compose$mcDJ$sp, compose$mcFD$sp, compose$mcFF$sp, compose$mcFI$sp, compose$mcFJ$sp, compose$mcID$sp, compose$mcIF$sp, compose$mcII$sp, compose$mcIJ$sp, compose$mcJD$sp, compose$mcJF$sp, compose$mcJI$sp, compose$mcJJ$sp, compose$mcVD$sp, compose$mcVF$sp, compose$mcVI$sp, compose$mcVJ$sp, compose$mcZD$sp, compose$mcZF$sp, compose$mcZI$sp, compose$mcZJ$sp, toString
 
Methods inherited from interface scala.collection.SeqLike
$colon$plus, $plus$colon, combinations, contains, containsSlice, corresponds, diff, distinct, endsWith, indexOfSlice, indexOfSlice, indexWhere, indices, intersect, isEmpty, lastIndexOfSlice, lastIndexOfSlice, lastIndexWhere, lengthCompare, padTo, parCombiner, patch, permutations, reverse, reverseIterator, reverseMap, segmentLength, size, sortBy, sorted, sortWith, startsWith, thisCollection, toCollection, toSeq, toString, union, updated, view, view
 
Methods inherited from interface scala.collection.IterableLike
canEqual, copyToArray, drop, dropRight, exists, find, foldRight, forall, foreach, grouped, head, reduceRight, sameElements, slice, sliding, sliding, take, takeRight, takeWhile, toIterable, toIterator, toStream, zip, zipAll, zipWithIndex
 
Methods inherited from interface scala.collection.TraversableLike
$plus$plus, $plus$plus$colon, $plus$plus$colon, collect, dropWhile, filter, filterNot, flatMap, groupBy, hasDefiniteSize, headOption, init, inits, isTraversableAgain, last, lastOption, map, partition, repr, scan, scanLeft, scanRight, sliceWithKnownBound, sliceWithKnownDelta, span, splitAt, stringPrefix, tail, tails, to, toTraversable, withFilter
 
Methods inherited from interface scala.collection.TraversableOnce
$colon$bslash, $div$colon, addString, addString, addString, aggregate, collectFirst, copyToArray, copyToArray, copyToBuffer, count, fold, foldLeft, max, maxBy, min, minBy, mkString, mkString, mkString, nonEmpty, product, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRightOption, reversed, sum, toArray, toBuffer, toIndexedSeq, toList, toMap, toSet, toVector
 
Methods inherited from interface scala.collection.GenSeqLike
equals, hashCode, indexOf, indexOf, indexWhere, isDefinedAt, lastIndexOf, lastIndexOf, lastIndexWhere, prefixLength, startsWith
 
Methods inherited from interface scala.collection.GenTraversableOnce
$div$colon$bslash
 
Methods inherited from interface scala.collection.Parallelizable
par
 
Methods inherited from interface scala.Product
productArity, productElement, productIterator, productPrefix
 

Constructor Detail

StructType

public StructType(StructField[] fields)
Method Detail

fields

public StructField[] fields()

fieldNames

public String[] fieldNames()
Returns all field names in an array.


apply

public StructField apply(String name)
Extracts a StructField of the given name. If the StructType object does not have a name matching the given name, null will be returned.

Parameters:
name - (undocumented)
Returns:
(undocumented)

apply

public StructType apply(scala.collection.immutable.Set<String> names)
Returns a StructType containing StructFields of the given names, preserving the original order of fields. Those names which do not have matching fields will be ignored.

Parameters:
names - (undocumented)
Returns:
(undocumented)

fieldIndex

public int fieldIndex(String name)
Returns index of a given field

Parameters:
name - (undocumented)
Returns:
(undocumented)

treeString

public String treeString()

printTreeString

public void printTreeString()

apply

public StructField apply(int fieldIndex)
Specified by:
apply in interface scala.collection.GenSeqLike<StructField,scala.collection.Seq<StructField>>
Specified by:
apply in interface scala.collection.SeqLike<StructField,scala.collection.Seq<StructField>>

length

public int length()
Specified by:
length in interface scala.collection.GenSeqLike<StructField,scala.collection.Seq<StructField>>
Specified by:
length in interface scala.collection.SeqLike<StructField,scala.collection.Seq<StructField>>

iterator

public scala.collection.Iterator<StructField> iterator()
Specified by:
iterator in interface scala.collection.GenIterableLike<StructField,scala.collection.Seq<StructField>>
Specified by:
iterator in interface scala.collection.IterableLike<StructField,scala.collection.Seq<StructField>>

defaultSize

public int defaultSize()
The default size of a value of the StructType is the total default sizes of all field types.

Specified by:
defaultSize in class DataType
Returns:
(undocumented)

simpleString

public String simpleString()
Description copied from class: DataType
Readable string representation for the type.

Overrides:
simpleString in class DataType