Welcome to Delta Lake’s Python documentation page¶
DeltaTable¶
- class delta.tables.DeltaTable(spark: SparkSession, jdt: JavaObject)¶
Main class for programmatically interacting with Delta tables. You can create DeltaTable instances using the path of the Delta table.:
deltaTable = DeltaTable.forPath(spark, "/path/to/table")
In addition, you can convert an existing Parquet table in place into a Delta table.:
deltaTable = DeltaTable.convertToDelta(spark, "parquet.`/path/to/table`")
Added in version 0.4.
- toDF() DataFrame¶
Get a DataFrame representation of this Delta table.
Added in version 0.4.
- alias(aliasName: str) DeltaTable¶
Apply an alias to the Delta table.
Added in version 0.4.
- generate(mode: str) None¶
Generate manifest files for the given delta table.
- Parameters:
mode –
mode for the type of manifest file to be generated The valid modes are as follows (not case sensitive):
- ”symlink_format_manifest”: This will generate manifests in symlink format
for Presto and Athena read support.
See the online documentation for more information.
Added in version 0.5.
- delete(condition: Column | str | None = None) None¶
Delete data from the table that match the given
condition.Example:
deltaTable.delete("date < '2017-01-01'") # predicate using SQL formatted string deltaTable.delete(col("date") < "2017-01-01") # predicate using Spark SQL functions
- Parameters:
condition (str or pyspark.sql.Column) – condition of the update
Added in version 0.4.
- update(condition: str | Column, set: Dict[str, str | Column]) None¶
- update(*, set: Dict[str, str | Column]) None
Update data from the table on the rows that match the given
condition, which performs the rules defined byset.Example:
# condition using SQL formatted string deltaTable.update( condition = "eventType = 'clck'", set = { "eventType": "'click'" } ) # condition using Spark SQL functions deltaTable.update( condition = col("eventType") == "clck", set = { "eventType": lit("click") } )
- Parameters:
condition (str or pyspark.sql.Column) – Optional condition of the update
set (dict with str as keys and str or pyspark.sql.Column as values) – Defines the rules of setting the values of columns that need to be updated. Note: This param is required. Default value None is present to allow positional args in same order across languages.
Added in version 0.4.
- merge(source: DataFrame, condition: str | Column) DeltaMergeBuilder¶
Merge data from the source DataFrame based on the given merge condition. This returns a
DeltaMergeBuilderobject that can be used to specify the update, delete, or insert actions to be performed on rows based on whether the rows matched the condition or not. SeeDeltaMergeBuilderfor a full description of this operation and what combinations of update, delete and insert operations are allowed.Example 1 with conditions and update expressions as SQL formatted string:
deltaTable.alias("events").merge( source = updatesDF.alias("updates"), condition =