Skip to content

Commit 3bcd274

Browse files
Revert: feat!: error on surplus columns in output schema (#1520)
1 parent 4e536f9 commit 3bcd274

File tree

4 files changed

+7
-123
lines changed

4 files changed

+7
-123
lines changed

ffi/src/transaction/write_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub unsafe extern "C" fn get_write_schema(
4343
write_context: Handle<SharedWriteContext>,
4444
) -> Handle<SharedSchema> {
4545
let write_context = unsafe { write_context.as_ref() };
46-
write_context.logical_schema().clone().into()
46+
write_context.schema().clone().into()
4747
}
4848

4949
/// Get write path from WriteContext handle.

kernel/src/engine/arrow_expression/evaluate_expression.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ fn evaluate_struct_expression(
102102
batch: &RecordBatch,
103103
output_schema: &StructType,
104104
) -> DeltaResult<ArrayRef> {
105-
if fields.len() != output_schema.num_fields() {
106-
return Err(Error::generic(format!(
107-
"Struct expression field count mismatch: {} fields in expression but {} in schema",
108-
fields.len(),
109-
output_schema.num_fields()
110-
)));
111-
}
112-
113105
let output_cols: Vec<ArrayRef> = fields
114106
.iter()
115107
.zip(output_schema.fields())
@@ -939,49 +931,6 @@ mod tests {
939931
.contains("Data type is required"));
940932
}
941933

942-
#[test]
943-
fn test_struct_expression_schema_validation() {
944-
let batch = create_test_batch();
945-
946-
let test_cases = vec![
947-
(
948-
"too many schema fields",
949-
Expr::Struct(vec![column_expr_ref!("a"), column_expr_ref!("b")]),
950-
StructType::new_unchecked(vec![
951-
StructField::not_null("a", DataType::INTEGER),
952-
StructField::not_null("b", DataType::INTEGER),
953-
StructField::not_null("c", DataType::INTEGER),
954-
]),
955-
),
956-
(
957-
"too few schema fields",
958-
Expr::Struct(vec![
959-
column_expr_ref!("a"),
960-
column_expr_ref!("b"),
961-
column_expr_ref!("c"),
962-
]),
963-
StructType::new_unchecked(vec![
964-
StructField::not_null("a", DataType::INTEGER),
965-
StructField::not_null("b", DataType::INTEGER),
966-
]),
967-
),
968-
];
969-
970-
for (name, expr, schema) in test_cases {
971-
let result =
972-
evaluate_expression(&expr, &batch, Some(&DataType::Struct(Box::new(schema))));
973-
assert!(result.is_err(), "Test case '{}' should fail", name);
974-
assert!(
975-
result
976-
.unwrap_err()
977-
.to_string()
978-
.contains("field count mismatch"),
979-
"Test case '{}' should contain 'field count mismatch' error",
980-
name
981-
);
982-
}
983-
}
984-
985934
#[test]
986935
fn test_coalesce_arrays_same_type() {
987936
// Test with Int32 arrays

kernel/src/engine/default/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<E: TaskExecutor> DefaultEngine<E> {
9999
) -> DeltaResult<Box<dyn EngineData>> {
100100
let transform = write_context.logical_to_physical();
101101
let input_schema = Schema::try_from_arrow(data.record_batch().schema())?;
102-
let output_schema = write_context.physical_schema();
102+
let output_schema = write_context.schema();
103103
let logical_to_physical_expr = self.evaluation_handler().new_expression_evaluator(
104104
input_schema.into(),
105105
transform.clone(),

kernel/src/transaction/mod.rs

Lines changed: 5 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -555,23 +555,9 @@ impl Transaction {
555555
let target_dir = self.read_snapshot.table_root();
556556
let snapshot_schema = self.read_snapshot.schema();
557557
let logical_to_physical = self.generate_logical_to_physical();
558-
559-
// Compute physical schema: exclude partition columns since they're stored in the path
560-
let partition_columns = self
561-
.read_snapshot
562-
.table_configuration()
563-
.metadata()
564-
.partition_columns();
565-
let physical_fields = snapshot_schema
566-
.fields()
567-
.filter(|f| !partition_columns.contains(f.name()))
568-
.cloned();
569-
let physical_schema = Arc::new(StructType::new_unchecked(physical_fields));
570-
571558
WriteContext::new(
572559
target_dir.clone(),
573560
snapshot_schema,
574-
physical_schema,
575561
Arc::new(logical_to_physical),
576562
)
577563
}
@@ -886,22 +872,15 @@ impl Transaction {
886872
/// [`Transaction`]: struct.Transaction.html
887873
pub struct WriteContext {
888874
target_dir: Url,
889-
logical_schema: SchemaRef,
890-
physical_schema: SchemaRef,
875+
schema: SchemaRef,
891876
logical_to_physical: ExpressionRef,
892877
}
893878

894879
impl WriteContext {
895-
fn new(
896-
target_dir: Url,
897-
logical_schema: SchemaRef,
898-
physical_schema: SchemaRef,
899-
logical_to_physical: ExpressionRef,
900-
) -> Self {
880+
fn new(target_dir: Url, schema: SchemaRef, logical_to_physical: ExpressionRef) -> Self {
901881
WriteContext {
902882
target_dir,
903-
logical_schema,
904-
physical_schema,
883+
schema,
905884
logical_to_physical,
906885
}
907886
}
@@ -910,12 +889,8 @@ impl WriteContext {
910889
&self.target_dir
911890
}
912891

913-
pub fn logical_schema(&self) -> &SchemaRef {
914-
&self.logical_schema
915-
}
916-
917-
pub fn physical_schema(&self) -> &SchemaRef {
918-
&self.physical_schema
892+
pub fn schema(&self) -> &SchemaRef {
893+
&self.schema
919894
}
920895

921896
pub fn logical_to_physical(&self) -> ExpressionRef {
@@ -1132,44 +1107,4 @@ mod tests {
11321107

11331108
Ok(())
11341109
}
1135-
1136-
#[test]
1137-
fn test_physical_schema_excludes_partition_columns() -> Result<(), Box<dyn std::error::Error>> {
1138-
let engine = SyncEngine::new();
1139-
let path = std::fs::canonicalize(PathBuf::from("./tests/data/basic_partitioned/")).unwrap();
1140-
let url = url::Url::from_directory_path(path).unwrap();
1141-
let snapshot = Snapshot::builder_for(url).build(&engine).unwrap();
1142-
let txn = snapshot
1143-
.transaction(Box::new(FileSystemCommitter::new()))?
1144-
.with_engine_info("default engine");
1145-
1146-
let write_context = txn.get_write_context();
1147-
let logical_schema = write_context.logical_schema();
1148-
let physical_schema = write_context.physical_schema();
1149-
1150-
// Logical schema should include the partition column
1151-
assert!(
1152-
logical_schema.contains("letter"),
1153-
"Logical schema should contain partition column 'letter'"
1154-
);
1155-
1156-
// Physical schema should exclude the partition column
1157-
assert!(
1158-
!physical_schema.contains("letter"),
1159-
"Physical schema should not contain partition column 'letter' (stored in path)"
1160-
);
1161-
1162-
// Both should contain the non-partition columns
1163-
assert!(
1164-
logical_schema.contains("number"),
1165-
"Logical schema should contain data column 'number'"
1166-
);
1167-
1168-
assert!(
1169-
physical_schema.contains("number"),
1170-
"Physical schema should contain data column 'number'"
1171-
);
1172-
1173-
Ok(())
1174-
}
11751110
}

0 commit comments

Comments
 (0)