-
Notifications
You must be signed in to change notification settings - Fork 103
feat!: Introduce metadata column API #1266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lbhm
wants to merge
5
commits into
delta-io:main
Choose a base branch
from
lbhm:metadata-column-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,166
−432
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -68,7 +68,7 @@ pub(crate) const DOMAIN_METADATA_NAME: &str = "domainMetadata"; | |
pub(crate) const INTERNAL_DOMAIN_PREFIX: &str = "delta."; | ||
|
||
static LOG_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| { | ||
Arc::new(StructType::new([ | ||
Arc::new(StructType::new_unchecked([ | ||
StructField::nullable(ADD_NAME, Add::to_schema()), | ||
StructField::nullable(REMOVE_NAME, Remove::to_schema()), | ||
StructField::nullable(METADATA_NAME, Metadata::to_schema()), | ||
|
@@ -83,28 +83,28 @@ static LOG_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| { | |
}); | ||
|
||
static LOG_ADD_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| { | ||
Arc::new(StructType::new([StructField::nullable( | ||
Arc::new(StructType::new_unchecked([StructField::nullable( | ||
ADD_NAME, | ||
Add::to_schema(), | ||
)])) | ||
}); | ||
|
||
static LOG_COMMIT_INFO_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| { | ||
Arc::new(StructType::new([StructField::nullable( | ||
Arc::new(StructType::new_unchecked([StructField::nullable( | ||
COMMIT_INFO_NAME, | ||
CommitInfo::to_schema(), | ||
)])) | ||
}); | ||
|
||
static LOG_TXN_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| { | ||
Arc::new(StructType::new([StructField::nullable( | ||
Arc::new(StructType::new_unchecked([StructField::nullable( | ||
SET_TRANSACTION_NAME, | ||
SetTransaction::to_schema(), | ||
)])) | ||
}); | ||
|
||
static LOG_DOMAIN_METADATA_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| { | ||
Arc::new(StructType::new([StructField::nullable( | ||
Arc::new(StructType::new_unchecked([StructField::nullable( | ||
DOMAIN_METADATA_NAME, | ||
DomainMetadata::to_schema(), | ||
)])) | ||
|
@@ -137,7 +137,9 @@ pub(crate) fn get_log_domain_metadata_schema() -> &'static SchemaRef { | |
/// This is useful for JSON conversion, as it allows us to wrap a dynamically maintained add action | ||
/// schema in a top-level "add" struct. | ||
pub(crate) fn as_log_add_schema(schema: SchemaRef) -> SchemaRef { | ||
Arc::new(StructType::new([StructField::nullable(ADD_NAME, schema)])) | ||
Arc::new(StructType::new_unchecked([StructField::nullable( | ||
ADD_NAME, schema, | ||
)])) | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, ToSchema)] | ||
|
@@ -174,7 +176,7 @@ impl TryFrom<Format> for Scalar { | |
) | ||
.map(Scalar::Map)?; | ||
Ok(Scalar::Struct(StructData::try_new( | ||
Format::to_schema().fields().cloned().collect(), | ||
Format::to_schema().into_fields().collect(), | ||
vec![provider, options], | ||
)?)) | ||
} | ||
|
@@ -188,6 +190,7 @@ impl TryFrom<Format> for Scalar { | |
)] | ||
#[internal_api] | ||
pub(crate) struct Metadata { | ||
// TODO: Make the struct fields private to force using the try_new function. | ||
/// Unique identifier for this table | ||
pub(crate) id: String, | ||
/// User-provided identifier for this table | ||
|
@@ -217,6 +220,16 @@ impl Metadata { | |
created_time: i64, | ||
configuration: HashMap<String, String>, | ||
) -> DeltaResult<Self> { | ||
// Validate that the schema does not contain metadata columns | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to enforce that we never leak metadata columns into the Delta log. |
||
// Note: We don't have to look for nested metadata columns because that is already validated | ||
// when creating a StructType. | ||
if let Some(metadata_field) = schema.fields().find(|field| field.is_metadata_column()) { | ||
return Err(Error::Schema(format!( | ||
"Table schema must not contain metadata columns. Found metadata column: '{}'", | ||
metadata_field.name | ||
))); | ||
} | ||
|
||
Ok(Self { | ||
id: uuid::Uuid::new_v4().to_string(), | ||
name, | ||
|
@@ -991,15 +1004,15 @@ mod tests { | |
.project(&[METADATA_NAME]) | ||
.expect("Couldn't get metaData field"); | ||
|
||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"metaData", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("id", DataType::STRING), | ||
StructField::nullable("name", DataType::STRING), | ||
StructField::nullable("description", DataType::STRING), | ||
StructField::not_null( | ||
"format", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("provider", DataType::STRING), | ||
StructField::not_null( | ||
"options", | ||
|
@@ -1025,9 +1038,9 @@ mod tests { | |
.project(&[ADD_NAME]) | ||
.expect("Couldn't get add field"); | ||
|
||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"add", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("path", DataType::STRING), | ||
StructField::not_null( | ||
"partitionValues", | ||
|
@@ -1067,7 +1080,7 @@ mod tests { | |
fn deletion_vector_field() -> StructField { | ||
StructField::nullable( | ||
"deletionVector", | ||
DataType::struct_type([ | ||
DataType::struct_type_unchecked([ | ||
StructField::not_null("storageType", DataType::STRING), | ||
StructField::not_null("pathOrInlineDv", DataType::STRING), | ||
StructField::nullable("offset", DataType::INTEGER), | ||
|
@@ -1082,9 +1095,9 @@ mod tests { | |
let schema = get_log_schema() | ||
.project(&[REMOVE_NAME]) | ||
.expect("Couldn't get remove field"); | ||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"remove", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("path", DataType::STRING), | ||
StructField::nullable("deletionTimestamp", DataType::LONG), | ||
StructField::not_null("dataChange", DataType::BOOLEAN), | ||
|
@@ -1105,9 +1118,9 @@ mod tests { | |
let schema = get_log_schema() | ||
.project(&[CDC_NAME]) | ||
.expect("Couldn't get cdc field"); | ||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"cdc", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("path", DataType::STRING), | ||
StructField::not_null( | ||
"partitionValues", | ||
|
@@ -1126,9 +1139,9 @@ mod tests { | |
let schema = get_log_schema() | ||
.project(&[SIDECAR_NAME]) | ||
.expect("Couldn't get sidecar field"); | ||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"sidecar", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("path", DataType::STRING), | ||
StructField::not_null("sizeInBytes", DataType::LONG), | ||
StructField::not_null("modificationTime", DataType::LONG), | ||
|
@@ -1143,9 +1156,9 @@ mod tests { | |
let schema = get_log_schema() | ||
.project(&[CHECKPOINT_METADATA_NAME]) | ||
.expect("Couldn't get checkpointMetadata field"); | ||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"checkpointMetadata", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("version", DataType::LONG), | ||
tags_field(), | ||
]), | ||
|
@@ -1159,9 +1172,9 @@ mod tests { | |
.project(&["txn"]) | ||
.expect("Couldn't get transaction field"); | ||
|
||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"txn", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("appId", DataType::STRING), | ||
StructField::not_null("version", DataType::LONG), | ||
StructField::nullable("lastUpdated", DataType::LONG), | ||
|
@@ -1176,9 +1189,9 @@ mod tests { | |
.project(&["commitInfo"]) | ||
.expect("Couldn't get commitInfo field"); | ||
|
||
let expected = Arc::new(StructType::new(vec![StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked(vec![StructField::nullable( | ||
"commitInfo", | ||
StructType::new(vec![ | ||
StructType::new_unchecked(vec![ | ||
StructField::nullable("timestamp", DataType::LONG), | ||
StructField::nullable("inCommitTimestamp", DataType::LONG), | ||
StructField::nullable("operation", DataType::STRING), | ||
|
@@ -1199,9 +1212,9 @@ mod tests { | |
let schema = get_log_schema() | ||
.project(&[DOMAIN_METADATA_NAME]) | ||
.expect("Couldn't get domainMetadata field"); | ||
let expected = Arc::new(StructType::new([StructField::nullable( | ||
let expected = Arc::new(StructType::new_unchecked([StructField::nullable( | ||
"domainMetadata", | ||
StructType::new([ | ||
StructType::new_unchecked([ | ||
StructField::not_null("domain", DataType::STRING), | ||
StructField::not_null("configuration", DataType::STRING), | ||
StructField::not_null("removed", DataType::BOOLEAN), | ||
|
@@ -1526,7 +1539,7 @@ mod tests { | |
|
||
#[test] | ||
fn test_metadata_try_new() { | ||
let schema = StructType::new([StructField::not_null("id", DataType::INTEGER)]); | ||
let schema = StructType::new_unchecked([StructField::not_null("id", DataType::INTEGER)]); | ||
let config = HashMap::from([("key1".to_string(), "value1".to_string())]); | ||
|
||
let metadata = Metadata::try_new( | ||
|
@@ -1551,7 +1564,7 @@ mod tests { | |
|
||
#[test] | ||
fn test_metadata_try_new_default() { | ||
let schema = StructType::new([StructField::not_null("id", DataType::INTEGER)]); | ||
let schema = StructType::new_unchecked([StructField::not_null("id", DataType::INTEGER)]); | ||
let metadata = Metadata::try_new(None, None, schema, vec![], 0, HashMap::new()).unwrap(); | ||
|
||
assert!(!metadata.id.is_empty()); | ||
|
@@ -1561,7 +1574,7 @@ mod tests { | |
|
||
#[test] | ||
fn test_metadata_unique_ids() { | ||
let schema = StructType::new([StructField::not_null("id", DataType::INTEGER)]); | ||
let schema = StructType::new_unchecked([StructField::not_null("id", DataType::INTEGER)]); | ||
let m1 = Metadata::try_new(None, None, schema.clone(), vec![], 0, HashMap::new()).unwrap(); | ||
let m2 = Metadata::try_new(None, None, schema, vec![], 0, HashMap::new()).unwrap(); | ||
assert_ne!(m1.id, m2.id); | ||
|
@@ -1648,7 +1661,7 @@ mod tests { | |
#[test] | ||
fn test_metadata_into_engine_data() { | ||
let engine = ExprEngine::new(); | ||
let schema = StructType::new([StructField::not_null("id", DataType::INTEGER)]); | ||
let schema = StructType::new_unchecked([StructField::not_null("id", DataType::INTEGER)]); | ||
|
||
let test_metadata = Metadata::try_new( | ||
Some("test".to_string()), | ||
|
@@ -1699,7 +1712,7 @@ mod tests { | |
#[test] | ||
fn test_metadata_with_log_schema() { | ||
let engine = ExprEngine::new(); | ||
let schema = StructType::new([StructField::not_null("id", DataType::INTEGER)]); | ||
let schema = StructType::new_unchecked([StructField::not_null("id", DataType::INTEGER)]); | ||
|
||
let metadata = Metadata::try_new( | ||
Some("table".to_string()), | ||
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metadata
is too often constructed directly across the codebase, so I would rather address this in a follow-up PR than make this PR bigger.