Skip to content

StructType

Defined in: types/struct.ts:36

Mirrors Spark’s StructType and StructField for schema inspection.

new StructType(fields?): StructType;

Defined in: types/struct.ts:39

ParameterTypeDefault value
fieldsStructField[][]

StructType

readonly fields: readonly StructField[];

Defined in: types/struct.ts:37

get fieldNames(): string[];

Defined in: types/struct.ts:49

Get field names.

string[]


get length(): number;

Defined in: types/struct.ts:59

Number of top-level fields.

number

add(
name,
dataType,
nullable?): StructType;

Defined in: types/struct.ts:44

Add a field and return a new StructType.

ParameterTypeDefault value
namestringundefined
dataTypestringundefined
nullablebooleantrue

StructType


getField(name): StructField | undefined;

Defined in: types/struct.ts:54

Look up a field by name.

ParameterType
namestring

StructField | undefined


toDDL(): string;

Defined in: types/struct.ts:85

Return a DDL-formatted schema string, e.g. “name string, age integer”. Compatible with DataFrameReader.schema().

string


toString(): string;

Defined in: types/struct.ts:77

string


treeString(): string;

Defined in: types/struct.ts:69

Pretty-print the schema in Spark’s tree format: root |— name: string (nullable = true) |— age: integer (nullable = false)

string


static fromProto(proto): StructType;

Defined in: types/struct.ts:95

Build a StructType from a Spark Connect DataType proto (schema response). The proto is a plain object with struct.fields array.

ParameterType
protoRecord<string, unknown>

StructType