Skip to content

DeltaColumnBuilder

DeltaColumnBuilder is a builder interface to create columns programmatically.

DeltaColumnBuilder is created using DeltaTable.columnBuilder utility.

In the end, DeltaColumnBuilder is supposed to be built.

io.delta.tables Package

DeltaColumnBuilder belongs to io.delta.tables package.

import io.delta.tables.DeltaColumnBuilder

Creating Instance

DeltaColumnBuilder takes the following to be created:

Operators

Build StructField

build(): StructField

Creates a StructField (Spark SQL) (possibly with some field metadata)

comment

comment(
  comment: String): DeltaColumnBuilder

dataType

dataType(
  dataType: DataType): DeltaColumnBuilder
dataType(
  dataType: String): DeltaColumnBuilder

generatedAlwaysAs

generatedAlwaysAs(
  expr: String): DeltaColumnBuilder

Registers the Generation Expression of this field

generatedAlwaysAsIdentity

generatedAlwaysAsIdentity(): DeltaColumnBuilder // (1)!
generatedAlwaysAsIdentity(
  start: Long,
  step: Long): DeltaColumnBuilder
  1. Uses the defaults

Sets the following:

Property Value Default Value
identityStart start 1
identityStep step 1
identityAllowExplicitInsert false (undefined)

generatedByDefaultAsIdentity

generatedByDefaultAsIdentity(): DeltaColumnBuilder // (1)!
generatedByDefaultAsIdentity(
  start: Long,
  step: Long): DeltaColumnBuilder
  1. Uses the defaults

Sets the following:

Property Value Default Value
identityStart start 1
identityStep step 1
identityAllowExplicitInsert true (undefined)

nullable

nullable(
  nullable: Boolean): DeltaColumnBuilder

Generation Expression

generationExpr: Option[String] = None

DeltaColumnBuilder uses generationExpr internal registry for the generatedAlwaysAs expression.

When requested to build a StructField, DeltaColumnBuilder registers generationExpr under delta.generationExpression key in the metadata (of this field).

identityAllowExplicitInsert

identityAllowExplicitInsert: Option[Boolean] = None

identityAllowExplicitInsert flag is used to indicate a call to the following methods:

Method Value
generatedAlwaysAsIdentity false
generatedByDefaultAsIdentity true

identityAllowExplicitInsert is used to build a StructField.