A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://spark.apache.org/docs/latest/api/java/org/apache/spark/sql/types/StructType.html below:

StructType (Spark 4.0.0 JavaDoc)

All Implemented Interfaces:
Serializable, scala.collection.immutable.Iterable<StructField>, scala.collection.immutable.Seq<StructField>, scala.collection.immutable.SeqOps<StructField,scala.collection.immutable.Seq,scala.collection.immutable.Seq<StructField>>, scala.collection.Iterable<StructField>, scala.collection.IterableFactoryDefaults<StructField,scala.collection.Iterable>, scala.collection.IterableOnce<StructField>, scala.collection.IterableOnceOps<StructField,scala.collection.Iterable,scala.collection.Iterable>, scala.collection.IterableOps<StructField,scala.collection.Iterable,scala.collection.Iterable>, scala.collection.Seq<StructField>, scala.collection.SeqOps<StructField,scala.collection.Seq,scala.collection.Seq<StructField>>, scala.Equals, scala.Function1<Object,StructField>, scala.PartialFunction<Object,StructField>, scala.Product

A

StructType

object can be constructed by


 StructType(fields: Seq[StructField])
 

For a

StructType

object, one or multiple

StructField

s can be extracted by names. If multiple

StructField

s 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.

Scala Example:


 import org.apache.spark.sql._
 import org.apache.spark.sql.types._

 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)

 // If this struct does not have a field called "d", it throws an exception.
 struct("d")
 // java.lang.IllegalArgumentException: d does not exist.
 //   ...

 // 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(StructField(b,LongType,false), StructField(c,BooleanType,false))

 // Any names without matching fields will throw an exception.
 // For the case shown below, an exception is thrown due to "d".
 struct(Set("b", "c", "d"))
 // java.lang.IllegalArgumentException: d does not exist.
 //    ...
 

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

Scala Example:


 import org.apache.spark.sql._
 import org.apache.spark.sql.types._

 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))
 
Since:
1.3.0
See Also:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4