c

io.delta.tables

DeltaTableBuilder

class DeltaTableBuilder extends AnyRef

Evolving API

Builder to specify how to create / replace a Delta table. You must specify the table name or the path before executing the builder. You can specify the table columns, the partitioning columns, the location of the data, the table comment and the property, and how you want to create / replace the Delta table.

After executing the builder, an instance of DeltaTable is returned.

Scala example to create a Delta table with generated columns, using the table name:

val table: DeltaTable = DeltaTable.create()
  .tableName("testTable")
  .addColumn("c1",  dataType = "INT", nullable = false)
  .addColumn(
    DeltaTable.columnBuilder("c2")
      .dataType("INT")
      .generatedAlwaysAs("c1 + 10")
      .build()
  )
  .addColumn(
    DeltaTable.columnBuilder("c3")
      .dataType("INT")
      .comment("comment")
      .nullable(true)
      .build()
  )
  .partitionedBy("c1", "c2")
  .execute()

Scala example to create a delta table using the location:

val table: DeltaTable = DeltaTable.createIfNotExists(spark)
  .location("/foo/`bar`")
  .addColumn("c1", dataType = "INT", nullable = false)
  .addColumn(
    DeltaTable.columnBuilder(spark, "c2")
      .dataType("INT")
      .generatedAlwaysAs("c1 + 10")
      .build()
  )
  .addColumn(
    DeltaTable.columnBuilder(spark, "c3")
      .dataType("INT")
      .comment("comment")
      .nullable(true)
      .build()
  )
  .partitionedBy("c1", "c2")
  .execute()

Java Example to replace a table:

DeltaTable table = DeltaTable.replace()
  .tableName("db.table")
  .addColumn("c1",  "INT", false)
  .addColumn(
    DeltaTable.columnBuilder("c2")
      .dataType("INT")
      .generatedAlwaysBy("c1 + 10")
      .build()
  )
  .execute();
Annotations
@Evolving()
Since

1.0.0

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DeltaTableBuilder
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. def Evolving API addColumn(col: StructField): DeltaTableBuilder

    Specify a column.

    col

    structField the column struct

    Annotations
    @Evolving()
    Since

    1.0.0

  2. def Evolving API addColumn(colName: String, dataType: DataType, nullable: Boolean): DeltaTableBuilder

    Specify a column.

    colName

    string the column name

    dataType

    dataType the DDL data type

    nullable

    boolean whether the column is nullable

    Annotations
    @Evolving()
    Since

    1.0.0

  3. def Evolving API addColumn(colName: String, dataType: String, nullable: Boolean): DeltaTableBuilder

    Specify a column.

    colName

    string the column name

    dataType

    string the DDL data type

    nullable

    boolean whether the column is nullable

    Annotations
    @Evolving()
    Since

    1.0.0

  4. def Evolving API addColumn(colName: String, dataType: DataType): DeltaTableBuilder

    Specify a column.

    colName

    string the column name

    dataType

    dataType the DDL data type

    Annotations
    @Evolving()
    Since

    1.0.0

  5. def Evolving API addColumn(colName: String, dataType: String): DeltaTableBuilder

    Specify a column.

    colName

    string the column name

    dataType

    string the DDL data type

    Annotations
    @Evolving()
    Since

    1.0.0

  6. def Evolving API addColumns(cols: StructType): DeltaTableBuilder

    Specify columns with an existing schema.

    cols

    structType the existing schema for columns

    Annotations
    @Evolving()
    Since

    1.0.0

  7. def Evolving API comment(comment: String): DeltaTableBuilder

    Specify the table comment to describe the table.

    comment

    string table comment

    Annotations
    @Evolving()
    Since

    1.0.0

  8. def Evolving API execute(): DeltaTable

    Execute the command to create / replace a Delta table and returns a instance of DeltaTable.

    Annotations
    @Evolving()
    Since

    1.0.0

  9. def Evolving API location(location: String): DeltaTableBuilder

    Specify the path to the directory where table data is stored, which could be a path on distributed storage.

    location

    string the data location

    Annotations
    @Evolving()
    Since

    1.0.0

  10. def Evolving API partitionedBy(colNames: String*): DeltaTableBuilder

    Specify the columns to partition the output on the file system.

    Note: This should only include table columns already defined in schema.

    colNames

    string* column names for partitioning

    Annotations
    @Evolving() @varargs()
    Since

    1.0.0

  11. def Evolving API property(key: String, value: String): DeltaTableBuilder

    Specify a key-value pair to tag the table definition.

    key

    string the table property key

    value

    string the table property value

    Annotations
    @Evolving()
    Since

    1.0.0

  12. def Evolving API tableName(identifier: String): DeltaTableBuilder

    Specify the table name, optionally qualified with a database name [database_name.] table_name

    identifier

    string the table name

    Annotations
    @Evolving()
    Since

    1.0.0