Skip to content

Commit 1825f97

Browse files
authored
Add duplicate name error reproducer (#20106)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #. ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> Reproduces a duplicate name issue introduced in #19019. Reverting the following code: https://github.com/apache/datafusion/blob/2e02cc131d1d71cce819000912f0411345ca2d6e/datafusion/expr/src/expr_rewriter/mod.rs#L263-L263 From: ```rust _ => { // maintain the original name when casting let name = dst_schema.field(idx).name(); Ok(expr.cast_to(new_type, src_schema)?.alias(name)) } ``` to ```rust _ => expr.cast_to(new_type, src_schema), ``` Seems to fix the issue. TODO: actually fix the issue before merging ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> For now, just a reproducer test ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> yes, by a new test ## Are there any user-facing changes? no <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. -->
1 parent b2a6893 commit 1825f97

File tree

2 files changed

+198
-0
lines changed

2 files changed

+198
-0
lines changed

datafusion/substrait/tests/cases/logical_plans.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,31 @@ mod tests {
229229

230230
Ok(())
231231
}
232+
233+
#[tokio::test]
234+
// Test still failing, issue tracked in "https://github.com/apache/datafusion/issues/20123".
235+
#[ignore]
236+
async fn duplicate_name_in_union() -> Result<()> {
237+
let proto_plan =
238+
read_json("tests/testdata/test_plans/duplicate_name_in_union.substrait.json");
239+
let ctx = add_plan_schemas_to_ctx(SessionContext::new(), &proto_plan)?;
240+
let plan = from_substrait_plan(&ctx.state(), &proto_plan).await?;
241+
242+
assert_snapshot!(
243+
plan,
244+
@r"
245+
Projection: foo AS col1, bar AS col2
246+
Union
247+
Projection: foo, bar
248+
Values: (Int64(100), Int64(200))
249+
Projection: x, foo
250+
Values: (Int32(300), Int64(400))
251+
"
252+
);
253+
254+
// Trigger execution to ensure plan validity
255+
DataFrame::new(ctx.state(), plan).show().await?;
256+
257+
Ok(())
258+
}
232259
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
{
2+
"version": {
3+
"minorNumber": 54,
4+
"producer": "datafusion-test"
5+
},
6+
"relations": [
7+
{
8+
"root": {
9+
"input": {
10+
"set": {
11+
"common": {
12+
"direct": {}
13+
},
14+
"inputs": [
15+
{
16+
"project": {
17+
"common": {
18+
"emit": {
19+
"outputMapping": [2, 3]
20+
}
21+
},
22+
"input": {
23+
"read": {
24+
"common": {
25+
"direct": {}
26+
},
27+
"baseSchema": {
28+
"names": ["foo", "bar"],
29+
"struct": {
30+
"types": [
31+
{
32+
"i64": {
33+
"nullability": "NULLABILITY_REQUIRED"
34+
}
35+
},
36+
{
37+
"i64": {
38+
"nullability": "NULLABILITY_REQUIRED"
39+
}
40+
}
41+
],
42+
"nullability": "NULLABILITY_REQUIRED"
43+
}
44+
},
45+
"virtualTable": {
46+
"expressions": [
47+
{
48+
"fields": [
49+
{
50+
"literal": {
51+
"i64": "100"
52+
}
53+
},
54+
{
55+
"literal": {
56+
"i64": "200"
57+
}
58+
}
59+
]
60+
}
61+
]
62+
}
63+
}
64+
},
65+
"expressions": [
66+
{
67+
"selection": {
68+
"directReference": {
69+
"structField": {
70+
"field": 0
71+
}
72+
},
73+
"rootReference": {}
74+
}
75+
},
76+
{
77+
"selection": {
78+
"directReference": {
79+
"structField": {
80+
"field": 1
81+
}
82+
},
83+
"rootReference": {}
84+
}
85+
}
86+
]
87+
}
88+
},
89+
{
90+
"project": {
91+
"common": {
92+
"emit": {
93+
"outputMapping": [2, 3]
94+
}
95+
},
96+
"input": {
97+
"read": {
98+
"common": {
99+
"direct": {}
100+
},
101+
"baseSchema": {
102+
"names": ["x", "foo"],
103+
"struct": {
104+
"types": [
105+
{
106+
"i32": {
107+
"nullability": "NULLABILITY_REQUIRED"
108+
}
109+
},
110+
{
111+
"i64": {
112+
"nullability": "NULLABILITY_REQUIRED"
113+
}
114+
}
115+
],
116+
"nullability": "NULLABILITY_REQUIRED"
117+
}
118+
},
119+
"virtualTable": {
120+
"expressions": [
121+
{
122+
"fields": [
123+
{
124+
"literal": {
125+
"i32": 300
126+
}
127+
},
128+
{
129+
"literal": {
130+
"i64": "400"
131+
}
132+
}
133+
]
134+
}
135+
]
136+
}
137+
}
138+
},
139+
"expressions": [
140+
{
141+
"selection": {
142+
"directReference": {
143+
"structField": {
144+
"field": 0
145+
}
146+
},
147+
"rootReference": {}
148+
}
149+
},
150+
{
151+
"selection": {
152+
"directReference": {
153+
"structField": {
154+
"field": 1
155+
}
156+
},
157+
"rootReference": {}
158+
}
159+
}
160+
]
161+
}
162+
}
163+
],
164+
"op": "SET_OP_UNION_ALL"
165+
}
166+
},
167+
"names": ["col1", "col2"]
168+
}
169+
}
170+
]
171+
}

0 commit comments

Comments
 (0)