DeltaTable¶
DeltaTable is the management interface of delta tables.
io.delta.tables Package¶
DeltaTable belongs to io.delta.tables package.
Creating Instance¶
DeltaTable takes the following to be created:
- Table Data (
Dataset[Row]) - DeltaTableV2
DeltaTable is created using DeltaTable.forPath and DeltaTable.forName utilities (and indirectly using create, createIfNotExists, createOrReplace and replace).
DeltaLog¶
DeltaLog of the DeltaTableV2.
Utilities (Static Methods)¶
columnBuilder¶
columnBuilder(
colName: String): DeltaColumnBuilder
columnBuilder(
spark: SparkSession,
colName: String): DeltaColumnBuilder
Creates a DeltaColumnBuilder
convertToDelta¶
convertToDelta(
spark: SparkSession,
identifier: String): DeltaTable
convertToDelta(
spark: SparkSession,
identifier: String,
partitionSchema: String): DeltaTable
convertToDelta(
spark: SparkSession,
identifier: String,
partitionSchema: StructType): DeltaTable
convertToDelta converts the parquet table to delta format
Note
Refer to Demo: Converting Parquet Dataset Into Delta Format for a demo of DeltaTable.convertToDelta.
create¶
Creates a DeltaTableBuilder
createIfNotExists¶
Creates a DeltaTableBuilder (with CreateTableOptions and ifNotExists flag enabled)
createOrReplace¶
Creates a DeltaTableBuilder (with ReplaceTableOptions and orCreate flag enabled)
forName¶
forName(
sparkSession: SparkSession,
tableName: String): DeltaTable
forName(
tableOrViewName: String): DeltaTable
forName uses ParserInterface (of the given SparkSession) to parse the given table name.
forName checks whether the given table name is of a Delta table and, if so, creates a DeltaTable with the following:
Datasetthat represents loading data from the specified table name (usingSparkSession.tableoperator)- DeltaTableV2
forName throws an AnalysisException when the given table name is for non-Delta table:
forPath¶
forPath checks whether the given table name is of a Delta table and, if so, creates a DeltaTable with the following:
Datasetthat represents loading data from the specifiedpathusing delta data source- DeltaTableV2
forPath throws an AnalysisException when the given path does not belong to a delta table:
isDeltaTable¶
isDeltaTable(
sparkSession: SparkSession,
identifier: String): Boolean
isDeltaTable(
identifier: String): Boolean
isDeltaTable...FIXME
replace¶
Creates a DeltaTableBuilder (with ReplaceTableOptions and orCreate flag disabled)
Operators¶
alias¶
Applies an alias to the DeltaTable (equivalent to as)
as¶
Applies an alias to the DeltaTable
delete¶
Executes DeleteFromTable command
dropFeatureSupport¶
dropFeatureSupport(
featureName: String): Unit
dropFeatureSupport(
featureName: String,
truncateHistory: Boolean): Unit
Executes the AlterTableDropFeatureDeltaCommand
generate¶
Executes the DeltaGenerateCommand
history¶
Requests the DeltaHistoryManager for history
merge¶
merge(
source: DataFrame,
condition: Column): DeltaMergeBuilder
merge(
source: DataFrame,
condition: String): DeltaMergeBuilder
Creates a DeltaMergeBuilder
optimize¶
Creates a DeltaOptimizeBuilder
restoreToTimestamp¶
restoreToVersion¶
toDF¶
Returns the DataFrame representation of the DeltaTable
update¶
updateExpr¶
updateExpr(
set: Map[String, String]): Unit
updateExpr(
condition: String,
set: Map[String, String]): Unit
upgradeTableProtocol¶
upgradeTableProtocol creates a new Protocol (for the given reader and writer versions) and requests the DeltaLog to upgrade the protocol.
Transactional Operation
upgradeTableProtocol is a transactional operation.
Updates the protocol version of the table to leverage new features.
Upgrading the reader version will prevent all clients that have an older version of Delta Lake from accessing this table.
Upgrading the writer version will prevent older versions of Delta Lake to write to this table.
The reader or writer version cannot be downgraded.
[SC-44271][DELTA] Introduce default protocol version for Delta tables
upgradeTableProtocol was introduced in [SC-44271][DELTA] Introduce default protocol version for Delta tables commit.
vacuum¶
Deletes files and directories (recursively) in the DeltaTable that are not needed by the table (and maintains older versions up to the given retention threshold).
executeDropFeature¶
executeDropFeature creates an AlterTableDropFeatureDeltaCommand for this DeltaTableV2, the given featureName and truncateHistory (if defined or false).
In the end, executeDropFeature creates a Dataset with the AlterTableDropFeatureDeltaCommand logical operator.
executeDropFeature is used when:
DeltaTableis requested to dropFeatureSupport