Commit 16e578d
authored
Unify cast handling by removing
## Which issue does this PR close?
* Part of #20164
---
## Rationale for this change
Downstream components in DataFusion currently branch on both `CastExpr`
and `CastColumnExpr`, even though they represent equivalent semantics
after recent cast unification work. This duplication increases
maintenance burden, introduces unnecessary complexity, and raises the
risk of inconsistent behavior when evolving cast-related logic.
This PR simplifies downstream logic by collapsing these dual branches
into a single `CastExpr`-based handling path, aligning with the broader
cast unification effort.
---
## What changes are included in this PR?
* **Removed `CastColumnExpr` handling in downstream logic**:
* Eliminated branching specific to `CastColumnExpr` in:
* `equivalence/properties/mod.rs`
* `pruning/pruning_predicate.rs`
* **Unified cast substitution logic in ordering equivalence**:
* Replaced `substitute_cast_like_ordering` with
`substitute_cast_ordering`
* Simplified implementation to only consider `CastExpr`
* Preserved correctness by ensuring:
* Exact child expression match
* Order-preserving (widening) casts only
* **Refactored pruning rewrite logic**:
* Introduced helper: `rewrite_cast_child_to_prunable`
* Removed duplicated validation and recursion logic across cast types
* Updated both `CastExpr` and `TryCastExpr` handling to reuse the helper
* **Test updates and cleanup**:
* Updated tests to use `CastExpr::new_with_target_field`
* Simplified test cases by removing vector-based equality conditions
* Removed obsolete test covering `CastColumnExpr`
* Renamed pruning test to reflect unified cast handling
* **Minor code cleanups**:
* Removed unused imports
* Simplified iterator chains and substitution logic
---
## Are these changes tested?
Yes.
* Existing pruning and equivalence tests were updated to reflect the
unified cast handling.
* Obsolete tests relying on `CastColumnExpr` were removed.
* Test cases were adjusted to ensure behavior remains unchanged,
including:
* Ordering equivalence with cast substitutions
* Predicate pruning with cast expressions
These updates ensure no regression in behavior while validating the
simplified implementation.
---
## Are there any user-facing changes?
No.
This change is an internal refactor and does not modify user-facing APIs
or query behavior. It preserves existing semantics while improving
maintainability.
---
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed and tested.CastColumnExpr branches in pruning and ordering equivalence (#21545)1 parent 0ab78e7 commit 16e578d
3 files changed
Lines changed: 80 additions & 130 deletions
File tree
- datafusion
- physical-expr/src/equivalence/properties
- pruning/src
Lines changed: 18 additions & 63 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
389 | 389 | | |
390 | 390 | | |
391 | 391 | | |
392 | | - | |
| 392 | + | |
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
| |||
931 | 931 | | |
932 | 932 | | |
933 | 933 | | |
934 | | - | |
935 | | - | |
| 934 | + | |
936 | 935 | | |
937 | 936 | | |
938 | 937 | | |
939 | 938 | | |
940 | 939 | | |
941 | 940 | | |
942 | | - | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
943 | 947 | | |
944 | 948 | | |
945 | 949 | | |
946 | | - | |
| 950 | + | |
947 | 951 | | |
948 | 952 | | |
949 | | - | |
950 | | - | |
| 953 | + | |
951 | 954 | | |
952 | 955 | | |
953 | 956 | | |
954 | 957 | | |
955 | 958 | | |
956 | | - | |
| 959 | + | |
957 | 960 | | |
958 | 961 | | |
959 | | - | |
960 | | - | |
| 962 | + | |
961 | 963 | | |
962 | 964 | | |
963 | 965 | | |
964 | 966 | | |
965 | 967 | | |
966 | 968 | | |
967 | 969 | | |
968 | | - | |
969 | | - | |
| 970 | + | |
970 | 971 | | |
971 | 972 | | |
972 | 973 | | |
| |||
979 | 980 | | |
980 | 981 | | |
981 | 982 | | |
982 | | - | |
983 | | - | |
984 | | - | |
| 983 | + | |
| 984 | + | |
985 | 985 | | |
986 | 986 | | |
987 | 987 | | |
| |||
993 | 993 | | |
994 | 994 | | |
995 | 995 | | |
996 | | - | |
997 | | - | |
998 | | - | |
| 996 | + | |
| 997 | + | |
999 | 998 | | |
1000 | 999 | | |
1001 | 1000 | | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | 1001 | | |
1009 | | - | |
| 1002 | + | |
1010 | 1003 | | |
1011 | 1004 | | |
1012 | 1005 | | |
| |||
1017 | 1010 | | |
1018 | 1011 | | |
1019 | 1012 | | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
1047 | | - | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
1051 | | - | |
1052 | | - | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
1058 | 1013 | | |
1059 | 1014 | | |
1060 | 1015 | | |
| |||
Lines changed: 27 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
200 | | - | |
| 199 | + | |
| 200 | + | |
201 | 201 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
212 | 208 | | |
213 | 209 | | |
214 | 210 | | |
215 | 211 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
| 212 | + | |
225 | 213 | | |
226 | | - | |
227 | | - | |
| 214 | + | |
| 215 | + | |
228 | 216 | | |
229 | 217 | | |
230 | 218 | | |
| |||
866 | 854 | | |
867 | 855 | | |
868 | 856 | | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | 857 | | |
876 | 858 | | |
877 | 859 | | |
| 860 | + | |
878 | 861 | | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | | - | |
883 | | - | |
884 | | - | |
885 | | - | |
886 | | - | |
887 | | - | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
888 | 876 | | |
889 | 877 | | |
890 | 878 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| |||
1124 | 1123 | | |
1125 | 1124 | | |
1126 | 1125 | | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
1133 | 1134 | | |
1134 | | - | |
| 1135 | + | |
1135 | 1136 | | |
1136 | 1137 | | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | | - | |
1149 | | - | |
1150 | | - | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
1151 | 1142 | | |
1152 | 1143 | | |
1153 | 1144 | | |
1154 | 1145 | | |
1155 | 1146 | | |
1156 | | - | |
1157 | | - | |
1158 | | - | |
1159 | | - | |
1160 | | - | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1161 | 1154 | | |
1162 | 1155 | | |
1163 | 1156 | | |
| |||
1191 | 1184 | | |
1192 | 1185 | | |
1193 | 1186 | | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
1194 | 1201 | | |
1195 | 1202 | | |
1196 | 1203 | | |
| |||
4192 | 4199 | | |
4193 | 4200 | | |
4194 | 4201 | | |
4195 | | - | |
| 4202 | + | |
4196 | 4203 | | |
4197 | 4204 | | |
4198 | 4205 | | |
| |||
0 commit comments