Skip to content

Commit

Permalink
fix(python, rust): use from_name during column projection creation (#…
Browse files Browse the repository at this point in the history
…2441)

# Description
@Blajda I don't think `from_qualified_name_ignore_case` was needed here
since the delta_fields don't have relation information, they are just
the column names.

`from_qualified_name_ignore_case` will try to parse `__delta_rs_c_y--1`
and results into `__delta_rs_c_y`, while `from_name `just keeps the
column name as-is, which is preferred.


# Related Issue(s)
- closes #2438
  • Loading branch information
ion-elgreco authored Apr 23, 2024
1 parent 15abe44 commit da6ed7b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 2 additions & 4 deletions crates/core/src/operations/merge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1218,10 +1218,8 @@ async fn execute(
.end()?;

let name = "__delta_rs_c_".to_owned() + delta_field.name();
write_projection.push(
Expr::Column(Column::from_qualified_name_ignore_case(name.clone()))
.alias(delta_field.name()),
);
write_projection
.push(Expr::Column(Column::from_name(name.clone())).alias(delta_field.name()));
new_columns.push((name, case));
}

Expand Down
24 changes: 24 additions & 0 deletions python/tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,3 +855,27 @@ def test_merge_timestamps_partitioned_2344(tmp_path: pathlib.Path, timezone, pre
assert last_action["operation"] == "MERGE"
assert result == data
assert last_action["operationParameters"].get("predicate") == predicate


def test_merge_field_special_characters_delete_2438(tmp_path: pathlib.Path):
## See issue: https://github.com/delta-io/delta-rs/issues/2438
data = pa.table({"x": [1, 2, 3], "y--1": [4, 5, 6]})
write_deltalake(tmp_path, data, mode="append")

dt = DeltaTable(tmp_path)
new_data = pa.table({"x": [2, 3]})

(
dt.merge(
source=new_data,
predicate="target.x = source.x",
source_alias="source",
target_alias="target",
)
.when_matched_delete()
.execute()
)

expected = pa.table({"x": [1], "y--1": [4]})

assert dt.to_pyarrow_table() == expected

0 comments on commit da6ed7b

Please sign in to comment.