Commit 136e63c
committed
[SPARK-58023][PYTHON] Fast paths for converting Arrow string, binary, numeric and boolean columns to Python rows
Extend ArrowTableToRowsConversion._to_pylist with leaf fast paths:
* string/large_string/binary/large_binary columns use Arrow's
object-dtype NumPy conversion, which produces exactly str/bytes and
None - no other type can come out of it.
* integer/float32/float64/boolean columns without nulls convert via a
zero-copy (except bit-packed booleans) NumPy view and ndarray.tolist,
which materializes exact Python ints/floats/bools. With nulls, the
values are filled with a placeholder first (pc.fill_null) and nulls
are restored to None from the validity bitmap, so ints are always
materialized from the original int buffer, never through a float
representation.
Types whose as_py returns non-primitive objects (dates, timestamps,
decimals, ...) keep using to_pylist. Since list columns convert their
flattened child values through _to_pylist, list-typed columns get the
leaf speedup on top of the bulk offsets slicing.
ASV microbenchmark (bench_arrow.ArrowLeafColumnToRowsBenchmark, 1M
rows): string with nulls 196ms -> 20ms (9.7x); int64 with nulls
99ms -> 28ms (3.6x); float64 without nulls 100ms -> 9ms (11x).
End-to-end list<string> conversion (ArrowListColumnToRowsBenchmark, 1M rows) improves from 507ms to 118ms on
top of SPARK-58019.
Co-authored-by: Isaac1 parent 691885a commit 136e63c
3 files changed
Lines changed: 108 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
984 | 984 | | |
985 | 985 | | |
986 | 986 | | |
987 | | - | |
| 987 | + | |
| 988 | + | |
988 | 989 | | |
989 | 990 | | |
990 | 991 | | |
991 | 992 | | |
992 | 993 | | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
999 | 1004 | | |
1000 | 1005 | | |
1001 | 1006 | | |
| |||
1014 | 1019 | | |
1015 | 1020 | | |
1016 | 1021 | | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
1017 | 1025 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
| 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 | + | |
1021 | 1054 | | |
1022 | 1055 | | |
1023 | 1056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
876 | 877 | | |
877 | 878 | | |
878 | 879 | | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
879 | 901 | | |
880 | 902 | | |
881 | 903 | | |
| |||
0 commit comments