Protocol¶
Protocol is an Action with TableFeatureSupport.
Creating Instance¶
Protocol takes the following to be created:
- Minimum Reader Version required to read this delta table
- Minimum Writer Version required to write to this delta table.
- Reader features that need to be supported to read this delta table (optional)
- Writer features that need to be supported to write to this delta table (optional)
Protocol is created using apply and forTableFeature factories.
Create Protocol¶
apply(
minReaderVersion: Int = Action.readerVersion,
minWriterVersion: Int = Action.writerVersion): Protocol
apply creates a Protocol for the given minReaderVersion and minWriterVersion.
apply supportsReaderFeatures and supportsWriterFeatures to initialize readerFeatures and writerFeatures.
apply is used when:
OptimisticTransactionImplis requested to updateMetadataInternalTableFeatureis requested to minProtocolVersionActionis requested to protocolVersionProtocolis requested to forNewTable, minProtocolComponentsFromMetadata, upgradeProtocolFromMetadataForExistingTableTableFeatureSupportis requested to denormalized, merge, normalizedCloneTableBaseis requested to determineTargetProtocolCloneConvertedSourceis requested to protocolCreateDeltaTableCommandis requested to handleCreateTableRowTrackingBackfillCommandis requested to upgradeProtocolIfRequiredCDCReaderImplis requested to isCDCEnabledOnTable
forTableFeature¶
forTableFeature...FIXME
forTableFeature is used when:
IcebergCompatBaseis requested toenforceInvariantsAndDependencies
forNewTable¶
forNewTable creates a new Protocol for the given SparkSession and Metadata.
forNewTable is used when:
OptimisticTransactionImplis requested to updateMetadataInternalDummySnapshotis requested for theprotocol
checkProtocolRequirements¶
checkProtocolRequirements(
spark: SparkSession,
metadata: Metadata,
current: Protocol): Option[Protocol]
checkProtocolRequirements asserts that the table configuration does not contain delta.minReaderVersion or throws an AssertionError:
checkProtocolRequirements asserts that the table configuration does not contain delta.minWriterVersion or throws an AssertionError:
checkProtocolRequirements determines the required minimum protocol.
checkProtocolRequirements...FIXME
checkProtocolRequirements is used when:
OptimisticTransactionImplis requested to verify a new metadata
Required Minimum Protocol¶
requiredMinimumProtocol creates a Protocol with 0 for the minimum reader and writer versions.
requiredMinimumProtocol tracks features used (in featuresUsed).
requiredMinimumProtocol determines the required minimum Protocol checking for the following features (in order):
- Column-Level Invariants
- Append Only Table
- CHECK Constraints
- Generated Columns
- Change Data Feed
- IDENTITY Columns (Unsupported)
- Column Mapping
In the end, requiredMinimumProtocol returns the required Protocol and the features used.
requiredMinimumProtocol is used when:
Protocolis requested for a new Protocol and checkProtocolRequirements
Column Invariants¶
requiredMinimumProtocol checks for column-level invariants (in the schema of the given Metadata).
If used, requiredMinimumProtocol sets the minWriterVersion to 2.
Append-Only Table¶
requiredMinimumProtocol reads appendOnly table property (from the table configuration of the given Metadata).
If set, requiredMinimumProtocol creates a new Protocol with the minWriterVersion to be 3.
CHECK Constraints¶
requiredMinimumProtocol checks for CHECK constraints (in the given Metadata).
If used, requiredMinimumProtocol creates a new Protocol with the minWriterVersion to be 3.
Generated Columns¶
requiredMinimumProtocol checks for generated columns (in the schema of the given Metadata).
If used, requiredMinimumProtocol creates a new Protocol with the minWriterVersion to be 4.
Change Data Feed¶
requiredMinimumProtocol checks whether delta.enableChangeDataFeed table property is enabled (in the given Metadata).
If enabled, requiredMinimumProtocol creates a new Protocol with the minWriterVersion to be 4.
IDENTITY Columns (Unsupported)¶
requiredMinimumProtocol checks for identity columns (in the schema of the given Metadata).
If used, requiredMinimumProtocol creates a new Protocol with the minWriterVersion to be 6.
AnalysisException
In the end, requiredMinimumProtocol throws an AnalysisException:
Column Mapping¶
requiredMinimumProtocol checks for column mapping (in the given Metadata).
If used, requiredMinimumProtocol creates a new Protocol.
extractAutomaticallyEnabledFeatures¶
extractAutomaticallyEnabledFeatures(
spark: SparkSession,
metadata: Metadata,
protocol: Option[Protocol] = None): Set[TableFeature]
extractAutomaticallyEnabledFeatures requests the given Protocol for the writerFeatureNames (protocol-enabled table features).
extractAutomaticallyEnabledFeatures finds FeatureAutomaticallyEnabledByMetadatas features (among the allSupportedFeaturesMap) that metadataRequiresFeatureToBeEnabled for the given Metadata (metadata-enabled table features)
In the end, extractAutomaticallyEnabledFeatures finds the smallest set of table features for the protocol- and metadata-enabled table features (incl. their dependencies, if there are any).
extractAutomaticallyEnabledFeatures is used when:
DeltaLogis requested to assertTableFeaturesMatchMetadataProtocolis requested to minProtocolComponentsFromMetadata and minProtocolComponentsFromAutomaticallyEnabledFeaturesCloneConvertedSourceis requested for the Protocol
minProtocolComponentsFromMetadata¶
minProtocolComponentsFromMetadata(
spark: SparkSession,
metadata: Metadata): (Int, Int, Set[TableFeature])
minProtocolComponentsFromMetadata...FIXME
minProtocolComponentsFromMetadata is used when:
Protocolis requested to forNewTableCloneTableBaseis requested to determineTargetProtocol
upgradeProtocolFromMetadataForExistingTable¶
upgradeProtocolFromMetadataForExistingTable(
spark: SparkSession,
metadata: Metadata): (Int, Int, Set[TableFeature])
upgradeProtocolFromMetadataForExistingTable...FIXME
upgradeProtocolFromMetadataForExistingTable is used when:
OptimisticTransactionImplis requested to setNewProtocolWithFeaturesEnabledByMetadata
minProtocolComponentsFromAutomaticallyEnabledFeatures¶
minProtocolComponentsFromAutomaticallyEnabledFeatures(
spark: SparkSession,
metadata: Metadata): (Int, Int, Set[TableFeature])
minProtocolComponentsFromAutomaticallyEnabledFeatures determines the minimum reader and writer versions based on automatically enabled table features.
Demo¶
import org.apache.spark.sql.delta.actions.{Metadata, Protocol}
import org.apache.spark.sql.delta.DeltaConfigs
val configuration = Map(
DeltaConfigs.IS_APPEND_ONLY.key -> "true") // (1)!
val metadata = Metadata(configuration = configuration)
val protocol = Protocol.forNewTable(spark, metadata)
- Append-only table