public final class StructType extends DataType
fieldName
to dataType
pairs).StructField
Constructor and Description |
---|
StructType() |
StructType(StructField[] fields) |
Modifier and Type | Method and Description |
---|---|
StructType |
add(String fieldName,
DataType dataType)
Creates a new
StructType by adding a new nullable field with no metadata. |
StructType |
add(String fieldName,
DataType dataType,
boolean nullable)
Creates a new
StructType by adding a new field with no metadata. |
StructType |
add(StructField field)
Creates a new
StructType by adding a new field. |
Column |
column(String fieldName)
Creates a
Column expression for the field with the given fieldName . |
boolean |
equals(Object o) |
StructField |
get(String fieldName) |
String[] |
getFieldNames() |
StructField[] |
getFields() |
String |
getTreeString() |
int |
hashCode() |
boolean |
isWriteCompatible(StructType newSchema)
Whether a new schema can replace this existing schema in a Delta table without rewriting data
files in the table.
|
int |
length() |
equivalent, fromJson, getCatalogString, getSimpleString, getTypeName, toJson, toPrettyJson
public StructType()
public StructType(StructField[] fields)
public StructType add(StructField field)
StructType
by adding a new field.
StructType schema = new StructType()
.add(new StructField("a", new IntegerType(), true))
.add(new StructField("b", new LongType(), false))
.add(new StructField("c", new StringType(), true))
field
- The new field to add.public StructType add(String fieldName, DataType dataType)
StructType
by adding a new nullable field with no metadata.
StructType schema = new StructType()
.add("a", new IntegerType())
.add("b", new LongType())
.add("c", new StringType())
fieldName
- The name of the new field.dataType
- The datatype for the new field.public StructType add(String fieldName, DataType dataType, boolean nullable)
StructType
by adding a new field with no metadata.
StructType schema = new StructType()
.add("a", new IntegerType(), true)
.add("b", new LongType(), false)
.add("c", new StringType(), true)
fieldName
- The name of the new field.dataType
- The datatype for the new field.nullable
- Whether or not the new field is nullable.public StructField[] getFields()
public String[] getFieldNames()
public int length()
public StructField get(String fieldName)
fieldName
- the name of the desired StructField
, not nullIllegalArgumentException
- if a field with the given name does not existpublic Column column(String fieldName)
Column
expression for the field with the given fieldName
.fieldName
- the name of the StructField
to create a column forpublic String getTreeString()
public boolean isWriteCompatible(StructType newSchema)
Returns false if the new schema:
newSchema
- the new schema to update the table with