summaryrefslogblamecommitdiffstats
path: root/venv/lib/python3.9/site-packages/pyarrow/includes/libarrow.pxd
blob: df6a883afe9806b5c5ac72147d87fffd810d71f0 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
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
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821




































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                               
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

# distutils: language = c++

from pyarrow.includes.common cimport *


cdef extern from "arrow/util/key_value_metadata.h" namespace "arrow" nogil:
    cdef cppclass CKeyValueMetadata" arrow::KeyValueMetadata":
        CKeyValueMetadata()
        CKeyValueMetadata(const unordered_map[c_string, c_string]&)
        CKeyValueMetadata(const vector[c_string]& keys,
                          const vector[c_string]& values)

        void reserve(int64_t n)
        int64_t size() const
        c_string key(int64_t i) const
        c_string value(int64_t i) const
        int FindKey(const c_string& key) const

        shared_ptr[CKeyValueMetadata] Copy() const
        c_bool Equals(const CKeyValueMetadata& other)
        void Append(const c_string& key, const c_string& value)
        void ToUnorderedMap(unordered_map[c_string, c_string]*) const
        c_string ToString() const

        CResult[c_string] Get(const c_string& key) const
        CStatus Delete(const c_string& key)
        CStatus Set(const c_string& key, const c_string& value)
        c_bool Contains(const c_string& key) const


cdef extern from "arrow/util/decimal.h" namespace "arrow" nogil:
    cdef cppclass CDecimal128" arrow::Decimal128":
        c_string ToString(int32_t scale) const


cdef extern from "arrow/util/decimal.h" namespace "arrow" nogil:
    cdef cppclass CDecimal256" arrow::Decimal256":
        c_string ToString(int32_t scale) const


cdef extern from "arrow/config.h" namespace "arrow" nogil:
    cdef cppclass CBuildInfo" arrow::BuildInfo":
        int version
        int version_major
        int version_minor
        int version_patch
        c_string version_string
        c_string so_version
        c_string full_so_version
        c_string compiler_id
        c_string compiler_version
        c_string compiler_flags
        c_string git_id
        c_string git_description
        c_string package_kind
        c_string build_type

    const CBuildInfo& GetBuildInfo()

    cdef cppclass CRuntimeInfo" arrow::RuntimeInfo":
        c_string simd_level
        c_string detected_simd_level

    CRuntimeInfo GetRuntimeInfo()


cdef extern from "arrow/util/future.h" namespace "arrow" nogil:
    cdef cppclass CFuture_Void" arrow::Future<>":
        CStatus status()


cdef extern from "arrow/api.h" namespace "arrow" nogil:
    cdef enum Type" arrow::Type::type":
        _Type_NA" arrow::Type::NA"

        _Type_BOOL" arrow::Type::BOOL"

        _Type_UINT8" arrow::Type::UINT8"
        _Type_INT8" arrow::Type::INT8"
        _Type_UINT16" arrow::Type::UINT16"
        _Type_INT16" arrow::Type::INT16"
        _Type_UINT32" arrow::Type::UINT32"
        _Type_INT32" arrow::Type::INT32"
        _Type_UINT64" arrow::Type::UINT64"
        _Type_INT64" arrow::Type::INT64"

        _Type_HALF_FLOAT" arrow::Type::HALF_FLOAT"
        _Type_FLOAT" arrow::Type::FLOAT"
        _Type_DOUBLE" arrow::Type::DOUBLE"

        _Type_DECIMAL128" arrow::Type::DECIMAL128"
        _Type_DECIMAL256" arrow::Type::DECIMAL256"

        _Type_DATE32" arrow::Type::DATE32"
        _Type_DATE64" arrow::Type::DATE64"
        _Type_TIMESTAMP" arrow::Type::TIMESTAMP"
        _Type_TIME32" arrow::Type::TIME32"
        _Type_TIME64" arrow::Type::TIME64"
        _Type_DURATION" arrow::Type::DURATION"
        _Type_INTERVAL_MONTH_DAY_NANO" arrow::Type::INTERVAL_MONTH_DAY_NANO"

        _Type_BINARY" arrow::Type::BINARY"
        _Type_STRING" arrow::Type::STRING"
        _Type_LARGE_BINARY" arrow::Type::LARGE_BINARY"
        _Type_LARGE_STRING" arrow::Type::LARGE_STRING"
        _Type_FIXED_SIZE_BINARY" arrow::Type::FIXED_SIZE_BINARY"

        _Type_LIST" arrow::Type::LIST"
        _Type_LARGE_LIST" arrow::Type::LARGE_LIST"
        _Type_FIXED_SIZE_LIST" arrow::Type::FIXED_SIZE_LIST"
        _Type_STRUCT" arrow::Type::STRUCT"
        _Type_SPARSE_UNION" arrow::Type::SPARSE_UNION"
        _Type_DENSE_UNION" arrow::Type::DENSE_UNION"
        _Type_DICTIONARY" arrow::Type::DICTIONARY"
        _Type_MAP" arrow::Type::MAP"

        _Type_EXTENSION" arrow::Type::EXTENSION"

    cdef enum UnionMode" arrow::UnionMode::type":
        _UnionMode_SPARSE" arrow::UnionMode::SPARSE"
        _UnionMode_DENSE" arrow::UnionMode::DENSE"

    cdef enum TimeUnit" arrow::TimeUnit::type":
        TimeUnit_SECOND" arrow::TimeUnit::SECOND"
        TimeUnit_MILLI" arrow::TimeUnit::MILLI"
        TimeUnit_MICRO" arrow::TimeUnit::MICRO"
        TimeUnit_NANO" arrow::TimeUnit::NANO"

    cdef cppclass CBufferSpec" arrow::DataTypeLayout::BufferSpec":
        pass

    cdef cppclass CDataTypeLayout" arrow::DataTypeLayout":
        vector[CBufferSpec] buffers
        c_bool has_dictionary

    cdef cppclass CDataType" arrow::DataType":
        Type id()

        c_bool Equals(const CDataType& other, c_bool check_metadata)
        c_bool Equals(const shared_ptr[CDataType]& other, c_bool check_metadata)

        shared_ptr[CField] field(int i)
        const vector[shared_ptr[CField]] fields()
        int num_fields()
        CDataTypeLayout layout()
        c_string ToString()

    c_bool is_primitive(Type type)

    cdef cppclass CArrayData" arrow::ArrayData":
        shared_ptr[CDataType] type
        int64_t length
        int64_t null_count
        int64_t offset
        vector[shared_ptr[CBuffer]] buffers
        vector[shared_ptr[CArrayData]] child_data
        shared_ptr[CArrayData] dictionary

        @staticmethod
        shared_ptr[CArrayData] Make(const shared_ptr[CDataType]& type,
                                    int64_t length,
                                    vector[shared_ptr[CBuffer]]& buffers,
                                    int64_t null_count,
                                    int64_t offset)

        @staticmethod
        shared_ptr[CArrayData] MakeWithChildren" Make"(
            const shared_ptr[CDataType]& type,
            int64_t length,
            vector[shared_ptr[CBuffer]]& buffers,
            vector[shared_ptr[CArrayData]]& child_data,
            int64_t null_count,
            int64_t offset)

        @staticmethod
        shared_ptr[CArrayData] MakeWithChildrenAndDictionary" Make"(
            const shared_ptr[CDataType]& type,
            int64_t length,
            vector[shared_ptr[CBuffer]]& buffers,
            vector[shared_ptr[CArrayData]]& child_data,
            shared_ptr[CArrayData]& dictionary,
            int64_t null_count,
            int64_t offset)

    cdef cppclass CArray" arrow::Array":
        shared_ptr[CDataType] type()

        int64_t length()
        int64_t null_count()
        int64_t offset()
        Type type_id()

        int num_fields()

        CResult[shared_ptr[CScalar]] GetScalar(int64_t i) const

        c_string Diff(const CArray& other)
        c_bool Equals(const CArray& arr)
        c_bool IsNull(int i)

        shared_ptr[CArrayData] data()

        shared_ptr[CArray] Slice(int64_t offset)
        shared_ptr[CArray] Slice(int64_t offset, int64_t length)

        CStatus Validate() const
        CStatus ValidateFull() const
        CResult[shared_ptr[CArray]] View(const shared_ptr[CDataType]& type)

    shared_ptr[CArray] MakeArray(const shared_ptr[CArrayData]& data)
    CResult[shared_ptr[CArray]] MakeArrayOfNull(
        const shared_ptr[CDataType]& type, int64_t length, CMemoryPool* pool)

    CResult[shared_ptr[CArray]] MakeArrayFromScalar(
        const CScalar& scalar, int64_t length, CMemoryPool* pool)

    CStatus DebugPrint(const CArray& arr, int indent)

    cdef cppclass CFixedWidthType" arrow::FixedWidthType"(CDataType):
        int bit_width()

    cdef cppclass CNullArray" arrow::NullArray"(CArray):
        CNullArray(int64_t length)

    cdef cppclass CDictionaryArray" arrow::DictionaryArray"(CArray):
        CDictionaryArray(const shared_ptr[CDataType]& type,
                         const shared_ptr[CArray]& indices,
                         const shared_ptr[CArray]& dictionary)
        CDictionaryArray(const shared_ptr[CArrayData]& data)

        @staticmethod
        CResult[shared_ptr[CArray]] FromArrays(
            const shared_ptr[CDataType]& type,
            const shared_ptr[CArray]& indices,
            const shared_ptr[CArray]& dictionary)

        shared_ptr[CArray] indices()
        shared_ptr[CArray] dictionary()

    cdef cppclass CDate32Type" arrow::Date32Type"(CFixedWidthType):
        pass

    cdef cppclass CDate64Type" arrow::Date64Type"(CFixedWidthType):
        pass

    cdef cppclass CTimestampType" arrow::TimestampType"(CFixedWidthType):
        CTimestampType(TimeUnit unit)
        TimeUnit unit()
        const c_string& timezone()

    cdef cppclass CTime32Type" arrow::Time32Type"(CFixedWidthType):
        TimeUnit unit()

    cdef cppclass CTime64Type" arrow::Time64Type"(CFixedWidthType):
        TimeUnit unit()

    shared_ptr[CDataType] ctime32" arrow::time32"(TimeUnit unit)
    shared_ptr[CDataType] ctime64" arrow::time64"(TimeUnit unit)

    cdef cppclass CDurationType" arrow::DurationType"(CFixedWidthType):
        TimeUnit unit()

    shared_ptr[CDataType] cduration" arrow::duration"(TimeUnit unit)

    cdef cppclass CDictionaryType" arrow::DictionaryType"(CFixedWidthType):
        CDictionaryType(const shared_ptr[CDataType]& index_type,
                        const shared_ptr[CDataType]& value_type,
                        c_bool ordered)

        shared_ptr[CDataType] index_type()
        shared_ptr[CDataType] value_type()
        c_bool ordered()

    shared_ptr[CDataType] ctimestamp" arrow::timestamp"(TimeUnit unit)
    shared_ptr[CDataType] ctimestamp" arrow::timestamp"(
        TimeUnit unit, const c_string& timezone)

    cdef cppclass CMemoryPool" arrow::MemoryPool":
        int64_t bytes_allocated()
        int64_t max_memory()
        c_string backend_name()
        void ReleaseUnused()

    cdef cppclass CLoggingMemoryPool" arrow::LoggingMemoryPool"(CMemoryPool):
        CLoggingMemoryPool(CMemoryPool*)

    cdef cppclass CProxyMemoryPool" arrow::ProxyMemoryPool"(CMemoryPool):
        CProxyMemoryPool(CMemoryPool*)

    cdef cppclass CBuffer" arrow::Buffer":
        CBuffer(const uint8_t* data, int64_t size)
        const uint8_t* data()
        uint8_t* mutable_data()
        uintptr_t address()
        uintptr_t mutable_address()
        int64_t size()
        shared_ptr[CBuffer] parent()
        c_bool is_cpu() const
        c_bool is_mutable() const
        c_string ToHexString()
        c_bool Equals(const CBuffer& other)

    CResult[shared_ptr[CBuffer]] SliceBufferSafe(
        const shared_ptr[CBuffer]& buffer, int64_t offset)
    CResult[shared_ptr[CBuffer]] SliceBufferSafe(
        const shared_ptr[CBuffer]& buffer, int64_t offset, int64_t length)

    cdef cppclass CMutableBuffer" arrow::MutableBuffer"(CBuffer):
        CMutableBuffer(const uint8_t* data, int64_t size)

    cdef cppclass CResizableBuffer" arrow::ResizableBuffer"(CMutableBuffer):
        CStatus Resize(const int64_t new_size, c_bool shrink_to_fit)
        CStatus Reserve(const int64_t new_size)

    CResult[unique_ptr[CBuffer]] AllocateBuffer(const int64_t size,
                                                CMemoryPool* pool)

    CResult[unique_ptr[CResizableBuffer]] AllocateResizableBuffer(
        const int64_t size, CMemoryPool* pool)

    cdef CMemoryPool* c_default_memory_pool" arrow::default_memory_pool"()
    cdef CMemoryPool* c_system_memory_pool" arrow::system_memory_pool"()
    cdef CStatus c_jemalloc_memory_pool" arrow::jemalloc_memory_pool"(
        CMemoryPool** out)
    cdef CStatus c_mimalloc_memory_pool" arrow::mimalloc_memory_pool"(
        CMemoryPool** out)
    cdef vector[c_string] c_supported_memory_backends \
        " arrow::SupportedMemoryBackendNames"()

    CStatus c_jemalloc_set_decay_ms" arrow::jemalloc_set_decay_ms"(int ms)

    cdef cppclass CListType" arrow::ListType"(CDataType):
        CListType(const shared_ptr[CDataType]& value_type)
        CListType(const shared_ptr[CField]& field)
        shared_ptr[CDataType] value_type()
        shared_ptr[CField] value_field()

    cdef cppclass CLargeListType" arrow::LargeListType"(CDataType):
        CLargeListType(const shared_ptr[CDataType]& value_type)
        CLargeListType(const shared_ptr[CField]& field)
        shared_ptr[CDataType] value_type()
        shared_ptr[CField] value_field()

    cdef cppclass CMapType" arrow::MapType"(CDataType):
        CMapType(const shared_ptr[CField]& key_field,
                 const shared_ptr[CField]& item_field, c_bool keys_sorted)
        shared_ptr[CDataType] key_type()
        shared_ptr[CField] key_field()
        shared_ptr[CDataType] item_type()
        shared_ptr[CField] item_field()
        c_bool keys_sorted()

    cdef cppclass CFixedSizeListType" arrow::FixedSizeListType"(CDataType):
        CFixedSizeListType(const shared_ptr[CDataType]& value_type,
                           int32_t list_size)
        CFixedSizeListType(const shared_ptr[CField]& field, int32_t list_size)
        shared_ptr[CDataType] value_type()
        shared_ptr[CField] value_field()
        int32_t list_size()

    cdef cppclass CStringType" arrow::StringType"(CDataType):
        pass

    cdef cppclass CFixedSizeBinaryType \
            " arrow::FixedSizeBinaryType"(CFixedWidthType):
        CFixedSizeBinaryType(int byte_width)
        int byte_width()
        int bit_width()

    cdef cppclass CDecimal128Type \
            " arrow::Decimal128Type"(CFixedSizeBinaryType):
        CDecimal128Type(int precision, int scale)
        int precision()
        int scale()

    cdef cppclass CDecimal256Type \
            " arrow::Decimal256Type"(CFixedSizeBinaryType):
        CDecimal256Type(int precision, int scale)
        int precision()
        int scale()

    cdef cppclass CField" arrow::Field":
        cppclass CMergeOptions "arrow::Field::MergeOptions":
            c_bool promote_nullability

            @staticmethod
            CMergeOptions Defaults()

        const c_string& name()
        shared_ptr[CDataType] type()
        c_bool nullable()

        c_string ToString()
        c_bool Equals(const CField& other, c_bool check_metadata)

        shared_ptr[const CKeyValueMetadata] metadata()

        CField(const c_string& name, const shared_ptr[CDataType]& type,
               c_bool nullable)

        CField(const c_string& name, const shared_ptr[CDataType]& type,
               c_bool nullable, const shared_ptr[CKeyValueMetadata]& metadata)

        # Removed const in Cython so don't have to cast to get code to generate
        shared_ptr[CField] AddMetadata(
            const shared_ptr[CKeyValueMetadata]& metadata)
        shared_ptr[CField] WithMetadata(
            const shared_ptr[CKeyValueMetadata]& metadata)
        shared_ptr[CField] RemoveMetadata()
        shared_ptr[CField] WithType(const shared_ptr[CDataType]& type)
        shared_ptr[CField] WithName(const c_string& name)
        shared_ptr[CField] WithNullable(c_bool nullable)
        vector[shared_ptr[CField]] Flatten()

    cdef cppclass CFieldRef" arrow::FieldRef":
        CFieldRef()
        CFieldRef(c_string name)
        CFieldRef(int index)
        CFieldRef(vector[CFieldRef])

        @staticmethod
        CResult[CFieldRef] FromDotPath(c_string& dot_path)
        const c_string* name() const

    cdef cppclass CFieldRefHash" arrow::FieldRef::Hash":
        pass

    cdef cppclass CStructType" arrow::StructType"(CDataType):
        CStructType(const vector[shared_ptr[CField]]& fields)

        shared_ptr[CField] GetFieldByName(const c_string& name)
        vector[shared_ptr[CField]] GetAllFieldsByName(const c_string& name)
        int GetFieldIndex(const c_string& name)
        vector[int] GetAllFieldIndices(const c_string& name)

    cdef cppclass CUnionType" arrow::UnionType"(CDataType):
        UnionMode mode()
        const vector[int8_t]& type_codes()
        const vector[int]& child_ids()

    cdef shared_ptr[CDataType] CMakeSparseUnionType" arrow::sparse_union"(
        vector[shared_ptr[CField]] fields,
        vector[int8_t] type_codes)

    cdef shared_ptr[CDataType] CMakeDenseUnionType" arrow::dense_union"(
        vector[shared_ptr[CField]] fields,
        vector[int8_t] type_codes)

    cdef cppclass CSchema" arrow::Schema":
        CSchema(const vector[shared_ptr[CField]]& fields)
        CSchema(const vector[shared_ptr[CField]]& fields,
                const shared_ptr[const CKeyValueMetadata]& metadata)

        # Does not actually exist, but gets Cython to not complain
        CSchema(const vector[shared_ptr[CField]]& fields,
                const shared_ptr[CKeyValueMetadata]& metadata)

        c_bool Equals(const CSchema& other, c_bool check_metadata)

        shared_ptr[CField] field(int i)
        shared_ptr[const CKeyValueMetadata] metadata()
        shared_ptr[CField] GetFieldByName(const c_string& name)
        vector[shared_ptr[CField]] GetAllFieldsByName(const c_string& name)
        int GetFieldIndex(const c_string& name)
        vector[int] GetAllFieldIndices(const c_string& name)
        int num_fields()
        c_string ToString()

        CResult[shared_ptr[CSchema]] AddField(int i,
                                              const shared_ptr[CField]& field)
        CResult[shared_ptr[CSchema]] RemoveField(int i)
        CResult[shared_ptr[CSchema]] SetField(int i,
                                              const shared_ptr[CField]& field)

        # Removed const in Cython so don't have to cast to get code to generate
        shared_ptr[CSchema] AddMetadata(
            const shared_ptr[CKeyValueMetadata]& metadata)
        shared_ptr[CSchema] WithMetadata(
            const shared_ptr[CKeyValueMetadata]& metadata)
        shared_ptr[CSchema] RemoveMetadata()

    CResult[shared_ptr[CSchema]] UnifySchemas(
        const vector[shared_ptr[CSchema]]& schemas)

    cdef cppclass PrettyPrintOptions:
        PrettyPrintOptions()
        PrettyPrintOptions(int indent_arg)
        PrettyPrintOptions(int indent_arg, int window_arg)
        int indent
        int indent_size
        int window
        int container_window
        c_string null_rep
        c_bool skip_new_lines
        c_bool truncate_metadata
        c_bool show_field_metadata
        c_bool show_schema_metadata

        @staticmethod
        PrettyPrintOptions Defaults()

    CStatus PrettyPrint(const CArray& schema,
                        const PrettyPrintOptions& options,
                        c_string* result)
    CStatus PrettyPrint(const CChunkedArray& schema,
                        const PrettyPrintOptions& options,
                        c_string* result)
    CStatus PrettyPrint(const CSchema& schema,
                        const PrettyPrintOptions& options,
                        c_string* result)

    cdef cppclass CBooleanArray" arrow::BooleanArray"(CArray):
        c_bool Value(int i)
        int64_t false_count()
        int64_t true_count()

    cdef cppclass CUInt8Array" arrow::UInt8Array"(CArray):
        uint8_t Value(int i)

    cdef cppclass CInt8Array" arrow::Int8Array"(CArray):
        int8_t Value(int i)

    cdef cppclass CUInt16Array" arrow::UInt16Array"(CArray):
        uint16_t Value(int i)

    cdef cppclass CInt16Array" arrow::Int16Array"(CArray):
        int16_t Value(int i)

    cdef cppclass CUInt32Array" arrow::UInt32Array"(CArray):
        uint32_t Value(int i)

    cdef cppclass CInt32Array" arrow::Int32Array"(CArray):
        int32_t Value(int i)

    cdef cppclass CUInt64Array" arrow::UInt64Array"(CArray):
        uint64_t Value(int i)

    cdef cppclass CInt64Array" arrow::Int64Array"(CArray):
        int64_t Value(int i)

    cdef cppclass CDate32Array" arrow::Date32Array"(CArray):
        int32_t Value(int i)

    cdef cppclass CDate64Array" arrow::Date64Array"(CArray):
        int64_t Value(int i)

    cdef cppclass CTime32Array" arrow::Time32Array"(CArray):
        int32_t Value(int i)

    cdef cppclass CTime64Array" arrow::Time64Array"(CArray):
        int64_t Value(int i)

    cdef cppclass CTimestampArray" arrow::TimestampArray"(CArray):
        int64_t Value(int i)

    cdef cppclass CDurationArray" arrow::DurationArray"(CArray):
        int64_t Value(int i)

    cdef cppclass CMonthDayNanoIntervalArray \
            "arrow::MonthDayNanoIntervalArray"(CArray):
        pass

    cdef cppclass CHalfFloatArray" arrow::HalfFloatArray"(CArray):
        uint16_t Value(int i)

    cdef cppclass CFloatArray" arrow::FloatArray"(CArray):
        float Value(int i)

    cdef cppclass CDoubleArray" arrow::DoubleArray"(CArray):
        double Value(int i)

    cdef cppclass CFixedSizeBinaryArray" arrow::FixedSizeBinaryArray"(CArray):
        const uint8_t* GetValue(int i)

    cdef cppclass CDecimal128Array" arrow::Decimal128Array"(
        CFixedSizeBinaryArray
    ):
        c_string FormatValue(int i)

    cdef cppclass CDecimal256Array" arrow::Decimal256Array"(
        CFixedSizeBinaryArray
    ):
        c_string FormatValue(int i)

    cdef cppclass CListArray" arrow::ListArray"(CArray):
        @staticmethod
        CResult[shared_ptr[CArray]] FromArrays(
            const CArray& offsets,
            const CArray& values,
            CMemoryPool* pool,
            shared_ptr[CBuffer] null_bitmap,
        )

        @staticmethod
        CResult[shared_ptr[CArray]] FromArraysAndType" FromArrays"(
            shared_ptr[CDataType],
            const CArray& offsets,
            const CArray& values,
            CMemoryPool* pool,
            shared_ptr[CBuffer] null_bitmap,
        )

        const int32_t* raw_value_offsets()
        int32_t value_offset(int i)
        int32_t value_length(int i)
        shared_ptr[CArray] values()
        shared_ptr[CArray] offsets()
        shared_ptr[CDataType] value_type()

    cdef cppclass CLargeListArray" arrow::LargeListArray"(CArray):
        @staticmethod
        CResult[shared_ptr[CArray]] FromArrays(
            const CArray& offsets,
            const CArray& values,
            CMemoryPool* pool,
            shared_ptr[CBuffer] null_bitmap
        )

        @staticmethod
        CResult[shared_ptr[CArray]] FromArraysAndType" FromArrays"(
            shared_ptr[CDataType],
            const CArray& offsets,
            const CArray& values,
            CMemoryPool* pool,
            shared_ptr[CBuffer] null_bitmap
        )

        int64_t value_offset(int i)
        int64_t value_length(int i)
        shared_ptr[CArray] values()
        shared_ptr[CArray] offsets()
        shared_ptr[CDataType] value_type()

    cdef cppclass CFixedSizeListArray" arrow::FixedSizeListArray"(CArray):
        @staticmethod
        CResult[shared_ptr[CArray]] FromArrays(
            const shared_ptr[CArray]& values, int32_t list_size)

        @staticmethod
        CResult[shared_ptr[CArray]] FromArraysAndType" FromArrays"(
            const shared_ptr[CArray]& values, shared_ptr[CDataType])

        int64_t value_offset(int i)
        int64_t value_length(int i)
        shared_ptr[CArray] values()
        shared_ptr[CDataType] value_type()

    cdef cppclass CMapArray" arrow::MapArray"(CArray):
        @staticmethod
        CResult[shared_ptr[CArray]] FromArrays(
            const shared_ptr[CArray]& offsets,
            const shared_ptr[CArray]& keys,
            const shared_ptr[CArray]& items,
            CMemoryPool* pool)

        shared_ptr[CArray] keys()
        shared_ptr[CArray] items()
        CMapType* map_type()
        int64_t value_offset(int i)
        int64_t value_length(int i)
        shared_ptr[CArray] values()
        shared_ptr[CDataType] value_type()

    cdef cppclass CUnionArray" arrow::UnionArray"(CArray):
        shared_ptr[CBuffer] type_codes()
        int8_t* raw_type_codes()
        int child_id(int64_t index)
        shared_ptr[CArray] field(int pos)
        const CArray* UnsafeField(int pos)
        UnionMode mode()

    cdef cppclass CSparseUnionArray" arrow::SparseUnionArray"(CUnionArray):
        @staticmethod
        CResult[shared_ptr[CArray]] Make(
            const CArray& type_codes,
            const vector[shared_ptr[CArray]]& children,
            const vector[c_string]& field_names,
            const vector[int8_t]& type_codes)

    cdef cppclass CDenseUnionArray" arrow::DenseUnionArray"(CUnionArray):
        @staticmethod
        CResult[shared_ptr[CArray]] Make(
            const CArray& type_codes,
            const CArray& value_offsets,
            const vector[shared_ptr[CArray]]& children,
            const vector[c_string]& field_names,
            const vector[int8_t]& type_codes)

        int32_t value_offset(int i)
        shared_ptr[CBuffer] value_offsets()

    cdef cppclass CBinaryArray" arrow::BinaryArray"(CArray):
        const uint8_t* GetValue(int i, int32_t* length)
        shared_ptr[CBuffer] value_data()
        int32_t value_offset(int64_t i)
        int32_t value_length(int64_t i)
        int32_t total_values_length()

    cdef cppclass CLargeBinaryArray" arrow::LargeBinaryArray"(CArray):
        const uint8_t* GetValue(int i, int64_t* length)
        shared_ptr[CBuffer] value_data()
        int64_t value_offset(int64_t i)
        int64_t value_length(int64_t i)
        int64_t total_values_length()

    cdef cppclass CStringArray" arrow::StringArray"(CBinaryArray):
        CStringArray(int64_t length, shared_ptr[CBuffer] value_offsets,
                     shared_ptr[CBuffer] data,
                     shared_ptr[CBuffer] null_bitmap,
                     int64_t null_count,
                     int64_t offset)

        c_string GetString(int i)

    cdef cppclass CLargeStringArray" arrow::LargeStringArray" \
            (CLargeBinaryArray):
        CLargeStringArray(int64_t length, shared_ptr[CBuffer] value_offsets,
                          shared_ptr[CBuffer] data,
                          shared_ptr[CBuffer] null_bitmap,
                          int64_t null_count,
                          int64_t offset)

        c_string GetString(int i)

    cdef cppclass CStructArray" arrow::StructArray"(CArray):
        CStructArray(shared_ptr[CDataType]& type, int64_t length,
                     vector[shared_ptr[CArray]]& children,
                     shared_ptr[CBuffer] null_bitmap=nullptr,
                     int64_t null_count=-1,
                     int64_t offset=0)

        # XXX Cython crashes if default argument values are declared here
        # https://github.com/cython/cython/issues/2167
        @staticmethod
        CResult[shared_ptr[CArray]] MakeFromFieldNames "Make"(
            vector[shared_ptr[CArray]] children,
            vector[c_string] field_names,
            shared_ptr[CBuffer] null_bitmap,
            int64_t null_count,
            int64_t offset)

        @staticmethod
        CResult[shared_ptr[CArray]] MakeFromFields "Make"(
            vector[shared_ptr[CArray]] children,
            vector[shared_ptr[CField]] fields,
            shared_ptr[CBuffer] null_bitmap,
            int64_t null_count,
            int64_t offset)

        shared_ptr[CArray] field(int pos)
        shared_ptr[CArray] GetFieldByName(const c_string& name) const
        CResult[shared_ptr[CArray]] GetFlattenedField(int index, CMemoryPool* pool) const

        CResult[vector[shared_ptr[CArray]]] Flatten(CMemoryPool* pool)

    cdef cppclass CChunkedArray" arrow::ChunkedArray":
        CChunkedArray(const vector[shared_ptr[CArray]]& arrays)
        CChunkedArray(const vector[shared_ptr[CArray]]& arrays,
                      const shared_ptr[CDataType]& type)

        @staticmethod
        CResult[shared_ptr[CChunkedArray]] Make(vector[shared_ptr[CArray]] chunks,
                                                shared_ptr[CDataType] type)
        int64_t length()
        int64_t null_count()
        int num_chunks()
        c_bool Equals(const CChunkedArray& other)

        shared_ptr[CArray] chunk(int i)
        shared_ptr[CDataType] type()
        CResult[shared_ptr[CScalar]] GetScalar(int64_t index) const
        shared_ptr[CChunkedArray] Slice(int64_t offset, int64_t length) const
        shared_ptr[CChunkedArray] Slice(int64_t offset) const

        CResult[vector[shared_ptr[CChunkedArray]]] Flatten(CMemoryPool* pool)

        CStatus Validate() const
        CStatus ValidateFull() const

    cdef cppclass CRecordBatch" arrow::RecordBatch":
        @staticmethod
        shared_ptr[CRecordBatch] Make(
            const shared_ptr[CSchema]& schema, int64_t num_rows,
            const vector[shared_ptr[CArray]]& columns)

        @staticmethod
        CResult[shared_ptr[CRecordBatch]] FromStructArray(
            const shared_ptr[CArray]& array)

        c_bool Equals(const CRecordBatch& other, c_bool check_metadata)

        shared_ptr[CSchema] schema()
        shared_ptr[CArray] column(int i)
        const c_string& column_name(int i)

        const vector[shared_ptr[CArray]]& columns()

        int num_columns()
        int64_t num_rows()

        CStatus Validate() const
        CStatus ValidateFull() const

        shared_ptr[CRecordBatch] ReplaceSchemaMetadata(
            const shared_ptr[CKeyValueMetadata]& metadata)

        shared_ptr[CRecordBatch] Slice(int64_t offset)
        shared_ptr[CRecordBatch] Slice(int64_t offset, int64_t length)

    cdef cppclass CRecordBatchWithMetadata" arrow::RecordBatchWithMetadata":
        shared_ptr[CRecordBatch] batch
        # The struct in C++ does not actually have these two `const` qualifiers, but adding `const` gets Cython to not complain
        const shared_ptr[const CKeyValueMetadata] custom_metadata

    cdef cppclass CTable" arrow::Table":
        CTable(const shared_ptr[CSchema]& schema,
               const vector[shared_ptr[CChunkedArray]]& columns)

        @staticmethod
        shared_ptr[CTable] Make(
            const shared_ptr[CSchema]& schema,
            const vector[shared_ptr[CChunkedArray]]& columns)

        @staticmethod
        shared_ptr[CTable] MakeWithRows "Make"(
            const shared_ptr[CSchema]& schema,
            const vector[shared_ptr[CChunkedArray]]& columns,
            int64_t num_rows)

        @staticmethod
        shared_ptr[CTable] MakeFromArrays" Make"(
            const shared_ptr[CSchema]& schema,
            const vector[shared_ptr[CArray]]& arrays)

        @staticmethod
        CResult[shared_ptr[CTable]] FromRecordBatchReader(
            CRecordBatchReader *reader)

        @staticmethod
        CResult[shared_ptr[CTable]] FromRecordBatches(
            const shared_ptr[CSchema]& schema,
            const vector[shared_ptr[CRecordBatch]]& batches)

        int num_columns()
        int64_t num_rows()

        c_bool Equals(const CTable& other, c_bool check_metadata)

        shared_ptr[CSchema] schema()
        shared_ptr[CChunkedArray] column(int i)
        shared_ptr[CField] field(int i)

        CResult[shared_ptr[CTable]] AddColumn(
            int i, shared_ptr[CField] field, shared_ptr[CChunkedArray] column)
        CResult[shared_ptr[CTable]] RemoveColumn(int i)
        CResult[shared_ptr[CTable]] SetColumn(
            int i, shared_ptr[CField] field, shared_ptr[CChunkedArray] column)

        vector[c_string] ColumnNames()
        CResult[shared_ptr[CTable]] RenameColumns(const vector[c_string]&)
        CResult[shared_ptr[CTable]] SelectColumns(const vector[int]&)

        CResult[shared_ptr[CTable]] Flatten(CMemoryPool* pool)

        CResult[shared_ptr[CTable]] CombineChunks(CMemoryPool* pool)

        CStatus Validate() const
        CStatus ValidateFull() const

        shared_ptr[CTable] ReplaceSchemaMetadata(
            const shared_ptr[CKeyValueMetadata]& metadata)

        shared_ptr[CTable] Slice(int64_t offset)
        shared_ptr[CTable] Slice(int64_t offset, int64_t length)

    cdef cppclass CRecordBatchReader" arrow::RecordBatchReader":
        shared_ptr[CSchema] schema()
        CStatus Close()
        CResult[CRecordBatchWithMetadata] ReadNext()
        CStatus ReadNext(shared_ptr[CRecordBatch]* batch)
        CResult[shared_ptr[CTable]] ToTable()

    cdef cppclass TableBatchReader(CRecordBatchReader):
        TableBatchReader(const CTable& table)
        TableBatchReader(shared_ptr[CTable] table)
        void set_chunksize(int64_t chunksize)

    cdef cppclass CTensor" arrow::Tensor":
        shared_ptr[CDataType] type()
        shared_ptr[CBuffer] data()

        const vector[int64_t]& shape()
        const vector[int64_t]& strides()
        int64_t size()

        int ndim()
        const vector[c_string]& dim_names()
        const c_string& dim_name(int i)

        c_bool is_mutable()
        c_bool is_contiguous()
        Type type_id()
        c_bool Equals(const CTensor& other)

    cdef cppclass CSparseIndex" arrow::SparseIndex":
        pass

    cdef cppclass CSparseCOOIndex" arrow::SparseCOOIndex":
        c_bool is_canonical()

    cdef cppclass CSparseCOOTensor" arrow::SparseCOOTensor":
        shared_ptr[CDataType] type()
        shared_ptr[CBuffer] data()
        CResult[shared_ptr[CTensor]] ToTensor()

        shared_ptr[CSparseIndex] sparse_index()

        const vector[int64_t]& shape()
        int64_t size()
        int64_t non_zero_length()

        int ndim()
        const vector[c_string]& dim_names()
        const c_string& dim_name(int i)

        c_bool is_mutable()
        Type type_id()
        c_bool Equals(const CSparseCOOTensor& other)

    cdef cppclass CSparseCSRMatrix" arrow::SparseCSRMatrix":
        shared_ptr[CDataType] type()
        shared_ptr[CBuffer] data()
        CResult[shared_ptr[CTensor]] ToTensor()

        const vector[int64_t]& shape()
        int64_t size()
        int64_t non_zero_length()

        int ndim()
        const vector[c_string]& dim_names()
        const c_string& dim_name(int i)

        c_bool is_mutable()
        Type type_id()
        c_bool Equals(const CSparseCSRMatrix& other)

    cdef cppclass CSparseCSCMatrix" arrow::SparseCSCMatrix":
        shared_ptr[CDataType] type()
        shared_ptr[CBuffer] data()
        CResult[shared_ptr[CTensor]] ToTensor()

        const vector[int64_t]& shape()
        int64_t size()
        int64_t non_zero_length()

        int ndim()
        const vector[c_string]& dim_names()
        const c_string& dim_name(int i)

        c_bool is_mutable()
        Type type_id()
        c_bool Equals(const CSparseCSCMatrix& other)

    cdef cppclass CSparseCSFTensor" arrow::SparseCSFTensor":
        shared_ptr[CDataType] type()
        shared_ptr[CBuffer] data()
        CResult[shared_ptr[CTensor]] ToTensor()

        const vector[int64_t]& shape()
        int64_t size()
        int64_t non_zero_length()

        int ndim()
        const vector[c_string]& dim_names()
        const c_string& dim_name(int i)

        c_bool is_mutable()
        Type type_id()
        c_bool Equals(const CSparseCSFTensor& other)

    cdef cppclass CScalar" arrow::Scalar":
        CScalar(shared_ptr[CDataType])

        shared_ptr[CDataType] type
        c_bool is_valid

        c_string ToString() const
        c_bool Equals(const CScalar& other) const
        CStatus Validate() const
        CStatus ValidateFull() const
        CResult[shared_ptr[CScalar]] CastTo(shared_ptr[CDataType] to) const

    cdef cppclass CScalarHash" arrow::Scalar::Hash":
        size_t operator()(const shared_ptr[CScalar]& scalar) const

    cdef cppclass CNullScalar" arrow::NullScalar"(CScalar):
        CNullScalar()

    cdef cppclass CBooleanScalar" arrow::BooleanScalar"(CScalar):
        CBooleanScalar(c_bool value)
        c_bool value

    cdef cppclass CInt8Scalar" arrow::Int8Scalar"(CScalar):
        int8_t value

    cdef cppclass CUInt8Scalar" arrow::UInt8Scalar"(CScalar):
        uint8_t value

    cdef cppclass CInt16Scalar" arrow::Int16Scalar"(CScalar):
        int16_t value

    cdef cppclass CUInt16Scalar" arrow::UInt16Scalar"(CScalar):
        uint16_t value

    cdef cppclass CInt32Scalar" arrow::Int32Scalar"(CScalar):
        int32_t value

    cdef cppclass CUInt32Scalar" arrow::UInt32Scalar"(CScalar):
        uint32_t value

    cdef cppclass CInt64Scalar" arrow::Int64Scalar"(CScalar):
        int64_t value

    cdef cppclass CUInt64Scalar" arrow::UInt64Scalar"(CScalar):
        uint64_t value

    cdef cppclass CHalfFloatScalar" arrow::HalfFloatScalar"(CScalar):
        npy_half value

    cdef cppclass CFloatScalar" arrow::FloatScalar"(CScalar):
        float value

    cdef cppclass CDoubleScalar" arrow::DoubleScalar"(CScalar):
        double value

    cdef cppclass CDecimal128Scalar" arrow::Decimal128Scalar"(CScalar):
        CDecimal128 value

    cdef cppclass CDecimal256Scalar" arrow::Decimal256Scalar"(CScalar):
        CDecimal256 value

    cdef cppclass CDate32Scalar" arrow::Date32Scalar"(CScalar):
        int32_t value

    cdef cppclass CDate64Scalar" arrow::Date64Scalar"(CScalar):
        int64_t value

    cdef cppclass CTime32Scalar" arrow::Time32Scalar"(CScalar):
        int32_t value

    cdef cppclass CTime64Scalar" arrow::Time64Scalar"(CScalar):
        int64_t value

    cdef cppclass CTimestampScalar" arrow::TimestampScalar"(CScalar):
        int64_t value

    cdef cppclass CDurationScalar" arrow::DurationScalar"(CScalar):
        int64_t value

    cdef cppclass CMonthDayNanoIntervalScalar \
            "arrow::MonthDayNanoIntervalScalar"(CScalar):
        pass

    cdef cppclass CBaseBinaryScalar" arrow::BaseBinaryScalar"(CScalar):
        shared_ptr[CBuffer] value

    cdef cppclass CBaseListScalar" arrow::BaseListScalar"(CScalar):
        shared_ptr[CArray] value

    cdef cppclass CListScalar" arrow::ListScalar"(CBaseListScalar):
        pass

    cdef cppclass CMapScalar" arrow::MapScalar"(CListScalar):
        pass

    cdef cppclass CStructScalar" arrow::StructScalar"(CScalar):
        vector[shared_ptr[CScalar]] value
        CResult[shared_ptr[CScalar]] field(CFieldRef ref) const

    cdef cppclass CDictionaryScalarIndexAndDictionary \
            "arrow::DictionaryScalar::ValueType":
        shared_ptr[CScalar] index
        shared_ptr[CArray] dictionary

    cdef cppclass CDictionaryScalar" arrow::DictionaryScalar"(CScalar):
        CDictionaryScalar(CDictionaryScalarIndexAndDictionary value,
                          shared_ptr[CDataType], c_bool is_valid)
        CDictionaryScalarIndexAndDictionary value

        CResult[shared_ptr[CScalar]] GetEncodedValue()

    cdef cppclass CUnionScalar" arrow::UnionScalar"(CScalar):
        int8_t type_code

    cdef cppclass CDenseUnionScalar" arrow::DenseUnionScalar"(CUnionScalar):
        shared_ptr[CScalar] value

    cdef cppclass CSparseUnionScalar" arrow::SparseUnionScalar"(CUnionScalar):
        vector[shared_ptr[CScalar]] value
        int child_id

    cdef cppclass CExtensionScalar" arrow::ExtensionScalar"(CScalar):
        CExtensionScalar(shared_ptr[CScalar] storage,
                         shared_ptr[CDataType], c_bool is_valid)
        shared_ptr[CScalar] value

    shared_ptr[CScalar] MakeScalar[Value](Value value)

    cdef cppclass CConcatenateTablesOptions" arrow::ConcatenateTablesOptions":
        c_bool unify_schemas
        CField.CMergeOptions field_merge_options

        @staticmethod
        CConcatenateTablesOptions Defaults()

    CResult[shared_ptr[CTable]] ConcatenateTables(
        const vector[shared_ptr[CTable]]& tables,
        CConcatenateTablesOptions options,
        CMemoryPool* memory_pool)

    cdef cppclass CDictionaryUnifier" arrow::DictionaryUnifier":
        @staticmethod
        CResult[shared_ptr[CChunkedArray]] UnifyChunkedArray(
            shared_ptr[CChunkedArray] array, CMemoryPool* pool)

        @staticmethod
        CResult[shared_ptr[CTable]] UnifyTable(
            const CTable& table, CMemoryPool* pool)

    shared_ptr[CScalar] MakeNullScalar(shared_ptr[CDataType] type)


cdef extern from "arrow/builder.h" namespace "arrow" nogil:

    cdef cppclass CArrayBuilder" arrow::ArrayBuilder":
        CArrayBuilder(shared_ptr[CDataType], CMemoryPool* pool)

        int64_t length()
        int64_t null_count()
        CStatus AppendNull()
        CStatus Finish(shared_ptr[CArray]* out)
        CStatus Reserve(int64_t additional_capacity)

    cdef cppclass CBooleanBuilder" arrow::BooleanBuilder"(CArrayBuilder):
        CBooleanBuilder(CMemoryPool* pool)
        CStatus Append(const c_bool val)
        CStatus Append(const uint8_t val)

    cdef cppclass CInt8Builder" arrow::Int8Builder"(CArrayBuilder):
        CInt8Builder(CMemoryPool* pool)
        CStatus Append(const int8_t value)

    cdef cppclass CInt16Builder" arrow::Int16Builder"(CArrayBuilder):
        CInt16Builder(CMemoryPool* pool)
        CStatus Append(const int16_t value)

    cdef cppclass CInt32Builder" arrow::Int32Builder"(CArrayBuilder):
        CInt32Builder(CMemoryPool* pool)
        CStatus Append(const int32_t value)

    cdef cppclass CInt64Builder" arrow::Int64Builder"(CArrayBuilder):
        CInt64Builder(CMemoryPool* pool)
        CStatus Append(const int64_t value)

    cdef cppclass CUInt8Builder" arrow::UInt8Builder"(CArrayBuilder):
        CUInt8Builder(CMemoryPool* pool)
        CStatus Append(const uint8_t value)

    cdef cppclass CUInt16Builder" arrow::UInt16Builder"(CArrayBuilder):
        CUInt16Builder(CMemoryPool* pool)
        CStatus Append(const uint16_t value)

    cdef cppclass CUInt32Builder" arrow::UInt32Builder"(CArrayBuilder):
        CUInt32Builder(CMemoryPool* pool)
        CStatus Append(const uint32_t value)

    cdef cppclass CUInt64Builder" arrow::UInt64Builder"(CArrayBuilder):
        CUInt64Builder(CMemoryPool* pool)
        CStatus Append(const uint64_t value)

    cdef cppclass CHalfFloatBuilder" arrow::HalfFloatBuilder"(CArrayBuilder):
        CHalfFloatBuilder(CMemoryPool* pool)

    cdef cppclass CFloatBuilder" arrow::FloatBuilder"(CArrayBuilder):
        CFloatBuilder(CMemoryPool* pool)
        CStatus Append(const float value)

    cdef cppclass CDoubleBuilder" arrow::DoubleBuilder"(CArrayBuilder):
        CDoubleBuilder(CMemoryPool* pool)
        CStatus Append(const double value)

    cdef cppclass CBinaryBuilder" arrow::BinaryBuilder"(CArrayBuilder):
        CArrayBuilder(shared_ptr[CDataType], CMemoryPool* pool)
        CStatus Append(const char* value, int32_t length)

    cdef cppclass CStringBuilder" arrow::StringBuilder"(CBinaryBuilder):
        CStringBuilder(CMemoryPool* pool)

        CStatus Append(const c_string& value)

    cdef cppclass CTimestampBuilder "arrow::TimestampBuilder"(CArrayBuilder):
        CTimestampBuilder(const shared_ptr[CDataType] typ, CMemoryPool* pool)
        CStatus Append(const int64_t value)

    cdef cppclass CDate32Builder "arrow::Date32Builder"(CArrayBuilder):
        CDate32Builder(CMemoryPool* pool)
        CStatus Append(const int32_t value)

    cdef cppclass CDate64Builder "arrow::Date64Builder"(CArrayBuilder):
        CDate64Builder(CMemoryPool* pool)
        CStatus Append(const int64_t value)


# Use typedef to emulate syntax for std::function<void(..)>
ctypedef void CallbackTransform(object, const shared_ptr[CBuffer]& src,
                                shared_ptr[CBuffer]* dest)

ctypedef CResult[shared_ptr[CInputStream]] StreamWrapFunc(
    shared_ptr[CInputStream])


cdef extern from "arrow/util/cancel.h" namespace "arrow" nogil:
    cdef cppclass CStopToken "arrow::StopToken":
        CStatus Poll()
        c_bool IsStopRequested()

    cdef cppclass CStopSource "arrow::StopSource":
        CStopToken token()

    CResult[CStopSource*] SetSignalStopSource()
    void ResetSignalStopSource()

    CStatus RegisterCancellingSignalHandler(vector[int] signals)
    void UnregisterCancellingSignalHandler()


cdef extern from "arrow/io/api.h" namespace "arrow::io" nogil:
    cdef enum FileMode" arrow::io::FileMode::type":
        FileMode_READ" arrow::io::FileMode::READ"
        FileMode_WRITE" arrow::io::FileMode::WRITE"
        FileMode_READWRITE" arrow::io::FileMode::READWRITE"

    cdef enum ObjectType" arrow::io::ObjectType::type":
        ObjectType_FILE" arrow::io::ObjectType::FILE"
        ObjectType_DIRECTORY" arrow::io::ObjectType::DIRECTORY"

    cdef cppclass CIOContext" arrow::io::IOContext":
        CIOContext()
        CIOContext(CStopToken)
        CIOContext(CMemoryPool*)
        CIOContext(CMemoryPool*, CStopToken)

    CIOContext c_default_io_context "arrow::io::default_io_context"()
    int GetIOThreadPoolCapacity()
    CStatus SetIOThreadPoolCapacity(int threads)

    cdef cppclass FileStatistics:
        int64_t size
        ObjectType kind

    cdef cppclass FileInterface:
        CStatus Close()
        CResult[int64_t] Tell()
        FileMode mode()
        c_bool closed()

    cdef cppclass Readable:
        # put overload under a different name to avoid cython bug with multiple
        # layers of inheritance
        CResult[shared_ptr[CBuffer]] ReadBuffer" Read"(int64_t nbytes)
        CResult[int64_t] Read(int64_t nbytes, uint8_t* out)

    cdef cppclass Seekable:
        CStatus Seek(int64_t position)

    cdef cppclass Writable:
        CStatus WriteBuffer" Write"(shared_ptr[CBuffer] data)
        CStatus Write(const uint8_t* data, int64_t nbytes)
        CStatus Flush()

    cdef cppclass COutputStream" arrow::io::OutputStream"(FileInterface,
                                                          Writable):
        pass

    cdef cppclass CInputStream" arrow::io::InputStream"(FileInterface,
                                                        Readable):
        CResult[shared_ptr[const CKeyValueMetadata]] ReadMetadata()

    cdef cppclass CRandomAccessFile" arrow::io::RandomAccessFile"(CInputStream,
                                                                  Seekable):
        CResult[int64_t] GetSize()

        @staticmethod
        CResult[shared_ptr[CInputStream]] GetStream(
            shared_ptr[CRandomAccessFile] file,
            int64_t file_offset,
            int64_t nbytes)

        CResult[int64_t] ReadAt(int64_t position, int64_t nbytes,
                                uint8_t* buffer)
        CResult[shared_ptr[CBuffer]] ReadAt(int64_t position, int64_t nbytes)
        c_bool supports_zero_copy()

    cdef cppclass WritableFile(COutputStream, Seekable):
        CStatus WriteAt(int64_t position, const uint8_t* data,
                        int64_t nbytes)

    cdef cppclass ReadWriteFileInterface(CRandomAccessFile,
                                         WritableFile):
        pass

    cdef cppclass CIOFileSystem" arrow::io::FileSystem":
        CStatus Stat(const c_string& path, FileStatistics* stat)

    cdef cppclass FileOutputStream(COutputStream):
        @staticmethod
        CResult[shared_ptr[COutputStream]] Open(const c_string& path)

        int file_descriptor()

    cdef cppclass ReadableFile(CRandomAccessFile):
        @staticmethod
        CResult[shared_ptr[ReadableFile]] Open(const c_string& path)

        @staticmethod
        CResult[shared_ptr[ReadableFile]] Open(const c_string& path,
                                               CMemoryPool* memory_pool)

        int file_descriptor()

    cdef cppclass CMemoryMappedFile \
            " arrow::io::MemoryMappedFile"(ReadWriteFileInterface):

        @staticmethod
        CResult[shared_ptr[CMemoryMappedFile]] Create(const c_string& path,
                                                      int64_t size)

        @staticmethod
        CResult[shared_ptr[CMemoryMappedFile]] Open(const c_string& path,
                                                    FileMode mode)

        CStatus Resize(int64_t size)

        int file_descriptor()

    cdef cppclass CCompressedInputStream \
            " arrow::io::CompressedInputStream"(CInputStream):
        @staticmethod
        CResult[shared_ptr[CCompressedInputStream]] Make(
            CCodec* codec, shared_ptr[CInputStream] raw)

    cdef cppclass CCompressedOutputStream \
            " arrow::io::CompressedOutputStream"(COutputStream):
        @staticmethod
        CResult[shared_ptr[CCompressedOutputStream]] Make(
            CCodec* codec, shared_ptr[COutputStream] raw)

    cdef cppclass CBufferedInputStream \
            " arrow::io::BufferedInputStream"(CInputStream):

        @staticmethod
        CResult[shared_ptr[CBufferedInputStream]] Create(
            int64_t buffer_size, CMemoryPool* pool,
            shared_ptr[CInputStream] raw)

        CResult[shared_ptr[CInputStream]] Detach()

    cdef cppclass CBufferedOutputStream \
            " arrow::io::BufferedOutputStream"(COutputStream):

        @staticmethod
        CResult[shared_ptr[CBufferedOutputStream]] Create(
            int64_t buffer_size, CMemoryPool* pool,
            shared_ptr[COutputStream] raw)

        CResult[shared_ptr[COutputStream]] Detach()

    cdef cppclass CTransformInputStreamVTable \
            "arrow::py::TransformInputStreamVTable":
        CTransformInputStreamVTable()
        function[CallbackTransform] transform

    shared_ptr[CInputStream] MakeTransformInputStream \
        "arrow::py::MakeTransformInputStream"(
        shared_ptr[CInputStream] wrapped, CTransformInputStreamVTable vtable,
        object method_arg)

    shared_ptr[function[StreamWrapFunc]] MakeStreamTransformFunc \
        "arrow::py::MakeStreamTransformFunc"(
        CTransformInputStreamVTable vtable,
        object method_arg)

    # ----------------------------------------------------------------------
    # HDFS

    CStatus HaveLibHdfs()
    CStatus HaveLibHdfs3()

    cdef enum HdfsDriver" arrow::io::HdfsDriver":
        HdfsDriver_LIBHDFS" arrow::io::HdfsDriver::LIBHDFS"
        HdfsDriver_LIBHDFS3" arrow::io::HdfsDriver::LIBHDFS3"

    cdef cppclass HdfsConnectionConfig:
        c_string host
        int port
        c_string user
        c_string kerb_ticket
        unordered_map[c_string, c_string] extra_conf
        HdfsDriver driver

    cdef cppclass HdfsPathInfo:
        ObjectType kind
        c_string name
        c_string owner
        c_string group
        int32_t last_modified_time
        int32_t last_access_time
        int64_t size
        int16_t replication
        int64_t block_size
        int16_t permissions

    cdef cppclass HdfsReadableFile(CRandomAccessFile):
        pass

    cdef cppclass HdfsOutputStream(COutputStream):
        pass

    cdef cppclass CIOHadoopFileSystem \
            "arrow::io::HadoopFileSystem"(CIOFileSystem):
        @staticmethod
        CStatus Connect(const HdfsConnectionConfig* config,
                        shared_ptr[CIOHadoopFileSystem]* client)

        CStatus MakeDirectory(const c_string& path)

        CStatus Delete(const c_string& path, c_bool recursive)

        CStatus Disconnect()

        c_bool Exists(const c_string& path)

        CStatus Chmod(const c_string& path, int mode)
        CStatus Chown(const c_string& path, const char* owner,
                      const char* group)

        CStatus GetCapacity(int64_t* nbytes)
        CStatus GetUsed(int64_t* nbytes)

        CStatus ListDirectory(const c_string& path,
                              vector[HdfsPathInfo]* listing)

        CStatus GetPathInfo(const c_string& path, HdfsPathInfo* info)

        CStatus Rename(const c_string& src, const c_string& dst)

        CStatus OpenReadable(const c_string& path,
                             shared_ptr[HdfsReadableFile]* handle)

        CStatus OpenWritable(const c_string& path, c_bool append,
                             int32_t buffer_size, int16_t replication,
                             int64_t default_block_size,
                             shared_ptr[HdfsOutputStream]* handle)

    cdef cppclass CBufferReader \
            " arrow::io::BufferReader"(CRandomAccessFile):
        CBufferReader(const shared_ptr[CBuffer]& buffer)
        CBufferReader(const uint8_t* data, int64_t nbytes)

    cdef cppclass CBufferOutputStream \
            " arrow::io::BufferOutputStream"(COutputStream):
        CBufferOutputStream(const shared_ptr[CResizableBuffer]& buffer)

    cdef cppclass CMockOutputStream \
            " arrow::io::MockOutputStream"(COutputStream):
        CMockOutputStream()
        int64_t GetExtentBytesWritten()

    cdef cppclass CFixedSizeBufferWriter \
            " arrow::io::FixedSizeBufferWriter"(WritableFile):
        CFixedSizeBufferWriter(const shared_ptr[CBuffer]& buffer)

        void set_memcopy_threads(int num_threads)
        void set_memcopy_blocksize(int64_t blocksize)
        void set_memcopy_threshold(int64_t threshold)


cdef extern from "arrow/ipc/api.h" namespace "arrow::ipc" nogil:
    cdef enum MessageType" arrow::ipc::MessageType":
        MessageType_SCHEMA" arrow::ipc::MessageType::SCHEMA"
        MessageType_RECORD_BATCH" arrow::ipc::MessageType::RECORD_BATCH"
        MessageType_DICTIONARY_BATCH \
            " arrow::ipc::MessageType::DICTIONARY_BATCH"

    # TODO: use "cpdef enum class" to automatically get a Python wrapper?
    # See
    # https://github.com/cython/cython/commit/2c7c22f51405299a4e247f78edf52957d30cf71d#diff-61c1365c0f761a8137754bb3a73bfbf7
    ctypedef enum CMetadataVersion" arrow::ipc::MetadataVersion":
        CMetadataVersion_V1" arrow::ipc::MetadataVersion::V1"
        CMetadataVersion_V2" arrow::ipc::MetadataVersion::V2"
        CMetadataVersion_V3" arrow::ipc::MetadataVersion::V3"
        CMetadataVersion_V4" arrow::ipc::MetadataVersion::V4"
        CMetadataVersion_V5" arrow::ipc::MetadataVersion::V5"

    cdef cppclass CIpcWriteOptions" arrow::ipc::IpcWriteOptions":
        c_bool allow_64bit
        int max_recursion_depth
        int32_t alignment
        c_bool write_legacy_ipc_format
        CMemoryPool* memory_pool
        CMetadataVersion metadata_version
        shared_ptr[CCodec] codec
        c_bool use_threads
        c_bool emit_dictionary_deltas
        c_bool unify_dictionaries

        CIpcWriteOptions()
        CIpcWriteOptions(CIpcWriteOptions&&)

        @staticmethod
        CIpcWriteOptions Defaults()

    cdef cppclass CIpcReadOptions" arrow::ipc::IpcReadOptions":
        int max_recursion_depth
        CMemoryPool* memory_pool
        vector[int] included_fields
        c_bool use_threads
        c_bool ensure_native_endian

        @staticmethod
        CIpcReadOptions Defaults()

    cdef cppclass CIpcWriteStats" arrow::ipc::WriteStats":
        int64_t num_messages
        int64_t num_record_batches
        int64_t num_dictionary_batches
        int64_t num_dictionary_deltas
        int64_t num_replaced_dictionaries

    cdef cppclass CIpcReadStats" arrow::ipc::ReadStats":
        int64_t num_messages
        int64_t num_record_batches
        int64_t num_dictionary_batches
        int64_t num_dictionary_deltas
        int64_t num_replaced_dictionaries

    cdef cppclass CDictionaryMemo" arrow::ipc::DictionaryMemo":
        pass

    cdef cppclass CIpcPayload" arrow::ipc::IpcPayload":
        MessageType type
        shared_ptr[CBuffer] metadata
        vector[shared_ptr[CBuffer]] body_buffers
        int64_t body_length

    cdef cppclass CMessage" arrow::ipc::Message":
        CResult[unique_ptr[CMessage]] Open(shared_ptr[CBuffer] metadata,
                                           shared_ptr[CBuffer] body)

        shared_ptr[CBuffer] body()

        c_bool Equals(const CMessage& other)

        shared_ptr[CBuffer] metadata()
        CMetadataVersion metadata_version()
        MessageType type()

        CStatus SerializeTo(COutputStream* stream,
                            const CIpcWriteOptions& options,
                            int64_t* output_length)

    c_string FormatMessageType(MessageType type)

    cdef cppclass CMessageReader" arrow::ipc::MessageReader":
        @staticmethod
        unique_ptr[CMessageReader] Open(const shared_ptr[CInputStream]& stream)

        CResult[unique_ptr[CMessage]] ReadNextMessage()

    cdef cppclass CRecordBatchWriter" arrow::ipc::RecordBatchWriter":
        CStatus Close()
        CStatus WriteRecordBatch(const CRecordBatch& batch)
        CStatus WriteRecordBatch(
            const CRecordBatch& batch,
            const shared_ptr[const CKeyValueMetadata]& metadata)
        CStatus WriteTable(const CTable& table, int64_t max_chunksize)

        CIpcWriteStats stats()

    cdef cppclass CRecordBatchStreamReader \
            " arrow::ipc::RecordBatchStreamReader"(CRecordBatchReader):
        @staticmethod
        CResult[shared_ptr[CRecordBatchReader]] Open(
            const shared_ptr[CInputStream], const CIpcReadOptions&)

        @staticmethod
        CResult[shared_ptr[CRecordBatchReader]] Open2" Open"(
            unique_ptr[CMessageReader] message_reader,
            const CIpcReadOptions& options)

        CIpcReadStats stats()

    cdef cppclass CRecordBatchFileReader \
            " arrow::ipc::RecordBatchFileReader":
        @staticmethod
        CResult[shared_ptr[CRecordBatchFileReader]] Open(
            CRandomAccessFile* file,
            const CIpcReadOptions& options)

        @staticmethod
        CResult[shared_ptr[CRecordBatchFileReader]] Open2" Open"(
            CRandomAccessFile* file, int64_t footer_offset,
            const CIpcReadOptions& options)

        shared_ptr[CSchema] schema()

        int num_record_batches()

        CResult[shared_ptr[CRecordBatch]] ReadRecordBatch(int i)

        CResult[CRecordBatchWithMetadata] ReadRecordBatchWithCustomMetadata(int i)

        CIpcReadStats stats()

    CResult[shared_ptr[CRecordBatchWriter]] MakeStreamWriter(
        shared_ptr[COutputStream] sink, const shared_ptr[CSchema]& schema,
        CIpcWriteOptions& options)

    CResult[shared_ptr[CRecordBatchWriter]] MakeFileWriter(
        shared_ptr[COutputStream] sink, const shared_ptr[CSchema]& schema,
        CIpcWriteOptions& options)

    CResult[unique_ptr[CMessage]] ReadMessage(CInputStream* stream,
                                              CMemoryPool* pool)

    CStatus GetRecordBatchSize(const CRecordBatch& batch, int64_t* size)
    CStatus GetTensorSize(const CTensor& tensor, int64_t* size)

    CStatus WriteTensor(const CTensor& tensor, COutputStream* dst,
                        int32_t* metadata_length,
                        int64_t* body_length)

    CResult[shared_ptr[CTensor]] ReadTensor(CInputStream* stream)

    CResult[shared_ptr[CRecordBatch]] ReadRecordBatch(
        const CMessage& message, const shared_ptr[CSchema]& schema,
        CDictionaryMemo* dictionary_memo,
        const CIpcReadOptions& options)

    CResult[shared_ptr[CBuffer]] SerializeSchema(
        const CSchema& schema, CMemoryPool* pool)

    CResult[shared_ptr[CBuffer]] SerializeRecordBatch(
        const CRecordBatch& schema, const CIpcWriteOptions& options)

    CResult[shared_ptr[CSchema]] ReadSchema(const CMessage& message,
                                            CDictionaryMemo* dictionary_memo)

    CResult[shared_ptr[CSchema]] ReadSchema(CInputStream* stream,
                                            CDictionaryMemo* dictionary_memo)

    CResult[shared_ptr[CRecordBatch]] ReadRecordBatch(
        const shared_ptr[CSchema]& schema,
        CDictionaryMemo* dictionary_memo,
        const CIpcReadOptions& options,
        CInputStream* stream)

    CStatus AlignStream(CInputStream* stream, int64_t alignment)
    CStatus AlignStream(COutputStream* stream, int64_t alignment)

    cdef CStatus GetRecordBatchPayload \
        " arrow::ipc::GetRecordBatchPayload"(
            const CRecordBatch& batch,
            const CIpcWriteOptions& options,
            CIpcPayload* out)


cdef extern from "arrow/util/value_parsing.h" namespace "arrow" nogil:
    cdef cppclass CTimestampParser" arrow::TimestampParser":
        const char* kind() const
        const char* format() const

        @staticmethod
        shared_ptr[CTimestampParser] MakeStrptime(c_string format)

        @staticmethod
        shared_ptr[CTimestampParser] MakeISO8601()


cdef extern from "arrow/csv/api.h" namespace "arrow::csv" nogil:

    cdef cppclass CCSVInvalidRow" arrow::csv::InvalidRow":
        int32_t expected_columns
        int32_t actual_columns
        int64_t number
        c_string text

    ctypedef enum CInvalidRowResult" arrow::csv::InvalidRowResult":
        CInvalidRowResult_Error" arrow::csv::InvalidRowResult::Error"
        CInvalidRowResult_Skip" arrow::csv::InvalidRowResult::Skip"

    ctypedef CInvalidRowResult CInvalidRowHandler(const CCSVInvalidRow&)


cdef extern from "arrow/csv/api.h" namespace "arrow::csv" nogil:

    ctypedef enum CQuotingStyle "arrow::csv::QuotingStyle":
        CQuotingStyle_Needed "arrow::csv::QuotingStyle::Needed"
        CQuotingStyle_AllValid "arrow::csv::QuotingStyle::AllValid"
        CQuotingStyle_None "arrow::csv::QuotingStyle::None"

    cdef cppclass CCSVParseOptions" arrow::csv::ParseOptions":
        unsigned char delimiter
        c_bool quoting
        unsigned char quote_char
        c_bool double_quote
        c_bool escaping
        unsigned char escape_char
        c_bool newlines_in_values
        c_bool ignore_empty_lines
        function[CInvalidRowHandler] invalid_row_handler

        CCSVParseOptions()
        CCSVParseOptions(CCSVParseOptions&&)

        @staticmethod
        CCSVParseOptions Defaults()

        CStatus Validate()

    cdef cppclass CCSVConvertOptions" arrow::csv::ConvertOptions":
        c_bool check_utf8
        unordered_map[c_string, shared_ptr[CDataType]] column_types
        vector[c_string] null_values
        vector[c_string] true_values
        vector[c_string] false_values
        c_bool strings_can_be_null
        c_bool quoted_strings_can_be_null
        vector[shared_ptr[CTimestampParser]] timestamp_parsers

        c_bool auto_dict_encode
        int32_t auto_dict_max_cardinality
        unsigned char decimal_point

        vector[c_string] include_columns
        c_bool include_missing_columns

        CCSVConvertOptions()
        CCSVConvertOptions(CCSVConvertOptions&&)

        @staticmethod
        CCSVConvertOptions Defaults()

        CStatus Validate()

    cdef cppclass CCSVReadOptions" arrow::csv::ReadOptions":
        c_bool use_threads
        int32_t block_size
        int32_t skip_rows
        int32_t skip_rows_after_names
        vector[c_string] column_names
        c_bool autogenerate_column_names

        CCSVReadOptions()
        CCSVReadOptions(CCSVReadOptions&&)

        @staticmethod
        CCSVReadOptions Defaults()

        CStatus Validate()

    cdef cppclass CCSVWriteOptions" arrow::csv::WriteOptions":
        c_bool include_header
        int32_t batch_size
        unsigned char delimiter
        CQuotingStyle quoting_style
        CIOContext io_context

        CCSVWriteOptions()
        CCSVWriteOptions(CCSVWriteOptions&&)

        @staticmethod
        CCSVWriteOptions Defaults()

        CStatus Validate()

    cdef cppclass CCSVReader" arrow::csv::TableReader":
        @staticmethod
        CResult[shared_ptr[CCSVReader]] Make(
            CIOContext, shared_ptr[CInputStream],
            CCSVReadOptions, CCSVParseOptions, CCSVConvertOptions)

        CResult[shared_ptr[CTable]] Read()

    cdef cppclass CCSVStreamingReader" arrow::csv::StreamingReader"(
            CRecordBatchReader):
        @staticmethod
        CResult[shared_ptr[CCSVStreamingReader]] Make(
            CIOContext, shared_ptr[CInputStream],
            CCSVReadOptions, CCSVParseOptions, CCSVConvertOptions)

    cdef CStatus WriteCSV(CTable&, CCSVWriteOptions& options, COutputStream*)
    cdef CStatus WriteCSV(
        CRecordBatch&, CCSVWriteOptions& options, COutputStream*)
    cdef CResult[shared_ptr[CRecordBatchWriter]] MakeCSVWriter(
        shared_ptr[COutputStream], shared_ptr[CSchema],
        CCSVWriteOptions& options)


cdef extern from "arrow/json/options.h" nogil:

    ctypedef enum CUnexpectedFieldBehavior \
            "arrow::json::UnexpectedFieldBehavior":
        CUnexpectedFieldBehavior_Ignore \
            "arrow::json::UnexpectedFieldBehavior::Ignore"
        CUnexpectedFieldBehavior_Error \
            "arrow::json::UnexpectedFieldBehavior::Error"
        CUnexpectedFieldBehavior_InferType \
            "arrow::json::UnexpectedFieldBehavior::InferType"

    cdef cppclass CJSONReadOptions" arrow::json::ReadOptions":
        c_bool use_threads
        int32_t block_size

        @staticmethod
        CJSONReadOptions Defaults()

    cdef cppclass CJSONParseOptions" arrow::json::ParseOptions":
        shared_ptr[CSchema] explicit_schema
        c_bool newlines_in_values
        CUnexpectedFieldBehavior unexpected_field_behavior

        @staticmethod
        CJSONParseOptions Defaults()


cdef extern from "arrow/json/reader.h" namespace "arrow::json" nogil:

    cdef cppclass CJSONReader" arrow::json::TableReader":
        @staticmethod
        CResult[shared_ptr[CJSONReader]] Make(
            CMemoryPool*, shared_ptr[CInputStream],
            CJSONReadOptions, CJSONParseOptions)

        CResult[shared_ptr[CTable]] Read()


cdef extern from "arrow/util/thread_pool.h" namespace "arrow::internal" nogil:

    cdef cppclass CExecutor "arrow::internal::Executor":
        pass

    cdef cppclass CThreadPool "arrow::internal::ThreadPool"(CExecutor):
        @staticmethod
        CResult[shared_ptr[CThreadPool]] Make(int threads)

    CThreadPool* GetCpuThreadPool()


cdef extern from "arrow/compute/api.h" namespace "arrow::compute" nogil:

    cdef cppclass CExecContext" arrow::compute::ExecContext":
        CExecContext()
        CExecContext(CMemoryPool* pool)
        CExecContext(CMemoryPool* pool, CExecutor* exc)

        CMemoryPool* memory_pool() const
        CExecutor* executor()

    cdef cppclass CKernelSignature" arrow::compute::KernelSignature":
        c_string ToString() const

    cdef cppclass CKernel" arrow::compute::Kernel":
        shared_ptr[CKernelSignature] signature

    cdef cppclass CArrayKernel" arrow::compute::ArrayKernel"(CKernel):
        pass

    cdef cppclass CScalarKernel" arrow::compute::ScalarKernel"(CArrayKernel):
        pass

    cdef cppclass CVectorKernel" arrow::compute::VectorKernel"(CArrayKernel):
        pass

    cdef cppclass CScalarAggregateKernel \
            " arrow::compute::ScalarAggregateKernel"(CKernel):
        pass

    cdef cppclass CHashAggregateKernel \
            " arrow::compute::HashAggregateKernel"(CKernel):
        pass

    cdef cppclass CArity" arrow::compute::Arity":
        int num_args
        c_bool is_varargs

        CArity()

        CArity(int num_args, c_bool is_varargs)

    cdef enum FunctionKind" arrow::compute::Function::Kind":
        FunctionKind_SCALAR" arrow::compute::Function::SCALAR"
        FunctionKind_VECTOR" arrow::compute::Function::VECTOR"
        FunctionKind_SCALAR_AGGREGATE \
            " arrow::compute::Function::SCALAR_AGGREGATE"
        FunctionKind_HASH_AGGREGATE \
            " arrow::compute::Function::HASH_AGGREGATE"
        FunctionKind_META \
            " arrow::compute::Function::META"

    cdef cppclass CFunctionDoc" arrow::compute::FunctionDoc":
        c_string summary
        c_string description
        vector[c_string] arg_names
        c_string options_class
        c_bool options_required

    cdef cppclass CFunctionOptionsType" arrow::compute::FunctionOptionsType":
        const char* type_name() const

    cdef cppclass CFunctionOptions" arrow::compute::FunctionOptions":
        const CFunctionOptionsType* options_type() const
        const char* type_name() const
        c_bool Equals(const CFunctionOptions& other) const
        c_string ToString() const
        unique_ptr[CFunctionOptions] Copy() const
        CResult[shared_ptr[CBuffer]] Serialize() const

        @staticmethod
        CResult[unique_ptr[CFunctionOptions]] Deserialize(
            const c_string& type_name, const CBuffer& buffer)

    cdef cppclass CFunction" arrow::compute::Function":
        const c_string& name() const
        FunctionKind kind() const
        const CArity& arity() const
        const CFunctionDoc& doc() const
        int num_kernels() const
        CResult[CDatum] Execute(const vector[CDatum]& args,
                                const CFunctionOptions* options,
                                CExecContext* ctx) const
        CResult[CDatum] Execute(const CExecBatch& args,
                                const CFunctionOptions* options,
                                CExecContext* ctx) const

    cdef cppclass CScalarFunction" arrow::compute::ScalarFunction"(CFunction):
        vector[const CScalarKernel*] kernels() const

    cdef cppclass CVectorFunction" arrow::compute::VectorFunction"(CFunction):
        vector[const CVectorKernel*] kernels() const

    cdef cppclass CScalarAggregateFunction \
            " arrow::compute::ScalarAggregateFunction"(CFunction):
        vector[const CScalarAggregateKernel*] kernels() const

    cdef cppclass CHashAggregateFunction \
            " arrow::compute::HashAggregateFunction"(CFunction):
        vector[const CHashAggregateKernel*] kernels() const

    cdef cppclass CMetaFunction" arrow::compute::MetaFunction"(CFunction):
        pass

    cdef cppclass CFunctionRegistry" arrow::compute::FunctionRegistry":
        CResult[shared_ptr[CFunction]] GetFunction(
            const c_string& name) const
        vector[c_string] GetFunctionNames() const
        int num_functions() const

    CFunctionRegistry* GetFunctionRegistry()

    cdef cppclass CElementWiseAggregateOptions \
            "arrow::compute::ElementWiseAggregateOptions"(CFunctionOptions):
        CElementWiseAggregateOptions(c_bool skip_nulls)
        c_bool skip_nulls

    ctypedef enum CRoundMode \
            "arrow::compute::RoundMode":
        CRoundMode_DOWN \
            "arrow::compute::RoundMode::DOWN"
        CRoundMode_UP \
            "arrow::compute::RoundMode::UP"
        CRoundMode_TOWARDS_ZERO \
            "arrow::compute::RoundMode::TOWARDS_ZERO"
        CRoundMode_TOWARDS_INFINITY \
            "arrow::compute::RoundMode::TOWARDS_INFINITY"
        CRoundMode_HALF_DOWN \
            "arrow::compute::RoundMode::HALF_DOWN"
        CRoundMode_HALF_UP \
            "arrow::compute::RoundMode::HALF_UP"
        CRoundMode_HALF_TOWARDS_ZERO \
            "arrow::compute::RoundMode::HALF_TOWARDS_ZERO"
        CRoundMode_HALF_TOWARDS_INFINITY \
            "arrow::compute::RoundMode::HALF_TOWARDS_INFINITY"
        CRoundMode_HALF_TO_EVEN \
            "arrow::compute::RoundMode::HALF_TO_EVEN"
        CRoundMode_HALF_TO_ODD \
            "arrow::compute::RoundMode::HALF_TO_ODD"

    cdef cppclass CRoundOptions \
            "arrow::compute::RoundOptions"(CFunctionOptions):
        CRoundOptions(int64_t ndigits, CRoundMode round_mode)
        int64_t ndigits
        CRoundMode round_mode

    ctypedef enum CCalendarUnit \
            "arrow::compute::CalendarUnit":
        CCalendarUnit_NANOSECOND \
            "arrow::compute::CalendarUnit::NANOSECOND"
        CCalendarUnit_MICROSECOND \
            "arrow::compute::CalendarUnit::MICROSECOND"
        CCalendarUnit_MILLISECOND \
            "arrow::compute::CalendarUnit::MILLISECOND"
        CCalendarUnit_SECOND \
            "arrow::compute::CalendarUnit::SECOND"
        CCalendarUnit_MINUTE \
            "arrow::compute::CalendarUnit::MINUTE"
        CCalendarUnit_HOUR \
            "arrow::compute::CalendarUnit::HOUR"
        CCalendarUnit_DAY \
            "arrow::compute::CalendarUnit::DAY"
        CCalendarUnit_WEEK \
            "arrow::compute::CalendarUnit::WEEK"
        CCalendarUnit_MONTH \
            "arrow::compute::CalendarUnit::MONTH"
        CCalendarUnit_QUARTER \
            "arrow::compute::CalendarUnit::QUARTER"
        CCalendarUnit_YEAR \
            "arrow::compute::CalendarUnit::YEAR"

    cdef cppclass CRoundTemporalOptions \
            "arrow::compute::RoundTemporalOptions"(CFunctionOptions):
        CRoundTemporalOptions(int multiple, CCalendarUnit unit,
                              c_bool week_starts_monday,
                              c_bool ceil_is_strictly_greater,
                              c_bool calendar_based_origin)
        int multiple
        CCalendarUnit unit
        c_bool week_starts_monday
        c_bool ceil_is_strictly_greater
        c_bool calendar_based_origin

    cdef cppclass CRoundToMultipleOptions \
            "arrow::compute::RoundToMultipleOptions"(CFunctionOptions):
        CRoundToMultipleOptions(shared_ptr[CScalar] multiple, CRoundMode round_mode)
        shared_ptr[CScalar] multiple
        CRoundMode round_mode

    cdef enum CJoinNullHandlingBehavior \
            "arrow::compute::JoinOptions::NullHandlingBehavior":
        CJoinNullHandlingBehavior_EMIT_NULL \
            "arrow::compute::JoinOptions::EMIT_NULL"
        CJoinNullHandlingBehavior_SKIP \
            "arrow::compute::JoinOptions::SKIP"
        CJoinNullHandlingBehavior_REPLACE \
            "arrow::compute::JoinOptions::REPLACE"

    cdef cppclass CJoinOptions \
            "arrow::compute::JoinOptions"(CFunctionOptions):
        CJoinOptions(CJoinNullHandlingBehavior null_handling,
                     c_string null_replacement)
        CJoinNullHandlingBehavior null_handling
        c_string null_replacement

    cdef cppclass CMatchSubstringOptions \
            "arrow::compute::MatchSubstringOptions"(CFunctionOptions):
        CMatchSubstringOptions(c_string pattern, c_bool ignore_case)
        c_string pattern
        c_bool ignore_case

    cdef cppclass CTrimOptions \
            "arrow::compute::TrimOptions"(CFunctionOptions):
        CTrimOptions(c_string characters)
        c_string characters

    cdef cppclass CPadOptions \
            "arrow::compute::PadOptions"(CFunctionOptions):
        CPadOptions(int64_t width, c_string padding)
        int64_t width
        c_string padding

    cdef cppclass CSliceOptions \
            "arrow::compute::SliceOptions"(CFunctionOptions):
        CSliceOptions(int64_t start, int64_t stop, int64_t step)
        int64_t start
        int64_t stop
        int64_t step

    cdef cppclass CListSliceOptions \
            "arrow::compute::ListSliceOptions"(CFunctionOptions):
        CListSliceOptions(int64_t start, optional[int64_t] stop,
                          int64_t step,
                          optional[c_bool] return_fixed_size_list)
        int64_t start
        optional[int64_t] stop
        int64_t step
        optional[c_bool] return_fixed_size_list

    cdef cppclass CSplitOptions \
            "arrow::compute::SplitOptions"(CFunctionOptions):
        CSplitOptions(int64_t max_splits, c_bool reverse)
        int64_t max_splits
        c_bool reverse

    cdef cppclass CSplitPatternOptions \
            "arrow::compute::SplitPatternOptions"(CFunctionOptions):
        CSplitPatternOptions(c_string pattern, int64_t max_splits,
                             c_bool reverse)
        int64_t max_splits
        c_bool reverse
        c_string pattern

    cdef cppclass CReplaceSliceOptions \
            "arrow::compute::ReplaceSliceOptions"(CFunctionOptions):
        CReplaceSliceOptions(int64_t start, int64_t stop, c_string replacement)
        int64_t start
        int64_t stop
        c_string replacement

    cdef cppclass CReplaceSubstringOptions \
            "arrow::compute::ReplaceSubstringOptions"(CFunctionOptions):
        CReplaceSubstringOptions(c_string pattern, c_string replacement,
                                 int64_t max_replacements)
        c_string pattern
        c_string replacement
        int64_t max_replacements

    cdef cppclass CExtractRegexOptions \
            "arrow::compute::ExtractRegexOptions"(CFunctionOptions):
        CExtractRegexOptions(c_string pattern)
        c_string pattern

    cdef cppclass CCastOptions" arrow::compute::CastOptions"(CFunctionOptions):
        CCastOptions()
        CCastOptions(c_bool safe)
        CCastOptions(CCastOptions&& options)

        @staticmethod
        CCastOptions Safe()

        @staticmethod
        CCastOptions Unsafe()
        shared_ptr[CDataType] to_type
        c_bool allow_int_overflow
        c_bool allow_time_truncate
        c_bool allow_time_overflow
        c_bool allow_decimal_truncate
        c_bool allow_float_truncate
        c_bool allow_invalid_utf8

    cdef enum CFilterNullSelectionBehavior \
            "arrow::compute::FilterOptions::NullSelectionBehavior":
        CFilterNullSelectionBehavior_DROP \
            "arrow::compute::FilterOptions::DROP"
        CFilterNullSelectionBehavior_EMIT_NULL \
            "arrow::compute::FilterOptions::EMIT_NULL"

    cdef cppclass CFilterOptions \
            " arrow::compute::FilterOptions"(CFunctionOptions):
        CFilterOptions()
        CFilterOptions(CFilterNullSelectionBehavior null_selection_behavior)
        CFilterNullSelectionBehavior null_selection_behavior

    cdef enum CDictionaryEncodeNullEncodingBehavior \
            "arrow::compute::DictionaryEncodeOptions::NullEncodingBehavior":
        CDictionaryEncodeNullEncodingBehavior_ENCODE \
            "arrow::compute::DictionaryEncodeOptions::ENCODE"
        CDictionaryEncodeNullEncodingBehavior_MASK \
            "arrow::compute::DictionaryEncodeOptions::MASK"

    cdef cppclass CDictionaryEncodeOptions \
            "arrow::compute::DictionaryEncodeOptions"(CFunctionOptions):
        CDictionaryEncodeOptions(
            CDictionaryEncodeNullEncodingBehavior null_encoding)
        CDictionaryEncodeNullEncodingBehavior null_encoding

    cdef cppclass CTakeOptions \
            " arrow::compute::TakeOptions"(CFunctionOptions):
        CTakeOptions(c_bool boundscheck)
        c_bool boundscheck

    cdef cppclass CStrptimeOptions \
            "arrow::compute::StrptimeOptions"(CFunctionOptions):
        CStrptimeOptions(c_string format, TimeUnit unit, c_bool raise_error)
        c_string format
        TimeUnit unit
        c_bool raise_error

    cdef cppclass CStrftimeOptions \
            "arrow::compute::StrftimeOptions"(CFunctionOptions):
        CStrftimeOptions(c_string format, c_string locale)
        c_string format
        c_string locale

    cdef cppclass CDayOfWeekOptions \
            "arrow::compute::DayOfWeekOptions"(CFunctionOptions):
        CDayOfWeekOptions(c_bool count_from_zero, uint32_t week_start)
        c_bool count_from_zero
        uint32_t week_start

    cdef enum CAssumeTimezoneAmbiguous \
            "arrow::compute::AssumeTimezoneOptions::Ambiguous":
        CAssumeTimezoneAmbiguous_AMBIGUOUS_RAISE \
            "arrow::compute::AssumeTimezoneOptions::AMBIGUOUS_RAISE"
        CAssumeTimezoneAmbiguous_AMBIGUOUS_EARLIEST \
            "arrow::compute::AssumeTimezoneOptions::AMBIGUOUS_EARLIEST"
        CAssumeTimezoneAmbiguous_AMBIGUOUS_LATEST \
            "arrow::compute::AssumeTimezoneOptions::AMBIGUOUS_LATEST"

    cdef enum CAssumeTimezoneNonexistent \
            "arrow::compute::AssumeTimezoneOptions::Nonexistent":
        CAssumeTimezoneNonexistent_NONEXISTENT_RAISE \
            "arrow::compute::AssumeTimezoneOptions::NONEXISTENT_RAISE"
        CAssumeTimezoneNonexistent_NONEXISTENT_EARLIEST \
            "arrow::compute::AssumeTimezoneOptions::NONEXISTENT_EARLIEST"
        CAssumeTimezoneNonexistent_NONEXISTENT_LATEST \
            "arrow::compute::AssumeTimezoneOptions::NONEXISTENT_LATEST"

    cdef cppclass CAssumeTimezoneOptions \
            "arrow::compute::AssumeTimezoneOptions"(CFunctionOptions):
        CAssumeTimezoneOptions(c_string timezone,
                               CAssumeTimezoneAmbiguous ambiguous,
                               CAssumeTimezoneNonexistent nonexistent)
        c_string timezone
        CAssumeTimezoneAmbiguous ambiguous
        CAssumeTimezoneNonexistent nonexistent

    cdef cppclass CWeekOptions \
            "arrow::compute::WeekOptions"(CFunctionOptions):
        CWeekOptions(c_bool week_starts_monday, c_bool count_from_zero,
                     c_bool first_week_is_fully_in_year)
        c_bool week_starts_monday
        c_bool count_from_zero
        c_bool first_week_is_fully_in_year

    cdef cppclass CNullOptions \
            "arrow::compute::NullOptions"(CFunctionOptions):
        CNullOptions(c_bool nan_is_null)
        c_bool nan_is_null

    cdef cppclass CVarianceOptions \
            "arrow::compute::VarianceOptions"(CFunctionOptions):
        CVarianceOptions(int ddof, c_bool skip_nulls, uint32_t min_count)
        int ddof
        c_bool skip_nulls
        uint32_t min_count

    cdef cppclass CScalarAggregateOptions \
            "arrow::compute::ScalarAggregateOptions"(CFunctionOptions):
        CScalarAggregateOptions(c_bool skip_nulls, uint32_t min_count)
        c_bool skip_nulls
        uint32_t min_count

    cdef enum CCountMode "arrow::compute::CountOptions::CountMode":
        CCountMode_ONLY_VALID "arrow::compute::CountOptions::ONLY_VALID"
        CCountMode_ONLY_NULL "arrow::compute::CountOptions::ONLY_NULL"
        CCountMode_ALL "arrow::compute::CountOptions::ALL"

    cdef cppclass CCountOptions \
            "arrow::compute::CountOptions"(CFunctionOptions):
        CCountOptions(CCountMode mode)
        CCountMode mode

    cdef cppclass CModeOptions \
            "arrow::compute::ModeOptions"(CFunctionOptions):
        CModeOptions(int64_t n, c_bool skip_nulls, uint32_t min_count)
        int64_t n
        c_bool skip_nulls
        uint32_t min_count

    cdef cppclass CIndexOptions \
            "arrow::compute::IndexOptions"(CFunctionOptions):
        CIndexOptions(shared_ptr[CScalar] value)
        shared_ptr[CScalar] value

    cdef enum CMapLookupOccurrence \
            "arrow::compute::MapLookupOptions::Occurrence":
        CMapLookupOccurrence_ALL "arrow::compute::MapLookupOptions::ALL"
        CMapLookupOccurrence_FIRST "arrow::compute::MapLookupOptions::FIRST"
        CMapLookupOccurrence_LAST "arrow::compute::MapLookupOptions::LAST"

    cdef cppclass CMapLookupOptions \
            "arrow::compute::MapLookupOptions"(CFunctionOptions):
        CMapLookupOptions(shared_ptr[CScalar] query_key,
                          CMapLookupOccurrence occurrence)
        CMapLookupOccurrence occurrence
        shared_ptr[CScalar] query_key

    cdef cppclass CMakeStructOptions \
            "arrow::compute::MakeStructOptions"(CFunctionOptions):
        CMakeStructOptions(vector[c_string] n,
                           vector[c_bool] r,
                           vector[shared_ptr[const CKeyValueMetadata]] m)
        CMakeStructOptions(vector[c_string] n)
        vector[c_string] field_names
        vector[c_bool] field_nullability
        vector[shared_ptr[const CKeyValueMetadata]] field_metadata

    cdef cppclass CStructFieldOptions \
            "arrow::compute::StructFieldOptions"(CFunctionOptions):
        CStructFieldOptions(vector[int] indices)
        CStructFieldOptions(CFieldRef field_ref)
        vector[int] indices
        CFieldRef field_ref

    ctypedef enum CSortOrder" arrow::compute::SortOrder":
        CSortOrder_Ascending \
            "arrow::compute::SortOrder::Ascending"
        CSortOrder_Descending \
            "arrow::compute::SortOrder::Descending"

    ctypedef enum CNullPlacement" arrow::compute::NullPlacement":
        CNullPlacement_AtStart \
            "arrow::compute::NullPlacement::AtStart"
        CNullPlacement_AtEnd \
            "arrow::compute::NullPlacement::AtEnd"

    cdef cppclass CPartitionNthOptions \
            "arrow::compute::PartitionNthOptions"(CFunctionOptions):
        CPartitionNthOptions(int64_t pivot, CNullPlacement)
        int64_t pivot
        CNullPlacement null_placement

    cdef cppclass CCumulativeSumOptions \
            "arrow::compute::CumulativeSumOptions"(CFunctionOptions):
        CCumulativeSumOptions(shared_ptr[CScalar] start, c_bool skip_nulls)
        shared_ptr[CScalar] start
        c_bool skip_nulls

    cdef cppclass CArraySortOptions \
            "arrow::compute::ArraySortOptions"(CFunctionOptions):
        CArraySortOptions(CSortOrder, CNullPlacement)
        CSortOrder order
        CNullPlacement null_placement

    cdef cppclass CSortKey" arrow::compute::SortKey":
        CSortKey(c_string name, CSortOrder order)
        c_string name
        CSortOrder order

    cdef cppclass CSortOptions \
            "arrow::compute::SortOptions"(CFunctionOptions):
        CSortOptions(vector[CSortKey] sort_keys, CNullPlacement)
        vector[CSortKey] sort_keys
        CNullPlacement null_placement

    cdef cppclass CSelectKOptions \
            "arrow::compute::SelectKOptions"(CFunctionOptions):
        CSelectKOptions(int64_t k, vector[CSortKey] sort_keys)
        int64_t k
        vector[CSortKey] sort_keys

    cdef enum CQuantileInterp \
            "arrow::compute::QuantileOptions::Interpolation":
        CQuantileInterp_LINEAR "arrow::compute::QuantileOptions::LINEAR"
        CQuantileInterp_LOWER "arrow::compute::QuantileOptions::LOWER"
        CQuantileInterp_HIGHER "arrow::compute::QuantileOptions::HIGHER"
        CQuantileInterp_NEAREST "arrow::compute::QuantileOptions::NEAREST"
        CQuantileInterp_MIDPOINT "arrow::compute::QuantileOptions::MIDPOINT"

    cdef cppclass CQuantileOptions \
            "arrow::compute::QuantileOptions"(CFunctionOptions):
        CQuantileOptions(vector[double] q, CQuantileInterp interpolation,
                         c_bool skip_nulls, uint32_t min_count)
        vector[double] q
        CQuantileInterp interpolation
        c_bool skip_nulls
        uint32_t min_count

    cdef cppclass CTDigestOptions \
            "arrow::compute::TDigestOptions"(CFunctionOptions):
        CTDigestOptions(vector[double] q,
                        uint32_t delta, uint32_t buffer_size,
                        c_bool skip_nulls, uint32_t min_count)
        vector[double] q
        uint32_t delta
        uint32_t buffer_size
        c_bool skip_nulls
        uint32_t min_count

    cdef enum CUtf8NormalizeForm \
            "arrow::compute::Utf8NormalizeOptions::Form":
        CUtf8NormalizeForm_NFC "arrow::compute::Utf8NormalizeOptions::NFC"
        CUtf8NormalizeForm_NFKC "arrow::compute::Utf8NormalizeOptions::NFKC"
        CUtf8NormalizeForm_NFD "arrow::compute::Utf8NormalizeOptions::NFD"
        CUtf8NormalizeForm_NFKD "arrow::compute::Utf8NormalizeOptions::NFKD"

    cdef cppclass CUtf8NormalizeOptions \
            "arrow::compute::Utf8NormalizeOptions"(CFunctionOptions):
        CUtf8NormalizeOptions(CUtf8NormalizeForm form)
        CUtf8NormalizeForm form

    cdef cppclass CSetLookupOptions \
            "arrow::compute::SetLookupOptions"(CFunctionOptions):
        CSetLookupOptions(CDatum value_set, c_bool skip_nulls)
        CDatum value_set
        c_bool skip_nulls

    cdef cppclass CRandomOptions \
            "arrow::compute::RandomOptions"(CFunctionOptions):
        CRandomOptions(CRandomOptions)

        @staticmethod
        CRandomOptions FromSystemRandom()

        @staticmethod
        CRandomOptions FromSeed(uint64_t seed)

    cdef enum CRankOptionsTiebreaker \
            "arrow::compute::RankOptions::Tiebreaker":
        CRankOptionsTiebreaker_Min "arrow::compute::RankOptions::Min"
        CRankOptionsTiebreaker_Max "arrow::compute::RankOptions::Max"
        CRankOptionsTiebreaker_First "arrow::compute::RankOptions::First"
        CRankOptionsTiebreaker_Dense "arrow::compute::RankOptions::Dense"

    cdef cppclass CRankOptions \
            "arrow::compute::RankOptions"(CFunctionOptions):
        CRankOptions(vector[CSortKey] sort_keys, CNullPlacement,
                     CRankOptionsTiebreaker tiebreaker)
        vector[CSortKey] sort_keys
        CNullPlacement null_placement
        CRankOptionsTiebreaker tiebreaker

    cdef enum DatumType" arrow::Datum::type":
        DatumType_NONE" arrow::Datum::NONE"
        DatumType_SCALAR" arrow::Datum::SCALAR"
        DatumType_ARRAY" arrow::Datum::ARRAY"
        DatumType_CHUNKED_ARRAY" arrow::Datum::CHUNKED_ARRAY"
        DatumType_RECORD_BATCH" arrow::Datum::RECORD_BATCH"
        DatumType_TABLE" arrow::Datum::TABLE"
        DatumType_COLLECTION" arrow::Datum::COLLECTION"

    cdef cppclass CDatum" arrow::Datum":
        CDatum()
        CDatum(const shared_ptr[CArray]& value)
        CDatum(const shared_ptr[CChunkedArray]& value)
        CDatum(const shared_ptr[CScalar]& value)
        CDatum(const shared_ptr[CRecordBatch]& value)
        CDatum(const shared_ptr[CTable]& value)

        DatumType kind() const
        c_string ToString() const

        const shared_ptr[CArrayData]& array() const
        const shared_ptr[CChunkedArray]& chunked_array() const
        const shared_ptr[CRecordBatch]& record_batch() const
        const shared_ptr[CTable]& table() const
        const shared_ptr[CScalar]& scalar() const

    cdef c_string ToString(DatumType kind)

cdef extern from * namespace "arrow::compute":
    # inlined from compute/function_internal.h to avoid exposing
    # implementation details
    """
    #include "arrow/compute/function.h"
    namespace arrow {
    namespace compute {
    namespace internal {
    Result<std::unique_ptr<FunctionOptions>> DeserializeFunctionOptions(
        const Buffer& buffer);
    } //  namespace internal
    } //  namespace compute
    } //  namespace arrow
    """
    CResult[unique_ptr[CFunctionOptions]] DeserializeFunctionOptions \
        " arrow::compute::internal::DeserializeFunctionOptions"(
            const CBuffer& buffer)


cdef extern from "arrow/compute/exec/aggregate.h" namespace \
        "arrow::compute::internal" nogil:
    cdef cppclass CAggregate "arrow::compute::Aggregate":
        c_string function
        shared_ptr[CFunctionOptions] options

    CResult[CDatum] GroupBy(const vector[CDatum]& arguments,
                            const vector[CDatum]& keys,
                            const vector[CAggregate]& aggregates)


cdef extern from * namespace "arrow::compute":
    # inlined from expression_internal.h to avoid
    # proliferation of #include <unordered_map>
    """
    #include <unordered_map>

    #include "arrow/type.h"
    #include "arrow/datum.h"

    namespace arrow {
    namespace compute {
    struct KnownFieldValues {
      std::unordered_map<FieldRef, Datum, FieldRef::Hash> map;
    };
    } //  namespace compute
    } //  namespace arrow
    """
    cdef struct CKnownFieldValues "arrow::compute::KnownFieldValues":
        unordered_map[CFieldRef, CDatum, CFieldRefHash] map

cdef extern from "arrow/compute/exec/expression.h" \
        namespace "arrow::compute" nogil:

    cdef cppclass CExpression "arrow::compute::Expression":
        c_bool Equals(const CExpression& other) const
        c_string ToString() const
        CResult[CExpression] Bind(const CSchema&)
        const CFieldRef* field_ref() const

    cdef CExpression CMakeScalarExpression \
        "arrow::compute::literal"(shared_ptr[CScalar] value)

    cdef CExpression CMakeFieldExpression \
        "arrow::compute::field_ref"(CFieldRef)

    cdef CExpression CMakeFieldExpressionByIndex \
        "arrow::compute::field_ref"(int idx)

    cdef CExpression CMakeCallExpression \
        "arrow::compute::call"(c_string function,
                               vector[CExpression] arguments,
                               shared_ptr[CFunctionOptions] options)

    cdef CResult[shared_ptr[CBuffer]] CSerializeExpression \
        "arrow::compute::Serialize"(const CExpression&)

    cdef CResult[CExpression] CDeserializeExpression \
        "arrow::compute::Deserialize"(shared_ptr[CBuffer])

    cdef CResult[CKnownFieldValues] \
        CExtractKnownFieldValues "arrow::compute::ExtractKnownFieldValues"(
            const CExpression& partition_expression)


cdef extern from "arrow/compute/exec/options.h" namespace "arrow::compute" nogil:
    cdef enum CJoinType "arrow::compute::JoinType":
        CJoinType_LEFT_SEMI "arrow::compute::JoinType::LEFT_SEMI"
        CJoinType_RIGHT_SEMI "arrow::compute::JoinType::RIGHT_SEMI"
        CJoinType_LEFT_ANTI "arrow::compute::JoinType::LEFT_ANTI"
        CJoinType_RIGHT_ANTI "arrow::compute::JoinType::RIGHT_ANTI"
        CJoinType_INNER "arrow::compute::JoinType::INNER"
        CJoinType_LEFT_OUTER "arrow::compute::JoinType::LEFT_OUTER"
        CJoinType_RIGHT_OUTER "arrow::compute::JoinType::RIGHT_OUTER"
        CJoinType_FULL_OUTER "arrow::compute::JoinType::FULL_OUTER"

    cdef cppclass CAsyncExecBatchGenerator "arrow::compute::AsyncExecBatchGenerator":
        pass

    cdef cppclass CExecNodeOptions "arrow::compute::ExecNodeOptions":
        pass

    cdef cppclass CSourceNodeOptions "arrow::compute::SourceNodeOptions"(CExecNodeOptions):
        pass

    cdef cppclass CTableSourceNodeOptions "arrow::compute::TableSourceNodeOptions"(CExecNodeOptions):
        CTableSourceNodeOptions(shared_ptr[CTable] table, int64_t max_batch_size)

    cdef cppclass CSinkNodeOptions "arrow::compute::SinkNodeOptions"(CExecNodeOptions):
        pass

    cdef cppclass CFilterNodeOptions "arrow::compute::FilterNodeOptions"(CExecNodeOptions):
        CFilterNodeOptions(CExpression)

    cdef cppclass CProjectNodeOptions "arrow::compute::ProjectNodeOptions"(CExecNodeOptions):
        CProjectNodeOptions(vector[CExpression] expressions)
        CProjectNodeOptions(vector[CExpression] expressions,
                            vector[c_string] names)

    cdef cppclass COrderBySinkNodeOptions "arrow::compute::OrderBySinkNodeOptions"(CExecNodeOptions):
        COrderBySinkNodeOptions(vector[CSortOptions] options,
                                CAsyncExecBatchGenerator generator)

    cdef cppclass CHashJoinNodeOptions "arrow::compute::HashJoinNodeOptions"(CExecNodeOptions):
        CHashJoinNodeOptions(CJoinType, vector[CFieldRef] in_left_keys,
                             vector[CFieldRef] in_right_keys)
        CHashJoinNodeOptions(CJoinType, vector[CFieldRef] in_left_keys,
                             vector[CFieldRef] in_right_keys,
                             CExpression filter,
                             c_string output_suffix_for_left,
                             c_string output_suffix_for_right)
        CHashJoinNodeOptions(CJoinType join_type,
                             vector[CFieldRef] left_keys,
                             vector[CFieldRef] right_keys,
                             vector[CFieldRef] left_output,
                             vector[CFieldRef] right_output,
                             CExpression filter,
                             c_string output_suffix_for_left,
                             c_string output_suffix_for_right)


cdef extern from "arrow/compute/exec/exec_plan.h" namespace "arrow::compute" nogil:
    cdef cppclass CDeclaration "arrow::compute::Declaration":
        cppclass Input:
            Input(CExecNode*)
            Input(CDeclaration)

        c_string label
        vector[Input] inputs

        CDeclaration()
        CDeclaration(c_string factory_name, CExecNodeOptions options)
        CDeclaration(c_string factory_name, vector[Input] inputs, shared_ptr[CExecNodeOptions] options)

        @staticmethod
        CDeclaration Sequence(vector[CDeclaration] decls)

        CResult[CExecNode*] AddToPlan(CExecPlan* plan) const

    cdef cppclass CExecPlan "arrow::compute::ExecPlan":
        @staticmethod
        CResult[shared_ptr[CExecPlan]] Make(CExecContext* exec_context)

        CStatus StartProducing()
        CStatus Validate()
        CStatus StopProducing()

        CFuture_Void finished()

        vector[CExecNode*] sinks() const
        vector[CExecNode*] sources() const

    cdef cppclass CExecNode "arrow::compute::ExecNode":
        const vector[CExecNode*]& inputs() const
        const shared_ptr[CSchema]& output_schema() const

    cdef cppclass CExecBatch "arrow::compute::ExecBatch":
        vector[CDatum] values
        int64_t length

    shared_ptr[CRecordBatchReader] MakeGeneratorReader(
        shared_ptr[CSchema] schema,
        CAsyncExecBatchGenerator gen,
        CMemoryPool* memory_pool
    )
    CResult[CExecNode*] MakeExecNode(c_string factory_name, CExecPlan* plan,
                                     vector[CExecNode*] inputs,
                                     const CExecNodeOptions& options)


cdef extern from "arrow/extension_type.h" namespace "arrow":
    cdef cppclass CExtensionTypeRegistry" arrow::ExtensionTypeRegistry":
        @staticmethod
        shared_ptr[CExtensionTypeRegistry] GetGlobalRegistry()

    cdef cppclass CExtensionType" arrow::ExtensionType"(CDataType):
        c_string extension_name()
        shared_ptr[CDataType] storage_type()

        @staticmethod
        shared_ptr[CArray] WrapArray(shared_ptr[CDataType] ext_type,
                                     shared_ptr[CArray] storage)

        @staticmethod
        shared_ptr[CChunkedArray] WrapArray(shared_ptr[CDataType] ext_type,
                                            shared_ptr[CChunkedArray] storage)

    cdef cppclass CExtensionArray" arrow::ExtensionArray"(CArray):
        CExtensionArray(shared_ptr[CDataType], shared_ptr[CArray] storage)

        shared_ptr[CArray] storage()


cdef extern from "arrow/util/compression.h" namespace "arrow" nogil:
    cdef enum CCompressionType" arrow::Compression::type":
        CCompressionType_UNCOMPRESSED" arrow::Compression::UNCOMPRESSED"
        CCompressionType_SNAPPY" arrow::Compression::SNAPPY"
        CCompressionType_GZIP" arrow::Compression::GZIP"
        CCompressionType_BROTLI" arrow::Compression::BROTLI"
        CCompressionType_ZSTD" arrow::Compression::ZSTD"
        CCompressionType_LZ4" arrow::Compression::LZ4"
        CCompressionType_LZ4_FRAME" arrow::Compression::LZ4_FRAME"
        CCompressionType_BZ2" arrow::Compression::BZ2"

    cdef cppclass CCodec" arrow::util::Codec":
        @staticmethod
        CResult[unique_ptr[CCodec]] Create(CCompressionType codec)

        @staticmethod
        CResult[unique_ptr[CCodec]] CreateWithLevel" Create"(
            CCompressionType codec,
            int compression_level)

        @staticmethod
        c_bool SupportsCompressionLevel(CCompressionType codec)

        @staticmethod
        CResult[int] MinimumCompressionLevel(CCompressionType codec)

        @staticmethod
        CResult[int] MaximumCompressionLevel(CCompressionType codec)

        @staticmethod
        CResult[int] DefaultCompressionLevel(CCompressionType codec)

        @staticmethod
        c_bool IsAvailable(CCompressionType codec)

        CResult[int64_t] Decompress(int64_t input_len, const uint8_t* input,
                                    int64_t output_len,
                                    uint8_t* output_buffer)
        CResult[int64_t] Compress(int64_t input_len, const uint8_t* input,
                                  int64_t output_buffer_len,
                                  uint8_t* output_buffer)
        c_string name() const
        int compression_level() const
        int64_t MaxCompressedLen(int64_t input_len, const uint8_t* input)


cdef extern from "arrow/util/io_util.h" namespace "arrow::internal" nogil:
    int ErrnoFromStatus(CStatus status)
    int WinErrorFromStatus(CStatus status)
    int SignalFromStatus(CStatus status)

    CStatus SendSignal(int signum)
    CStatus SendSignalToThread(int signum, uint64_t thread_id)


cdef extern from "arrow/util/iterator.h" namespace "arrow" nogil:
    cdef cppclass CIterator" arrow::Iterator"[T]:
        CResult[T] Next()
        CStatus Visit[Visitor](Visitor&& visitor)
        cppclass RangeIterator:
            CResult[T] operator*()
            RangeIterator& operator++()
            c_bool operator!=(RangeIterator) const
        RangeIterator begin()
        RangeIterator end()
    CIterator[T] MakeVectorIterator[T](vector[T] v)

cdef extern from "arrow/util/thread_pool.h" namespace "arrow" nogil:
    int GetCpuThreadPoolCapacity()
    CStatus SetCpuThreadPoolCapacity(int threads)

cdef extern from "arrow/array/concatenate.h" namespace "arrow" nogil:
    CResult[shared_ptr[CArray]] Concatenate(
        const vector[shared_ptr[CArray]]& arrays,
        CMemoryPool* pool)

cdef extern from "arrow/c/abi.h":
    cdef struct ArrowSchema:
        pass

    cdef struct ArrowArray:
        pass

    cdef struct ArrowArrayStream:
        pass

cdef extern from "arrow/c/bridge.h" namespace "arrow" nogil:
    CStatus ExportType(CDataType&, ArrowSchema* out)
    CResult[shared_ptr[CDataType]] ImportType(ArrowSchema*)

    CStatus ExportField(CField&, ArrowSchema* out)
    CResult[shared_ptr[CField]] ImportField(ArrowSchema*)

    CStatus ExportSchema(CSchema&, ArrowSchema* out)
    CResult[shared_ptr[CSchema]] ImportSchema(ArrowSchema*)

    CStatus ExportArray(CArray&, ArrowArray* out)
    CStatus ExportArray(CArray&, ArrowArray* out, ArrowSchema* out_schema)
    CResult[shared_ptr[CArray]] ImportArray(ArrowArray*,
                                            shared_ptr[CDataType])
    CResult[shared_ptr[CArray]] ImportArray(ArrowArray*, ArrowSchema*)

    CStatus ExportRecordBatch(CRecordBatch&, ArrowArray* out)
    CStatus ExportRecordBatch(CRecordBatch&, ArrowArray* out,
                              ArrowSchema* out_schema)
    CResult[shared_ptr[CRecordBatch]] ImportRecordBatch(ArrowArray*,
                                                        shared_ptr[CSchema])
    CResult[shared_ptr[CRecordBatch]] ImportRecordBatch(ArrowArray*,
                                                        ArrowSchema*)

    CStatus ExportRecordBatchReader(shared_ptr[CRecordBatchReader],
                                    ArrowArrayStream*)
    CResult[shared_ptr[CRecordBatchReader]] ImportRecordBatchReader(
        ArrowArrayStream*)


cdef extern from "arrow/util/byte_size.h" namespace "arrow::util" nogil:
    CResult[int64_t] ReferencedBufferSize(const CArray& array_data)
    CResult[int64_t] ReferencedBufferSize(const CRecordBatch& record_batch)
    CResult[int64_t] ReferencedBufferSize(const CChunkedArray& chunked_array)
    CResult[int64_t] ReferencedBufferSize(const CTable& table)
    int64_t TotalBufferSize(const CArray& array)
    int64_t TotalBufferSize(const CChunkedArray& array)
    int64_t TotalBufferSize(const CRecordBatch& record_batch)
    int64_t TotalBufferSize(const CTable& table)

ctypedef PyObject* CallbackUdf(object user_function, const CScalarUdfContext& context, object inputs)

cdef extern from "arrow/python/udf.h" namespace "arrow::py":
    cdef cppclass CScalarUdfContext" arrow::py::ScalarUdfContext":
        CMemoryPool *pool
        int64_t batch_length

    cdef cppclass CScalarUdfOptions" arrow::py::ScalarUdfOptions":
        c_string func_name
        CArity arity
        CFunctionDoc func_doc
        vector[shared_ptr[CDataType]] input_types
        shared_ptr[CDataType] output_type

    CStatus RegisterScalarFunction(PyObject* function,
                                   function[CallbackUdf] wrapper, const CScalarUdfOptions& options)