forked from delta-io/delta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6db4e0
commit dff2c0f
Showing
14 changed files
with
450 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...src/main/java/io/delta/kernel/internal/tablefeatures/FeatureAutoEnablementByMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.delta.kernel.internal.tablefeatures; | ||
|
||
import io.delta.kernel.internal.actions.Metadata; | ||
import io.delta.kernel.internal.actions.Protocol; | ||
|
||
/** | ||
* Extension of {@link TableFeature} that can be automatically enabled via a change in a table's | ||
* metadata, e.g., through setting particular values of certain feature-specific table properties. | ||
* | ||
* <p>When the feature's metadata requirements are satisfied for <strong>new tables</strong>, or for | ||
* <strong>existing tables when {@link #automaticallyUpdateProtocolOfExistingTables()} set to | ||
* `true`</strong>, the client will silently add the feature to the protocol's `readerFeatures` | ||
* and/or `writerFeatures`. Otherwise, a proper protocol version bump must be present in the same | ||
* transaction. | ||
*/ | ||
public interface FeatureAutoEnablementByMetadata { | ||
/** | ||
* Whether the feature can automatically update the protocol of an existing table when the | ||
* metadata requirements are satisfied. As a rule of thumb, a table feature that requires explicit | ||
* operations (e.g., turning on a table property) should set this flag to `true`, while features | ||
* that are used implicitly (e.g., when using a new data type) should set this flag to `false`. | ||
*/ | ||
default boolean automaticallyUpdateProtocolOfExistingTables() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Determine whether the feature must be supported and enabled because its metadata requirements | ||
* are satisfied. | ||
*/ | ||
boolean metadataRequiresFeatureToBeEnabled(Protocol protocol, Metadata metadata); | ||
} |
129 changes: 129 additions & 0 deletions
129
kernel/kernel-api/src/main/java/io/delta/kernel/internal/tablefeatures/TableFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package io.delta.kernel.internal.tablefeatures; | ||
|
||
import static io.delta.kernel.internal.util.Preconditions.checkArgument; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Base class for table features. | ||
* | ||
* <p>A feature can be <b>explicitly supported</b> by a table's protocol when the protocol contains | ||
* a feature's `name`. Writers (for writer-only features) or readers and writers (for reader-writer | ||
* features) must recognize supported features and must handle them appropriately. | ||
* | ||
* <p>A table feature that released before Delta Table Features (reader version 3 and writer version | ||
* 7) is considered as a <strong>legacy feature</strong>. Legacy features are <strong> implicitly | ||
* supported</strong> when (a) the protocol does not support table features, i.e., has reader | ||
* version less than 3 or writer version less than 7 and (b) the feature's minimum reader/writer | ||
* version is less than or equal to the current protocol's reader/writer version. | ||
* | ||
* <p>Separately, a feature can be automatically supported by a table's metadata when certain | ||
* feature-specific table properties are set. For example, `changeDataFeed` is automatically | ||
* supported when there's a table property `delta.enableChangeDataFeed=true`. This is independent of | ||
* the table's enabled features. When a feature is supported (explicitly or implicitly) by the table | ||
* protocol but its metadata requirements are not satisfied, then clients still have to understand | ||
* the feature (at least to the extent that they can read and preserve the existing data in the | ||
* table that uses the feature). | ||
*/ | ||
public class TableFeature { | ||
private final String featureName; | ||
private final int minReaderVersion; | ||
private final int minWriterVersion; | ||
private final boolean readerWriterFeature; | ||
private final boolean isLegacyFeature; | ||
private final List<TableFeature> requiredFeatures; | ||
private final Optional<FeatureAutoEnablementByMetadata> featureAutoEnablementByMetadata; | ||
|
||
/** | ||
* Create a new table feature. | ||
* | ||
* @param featureName a globally-unique string indicator to represent the feature. All characters | ||
* must be letters (a-z, A-Z), digits (0-9), '-', or '_'. Words must be in camelCase. | ||
* @param minReaderVersion the minimum reader version this feature requires. For a feature that | ||
* can only be explicitly supported, this is either `0` or `3` (the reader protocol version | ||
* that supports table features), depending on the feature is writer-only or reader-writer. | ||
* For a legacy feature that can be implicitly supported, this is the first protocol version | ||
* which the feature is introduced. | ||
* @param minWriterVersion the minimum writer version this feature requires. For a feature that | ||
* can only be explicitly supported, this is the writer protocol `7` that supports table | ||
* features. For a legacy feature that can be implicitly supported, this is the first protocol | ||
* version which the feature is introduced. | ||
* @param isLegacyTableFeature this feature is a legacy feature? i.e a feature that released | ||
* before Delta Table Features (reader version 3 and writer version 7). | ||
* @param requiredFeatures Set of table features that this table feature depends on. I.e. the set | ||
* of features that need to be enabled if this table feature is enabled. | ||
*/ | ||
public TableFeature( | ||
String featureName, | ||
int minReaderVersion, | ||
int minWriterVersion, | ||
boolean readerWriterFeature, | ||
boolean isLegacyTableFeature, | ||
List<TableFeature> requiredFeatures, | ||
Optional<FeatureAutoEnablementByMetadata> featureAutoEnablementByMetadata) { | ||
this.featureName = requireNonNull(featureName, "name is null"); | ||
checkArgument(!featureName.isEmpty(), "name is empty"); | ||
checkArgument( | ||
featureName.chars().allMatch(c -> Character.isLetterOrDigit(c) || c == '-' || c == '_'), | ||
"name contains invalid characters: " + featureName); | ||
this.minReaderVersion = minReaderVersion; | ||
this.minWriterVersion = minWriterVersion; | ||
if (!readerWriterFeature) { | ||
checkArgument(minReaderVersion == 0, "Writer-only feature must have minReaderVersion=0"); | ||
} | ||
this.readerWriterFeature = readerWriterFeature; | ||
this.isLegacyFeature = isLegacyTableFeature; | ||
this.requiredFeatures = | ||
Collections.unmodifiableList(requireNonNull(requiredFeatures, "requiredFeatures is null")); | ||
this.featureAutoEnablementByMetadata = | ||
requireNonNull(featureAutoEnablementByMetadata, "featureAutoEnablementByMetadata is null"); | ||
|
||
featureAutoEnablementByMetadata.ifPresent( | ||
autoEnablementByMetadata -> { | ||
checkArgument( | ||
isLegacyFeature() | ||
&& autoEnablementByMetadata.automaticallyUpdateProtocolOfExistingTables(), | ||
"Legacy feature must be auto-update capable."); | ||
}); | ||
} | ||
/** @return the name of the table feature. */ | ||
String featureName() { | ||
return featureName; | ||
} | ||
|
||
/** | ||
* @return true if this feature is applicable to both reader and writer, false if it is | ||
* writer-only. | ||
*/ | ||
boolean isReaderWriterFeature() { | ||
return readerWriterFeature; | ||
} | ||
|
||
/** @return the minimum reader version this feature requires */ | ||
int minReaderVersion() { | ||
return minReaderVersion; | ||
} | ||
|
||
/** @return the minimum writer version that this feature requires. */ | ||
int minWriterVersion() { | ||
return minWriterVersion; | ||
} | ||
|
||
/** @return if this feature is a legacy feature? */ | ||
boolean isLegacyFeature() { | ||
return isLegacyFeature; | ||
} | ||
|
||
/** | ||
* Set of table features that this table feature depends on. I.e. the set of features that need to | ||
* be enabled if this table feature is enabled. | ||
* | ||
* @return the list of table features that this table feature depends on. | ||
*/ | ||
List<TableFeature> requiredFeatures() { | ||
return requiredFeatures; | ||
} | ||
} |
Oops, something went wrong.