Skip to content
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

fix: allow loading of tables with identity columns #2155

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions crates/core/src/kernel/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum MetadataValue {
Number(i32),
/// A string value
String(String),
/// A Boolean value
Boolean(bool),
}

impl From<String> for MetadataValue {
Expand All @@ -45,6 +47,12 @@ impl From<i32> for MetadataValue {
}
}

impl From<bool> for MetadataValue {
fn from(value: bool) -> Self {
Self::Boolean(value)
}
}

impl From<Value> for MetadataValue {
fn from(value: Value) -> Self {
Self::String(value.to_string())
Expand Down Expand Up @@ -184,6 +192,7 @@ impl StructField {
let phys_name = self.get_config_value(&ColumnMetadataKey::ColumnMappingPhysicalName);
match phys_name {
None => Ok(&self.name),
Some(MetadataValue::Boolean(_)) => Ok(&self.name),
Some(MetadataValue::String(s)) => Ok(s),
Some(MetadataValue::Number(_)) => Err(Error::MetadataError(
"Unexpected type for physical name".to_string(),
Expand Down Expand Up @@ -850,4 +859,11 @@ mod tests {
Invariant::new("a_map.value.element.d", "a_map.value.element.d < 4")
);
}

/// <https://github.com/delta-io/delta-rs/issues/2152>
#[test]
fn test_identity_columns() {
let buf = r#"{"type":"struct","fields":[{"name":"ID_D_DATE","type":"long","nullable":true,"metadata":{"delta.identity.start":1,"delta.identity.step":1,"delta.identity.allowExplicitInsert":false}},{"name":"TXT_DateKey","type":"string","nullable":true,"metadata":{}}]}"#;
let schema: StructType = serde_json::from_str(buf).expect("Failed to load");
}
}
9 changes: 9 additions & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,13 @@ mod tests {
DeltaTableError::InvalidTableLocation(_expected_error_msg),
))
}

/// <https://github.com/delta-io/delta-rs/issues/2152>
#[tokio::test]
async fn test_identity_column() {
let path = "../test/tests/data/issue-2152";
let _ = crate::open_table(path)
.await
.expect("Failed to load the table");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{"commitInfo":{"timestamp":1706770085847,"operation":"CREATE TABLE","operationParameters":{"partitionBy":"[]","description":null,"isManaged":"true","properties":"{}","statsOnLoad":false},"isolationLevel":"WriteSerializable","isBlindAppend":true,"operationMetrics":{},"tags":{"restoresDeletedRows":"false"},"engineInfo":"Databricks-Runtime/14.1.x-photon-scala2.12","txnId":"5ba2d1f4-09e0-4013-920a-92b057185128"}}
{"metaData":{"id":"7791991a-60e9-4a8f-bff0-ccffec779dc4","format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"ID_D_DATE\",\"type\":\"long\",\"nullable\":true,\"metadata\":{\"delta.identity.start\":1,\"delta.identity.step\":1,\"delta.identity.allowExplicitInsert\":false}},{\"name\":\"TXT_DateKey\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":[],"configuration":{},"createdTime":1706770085202}}
{"protocol":{"minReaderVersion":1,"minWriterVersion":6}}
Loading