summaryrefslogtreecommitdiffstats
path: root/contrib/libs/apache/arrow_next/cpp/src/arrow/compute/api_scalar.cc
blob: 1eb28e529f18c319fb1308d18e80f6f6555c1633 (plain) (blame)
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
// 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.

#include "contrib/libs/apache/arrow_next/cpp/src/arrow/compute/api_scalar.h"

#include <memory>
#include <optional>
#include <sstream>
#include <string>

#include "contrib/libs/apache/arrow_next/cpp/src/arrow/array/array_base.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/compute/exec.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/compute/function_internal.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/compute/registry.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/status.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/type.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/util/checked_cast.h"
#include "contrib/libs/apache/arrow_next/cpp/src/arrow/util/logging.h"

namespace arrow20 {

namespace internal {
template <>
struct EnumTraits<compute::JoinOptions::NullHandlingBehavior>
    : BasicEnumTraits<compute::JoinOptions::NullHandlingBehavior,
                      compute::JoinOptions::NullHandlingBehavior::EMIT_NULL,
                      compute::JoinOptions::NullHandlingBehavior::SKIP,
                      compute::JoinOptions::NullHandlingBehavior::REPLACE> {
  static std::string name() { return "JoinOptions::NullHandlingBehavior"; }
  static std::string value_name(compute::JoinOptions::NullHandlingBehavior value) {
    switch (value) {
      case compute::JoinOptions::NullHandlingBehavior::EMIT_NULL:
        return "EMIT_NULL";
      case compute::JoinOptions::NullHandlingBehavior::SKIP:
        return "SKIP";
      case compute::JoinOptions::NullHandlingBehavior::REPLACE:
        return "REPLACE";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<TimeUnit::type>
    : BasicEnumTraits<TimeUnit::type, TimeUnit::type::SECOND, TimeUnit::type::MILLI,
                      TimeUnit::type::MICRO, TimeUnit::type::NANO> {
  static std::string name() { return "TimeUnit::type"; }
  static std::string value_name(TimeUnit::type value) {
    switch (value) {
      case TimeUnit::type::SECOND:
        return "SECOND";
      case TimeUnit::type::MILLI:
        return "MILLI";
      case TimeUnit::type::MICRO:
        return "MICRO";
      case TimeUnit::type::NANO:
        return "NANO";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::CompareOperator>
    : BasicEnumTraits<
          compute::CompareOperator, compute::CompareOperator::EQUAL,
          compute::CompareOperator::NOT_EQUAL, compute::CompareOperator::GREATER,
          compute::CompareOperator::GREATER_EQUAL, compute::CompareOperator::LESS,
          compute::CompareOperator::LESS_EQUAL> {
  static std::string name() { return "compute::CompareOperator"; }
  static std::string value_name(compute::CompareOperator value) {
    switch (value) {
      case compute::CompareOperator::EQUAL:
        return "EQUAL";
      case compute::CompareOperator::NOT_EQUAL:
        return "NOT_EQUAL";
      case compute::CompareOperator::GREATER:
        return "GREATER";
      case compute::CompareOperator::GREATER_EQUAL:
        return "GREATER_EQUAL";
      case compute::CompareOperator::LESS:
        return "LESS";
      case compute::CompareOperator::LESS_EQUAL:
        return "LESS_EQUAL";
    }
    return "<INVALID>";
  }
};
template <>
struct EnumTraits<compute::AssumeTimezoneOptions::Ambiguous>
    : BasicEnumTraits<compute::AssumeTimezoneOptions::Ambiguous,
                      compute::AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_RAISE,
                      compute::AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_EARLIEST,
                      compute::AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_LATEST> {
  static std::string name() { return "AssumeTimezoneOptions::Ambiguous"; }
  static std::string value_name(compute::AssumeTimezoneOptions::Ambiguous value) {
    switch (value) {
      case compute::AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_RAISE:
        return "AMBIGUOUS_RAISE";
      case compute::AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_EARLIEST:
        return "AMBIGUOUS_EARLIEST";
      case compute::AssumeTimezoneOptions::Ambiguous::AMBIGUOUS_LATEST:
        return "AMBIGUOUS_LATEST";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::AssumeTimezoneOptions::Nonexistent>
    : BasicEnumTraits<compute::AssumeTimezoneOptions::Nonexistent,
                      compute::AssumeTimezoneOptions::Nonexistent::NONEXISTENT_RAISE,
                      compute::AssumeTimezoneOptions::Nonexistent::NONEXISTENT_EARLIEST,
                      compute::AssumeTimezoneOptions::Nonexistent::NONEXISTENT_LATEST> {
  static std::string name() { return "AssumeTimezoneOptions::Nonexistent"; }
  static std::string value_name(compute::AssumeTimezoneOptions::Nonexistent value) {
    switch (value) {
      case compute::AssumeTimezoneOptions::Nonexistent::NONEXISTENT_RAISE:
        return "NONEXISTENT_RAISE";
      case compute::AssumeTimezoneOptions::Nonexistent::NONEXISTENT_EARLIEST:
        return "NONEXISTENT_EARLIEST";
      case compute::AssumeTimezoneOptions::Nonexistent::NONEXISTENT_LATEST:
        return "NONEXISTENT_LATEST";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::RoundMode>
    : BasicEnumTraits<compute::RoundMode, compute::RoundMode::DOWN,
                      compute::RoundMode::UP, compute::RoundMode::TOWARDS_ZERO,
                      compute::RoundMode::TOWARDS_INFINITY, compute::RoundMode::HALF_DOWN,
                      compute::RoundMode::HALF_UP, compute::RoundMode::HALF_TOWARDS_ZERO,
                      compute::RoundMode::HALF_TOWARDS_INFINITY,
                      compute::RoundMode::HALF_TO_EVEN, compute::RoundMode::HALF_TO_ODD> {
  static std::string name() { return "compute::RoundMode"; }
  static std::string value_name(compute::RoundMode value) {
    switch (value) {
      case compute::RoundMode::DOWN:
        return "DOWN";
      case compute::RoundMode::UP:
        return "UP";
      case compute::RoundMode::TOWARDS_ZERO:
        return "TOWARDS_ZERO";
      case compute::RoundMode::TOWARDS_INFINITY:
        return "TOWARDS_INFINITY";
      case compute::RoundMode::HALF_DOWN:
        return "HALF_DOWN";
      case compute::RoundMode::HALF_UP:
        return "HALF_UP";
      case compute::RoundMode::HALF_TOWARDS_ZERO:
        return "HALF_TOWARDS_ZERO";
      case compute::RoundMode::HALF_TOWARDS_INFINITY:
        return "HALF_TOWARDS_INFINITY";
      case compute::RoundMode::HALF_TO_EVEN:
        return "HALF_TO_EVEN";
      case compute::RoundMode::HALF_TO_ODD:
        return "HALF_TO_ODD";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::CalendarUnit>
    : BasicEnumTraits<compute::CalendarUnit, compute::CalendarUnit::NANOSECOND,
                      compute::CalendarUnit::MICROSECOND,
                      compute::CalendarUnit::MILLISECOND, compute::CalendarUnit::SECOND,
                      compute::CalendarUnit::MINUTE, compute::CalendarUnit::HOUR,
                      compute::CalendarUnit::DAY, compute::CalendarUnit::WEEK,
                      compute::CalendarUnit::MONTH, compute::CalendarUnit::QUARTER,
                      compute::CalendarUnit::YEAR> {
  static std::string name() { return "compute::CalendarUnit"; }
  static std::string value_name(compute::CalendarUnit value) {
    switch (value) {
      case compute::CalendarUnit::NANOSECOND:
        return "NANOSECOND";
      case compute::CalendarUnit::MICROSECOND:
        return "MICROSECOND";
      case compute::CalendarUnit::MILLISECOND:
        return "MILLISECOND";
      case compute::CalendarUnit::SECOND:
        return "SECOND";
      case compute::CalendarUnit::MINUTE:
        return "MINUTE";
      case compute::CalendarUnit::HOUR:
        return "HOUR";
      case compute::CalendarUnit::DAY:
        return "DAY";
      case compute::CalendarUnit::WEEK:
        return "WEEK";
      case compute::CalendarUnit::MONTH:
        return "MONTH";
      case compute::CalendarUnit::QUARTER:
        return "QUARTER";
      case compute::CalendarUnit::YEAR:
        return "YEAR";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::Utf8NormalizeOptions::Form>
    : BasicEnumTraits<compute::Utf8NormalizeOptions::Form,
                      compute::Utf8NormalizeOptions::Form::NFC,
                      compute::Utf8NormalizeOptions::Form::NFKC,
                      compute::Utf8NormalizeOptions::Form::NFD,
                      compute::Utf8NormalizeOptions::Form::NFKD> {
  static std::string name() { return "Utf8NormalizeOptions::Form"; }
  static std::string value_name(compute::Utf8NormalizeOptions::Form value) {
    switch (value) {
      case compute::Utf8NormalizeOptions::Form::NFC:
        return "NFC";
      case compute::Utf8NormalizeOptions::Form::NFKC:
        return "NFKC";
      case compute::Utf8NormalizeOptions::Form::NFD:
        return "NFD";
      case compute::Utf8NormalizeOptions::Form::NFKD:
        return "NFKD";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::RandomOptions::Initializer>
    : BasicEnumTraits<compute::RandomOptions::Initializer,
                      compute::RandomOptions::Initializer::SystemRandom,
                      compute::RandomOptions::Initializer::Seed> {
  static std::string name() { return "RandomOptions::Initializer"; }
  static std::string value_name(compute::RandomOptions::Initializer value) {
    switch (value) {
      case compute::RandomOptions::Initializer::SystemRandom:
        return "SystemRandom";
      case compute::RandomOptions::Initializer::Seed:
        return "Seed";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::MapLookupOptions::Occurrence>
    : BasicEnumTraits<compute::MapLookupOptions::Occurrence,
                      compute::MapLookupOptions::Occurrence::FIRST,
                      compute::MapLookupOptions::Occurrence::LAST,
                      compute::MapLookupOptions::Occurrence::ALL> {
  static std::string name() { return "MapLookupOptions::Occurrence"; }
  static std::string value_name(compute::MapLookupOptions::Occurrence value) {
    switch (value) {
      case compute::MapLookupOptions::Occurrence::FIRST:
        return "FIRST";
      case compute::MapLookupOptions::Occurrence::LAST:
        return "LAST";
      case compute::MapLookupOptions::Occurrence::ALL:
        return "ALL";
    }
    return "<INVALID>";
  }
};

template <>
struct EnumTraits<compute::SetLookupOptions::NullMatchingBehavior>
    : BasicEnumTraits<compute::SetLookupOptions::NullMatchingBehavior,
                      compute::SetLookupOptions::NullMatchingBehavior::MATCH,
                      compute::SetLookupOptions::NullMatchingBehavior::SKIP,
                      compute::SetLookupOptions::NullMatchingBehavior::EMIT_NULL,
                      compute::SetLookupOptions::NullMatchingBehavior::INCONCLUSIVE> {
  static std::string name() { return "SetLookupOptions::NullMatchingBehavior"; }
  static std::string value_name(compute::SetLookupOptions::NullMatchingBehavior value) {
    switch (value) {
      case compute::SetLookupOptions::NullMatchingBehavior::MATCH:
        return "MATCH";
      case compute::SetLookupOptions::NullMatchingBehavior::SKIP:
        return "SKIP";
      case compute::SetLookupOptions::NullMatchingBehavior::EMIT_NULL:
        return "EMIT_NULL";
      case compute::SetLookupOptions::NullMatchingBehavior::INCONCLUSIVE:
        return "INCONCLUSIVE";
    }
    return "<INVALID>";
  }
};

}  // namespace internal

namespace compute {

// ----------------------------------------------------------------------
// Function options

using ::arrow20::internal::checked_cast;

namespace internal {
namespace {
using ::arrow20::internal::CoercedDataMember;
using ::arrow20::internal::DataMember;
static auto kArithmeticOptionsType = GetFunctionOptionsType<ArithmeticOptions>(
    DataMember("check_overflow", &ArithmeticOptions::check_overflow));
static auto kAssumeTimezoneOptionsType = GetFunctionOptionsType<AssumeTimezoneOptions>(
    DataMember("timezone", &AssumeTimezoneOptions::timezone),
    DataMember("ambiguous", &AssumeTimezoneOptions::ambiguous),
    DataMember("nonexistent", &AssumeTimezoneOptions::nonexistent));
static auto kDayOfWeekOptionsType = GetFunctionOptionsType<DayOfWeekOptions>(
    DataMember("count_from_zero", &DayOfWeekOptions::count_from_zero),
    DataMember("week_start", &DayOfWeekOptions::week_start));
static auto kElementWiseAggregateOptionsType =
    GetFunctionOptionsType<ElementWiseAggregateOptions>(
        DataMember("skip_nulls", &ElementWiseAggregateOptions::skip_nulls));
static auto kExtractRegexOptionsType = GetFunctionOptionsType<ExtractRegexOptions>(
    DataMember("pattern", &ExtractRegexOptions::pattern));
static auto kExtractRegexSpanOptionsType =
    GetFunctionOptionsType<ExtractRegexSpanOptions>(
        DataMember("pattern", &ExtractRegexSpanOptions::pattern));
static auto kJoinOptionsType = GetFunctionOptionsType<JoinOptions>(
    DataMember("null_handling", &JoinOptions::null_handling),
    DataMember("null_replacement", &JoinOptions::null_replacement));
static auto kMakeStructOptionsType = GetFunctionOptionsType<MakeStructOptions>(
    DataMember("field_names", &MakeStructOptions::field_names),
    DataMember("field_nullability", &MakeStructOptions::field_nullability),
    DataMember("field_metadata", &MakeStructOptions::field_metadata));
static auto kMapLookupOptionsType = GetFunctionOptionsType<MapLookupOptions>(
    DataMember("occurrence", &MapLookupOptions::occurrence),
    DataMember("query_key", &MapLookupOptions::query_key));
static auto kMatchSubstringOptionsType = GetFunctionOptionsType<MatchSubstringOptions>(
    DataMember("pattern", &MatchSubstringOptions::pattern),
    DataMember("ignore_case", &MatchSubstringOptions::ignore_case));
static auto kNullOptionsType = GetFunctionOptionsType<NullOptions>(
    DataMember("nan_is_null", &NullOptions::nan_is_null));
static auto kPadOptionsType = GetFunctionOptionsType<PadOptions>(
    DataMember("width", &PadOptions::width), DataMember("padding", &PadOptions::padding),
    DataMember("lean_left_on_odd_padding", &PadOptions::lean_left_on_odd_padding));
static auto kReplaceSliceOptionsType = GetFunctionOptionsType<ReplaceSliceOptions>(
    DataMember("start", &ReplaceSliceOptions::start),
    DataMember("stop", &ReplaceSliceOptions::stop),
    DataMember("replacement", &ReplaceSliceOptions::replacement));
static auto kReplaceSubstringOptionsType =
    GetFunctionOptionsType<ReplaceSubstringOptions>(
        DataMember("pattern", &ReplaceSubstringOptions::pattern),
        DataMember("replacement", &ReplaceSubstringOptions::replacement),
        DataMember("max_replacements", &ReplaceSubstringOptions::max_replacements));
static auto kRoundOptionsType = GetFunctionOptionsType<RoundOptions>(
    DataMember("ndigits", &RoundOptions::ndigits),
    DataMember("round_mode", &RoundOptions::round_mode));
static auto kRoundBinaryOptionsType = GetFunctionOptionsType<RoundBinaryOptions>(
    DataMember("round_mode", &RoundBinaryOptions::round_mode));
static auto kRoundTemporalOptionsType = GetFunctionOptionsType<RoundTemporalOptions>(
    DataMember("multiple", &RoundTemporalOptions::multiple),
    DataMember("unit", &RoundTemporalOptions::unit),
    DataMember("week_starts_monday", &RoundTemporalOptions::week_starts_monday),
    DataMember("ceil_is_strictly_greater",
               &RoundTemporalOptions::ceil_is_strictly_greater),
    DataMember("calendar_based_origin", &RoundTemporalOptions::calendar_based_origin));
static auto kRoundToMultipleOptionsType = GetFunctionOptionsType<RoundToMultipleOptions>(
    DataMember("multiple", &RoundToMultipleOptions::multiple),
    DataMember("round_mode", &RoundToMultipleOptions::round_mode));
static auto kSetLookupOptionsType = GetFunctionOptionsType<SetLookupOptions>(
    DataMember("value_set", &SetLookupOptions::value_set),
    CoercedDataMember("null_matching_behavior", &SetLookupOptions::null_matching_behavior,
                      &SetLookupOptions::GetNullMatchingBehavior));
static auto kSliceOptionsType = GetFunctionOptionsType<SliceOptions>(
    DataMember("start", &SliceOptions::start), DataMember("stop", &SliceOptions::stop),
    DataMember("step", &SliceOptions::step));
static auto kListSliceOptionsType = GetFunctionOptionsType<ListSliceOptions>(
    DataMember("start", &ListSliceOptions::start),
    DataMember("stop", &ListSliceOptions::stop),
    DataMember("step", &ListSliceOptions::step),
    DataMember("return_fixed_size_list", &ListSliceOptions::return_fixed_size_list));
static auto kSplitPatternOptionsType = GetFunctionOptionsType<SplitPatternOptions>(
    DataMember("pattern", &SplitPatternOptions::pattern),
    DataMember("max_splits", &SplitPatternOptions::max_splits),
    DataMember("reverse", &SplitPatternOptions::reverse));
static auto kSplitOptionsType = GetFunctionOptionsType<SplitOptions>(
    DataMember("max_splits", &SplitOptions::max_splits),
    DataMember("reverse", &SplitOptions::reverse));
static auto kStrftimeOptionsType = GetFunctionOptionsType<StrftimeOptions>(
    DataMember("format", &StrftimeOptions::format));
static auto kStrptimeOptionsType = GetFunctionOptionsType<StrptimeOptions>(
    DataMember("format", &StrptimeOptions::format),
    DataMember("unit", &StrptimeOptions::unit),
    DataMember("error_is_null", &StrptimeOptions::error_is_null));
static auto kStructFieldOptionsType = GetFunctionOptionsType<StructFieldOptions>(
    DataMember("field_ref", &StructFieldOptions::field_ref));
static auto kTrimOptionsType = GetFunctionOptionsType<TrimOptions>(
    DataMember("characters", &TrimOptions::characters));
static auto kUtf8NormalizeOptionsType = GetFunctionOptionsType<Utf8NormalizeOptions>(
    DataMember("form", &Utf8NormalizeOptions::form));
static auto kWeekOptionsType = GetFunctionOptionsType<WeekOptions>(
    DataMember("week_starts_monday", &WeekOptions::week_starts_monday),
    DataMember("count_from_zero", &WeekOptions::count_from_zero),
    DataMember("first_week_is_fully_in_year", &WeekOptions::first_week_is_fully_in_year));
static auto kRandomOptionsType = GetFunctionOptionsType<RandomOptions>(
    DataMember("initializer", &RandomOptions::initializer),
    DataMember("seed", &RandomOptions::seed));

}  // namespace
}  // namespace internal

ArithmeticOptions::ArithmeticOptions(bool check_overflow)
    : FunctionOptions(internal::kArithmeticOptionsType), check_overflow(check_overflow) {}
constexpr char ArithmeticOptions::kTypeName[];

AssumeTimezoneOptions::AssumeTimezoneOptions(std::string timezone, Ambiguous ambiguous,
                                             Nonexistent nonexistent)
    : FunctionOptions(internal::kAssumeTimezoneOptionsType),
      timezone(std::move(timezone)),
      ambiguous(ambiguous),
      nonexistent(nonexistent) {}
AssumeTimezoneOptions::AssumeTimezoneOptions() : AssumeTimezoneOptions("UTC") {}
constexpr char AssumeTimezoneOptions::kTypeName[];

DayOfWeekOptions::DayOfWeekOptions(bool count_from_zero, uint32_t week_start)
    : FunctionOptions(internal::kDayOfWeekOptionsType),
      count_from_zero(count_from_zero),
      week_start(week_start) {}
constexpr char DayOfWeekOptions::kTypeName[];

ElementWiseAggregateOptions::ElementWiseAggregateOptions(bool skip_nulls)
    : FunctionOptions(internal::kElementWiseAggregateOptionsType),
      skip_nulls(skip_nulls) {}
constexpr char ElementWiseAggregateOptions::kTypeName[];

ExtractRegexOptions::ExtractRegexOptions(std::string pattern)
    : FunctionOptions(internal::kExtractRegexOptionsType), pattern(std::move(pattern)) {}
ExtractRegexOptions::ExtractRegexOptions() : ExtractRegexOptions("") {}
constexpr char ExtractRegexOptions::kTypeName[];

ExtractRegexSpanOptions::ExtractRegexSpanOptions(std::string pattern)
    : FunctionOptions(internal::kExtractRegexSpanOptionsType),
      pattern(std::move(pattern)) {}
ExtractRegexSpanOptions::ExtractRegexSpanOptions() : ExtractRegexSpanOptions("") {}
constexpr char ExtractRegexSpanOptions::kTypeName[];

JoinOptions::JoinOptions(NullHandlingBehavior null_handling, std::string null_replacement)
    : FunctionOptions(internal::kJoinOptionsType),
      null_handling(null_handling),
      null_replacement(std::move(null_replacement)) {}
constexpr char JoinOptions::kTypeName[];

MakeStructOptions::MakeStructOptions(
    std::vector<std::string> n, std::vector<bool> r,
    std::vector<std::shared_ptr<const KeyValueMetadata>> m)
    : FunctionOptions(internal::kMakeStructOptionsType),
      field_names(std::move(n)),
      field_nullability(std::move(r)),
      field_metadata(std::move(m)) {}

MakeStructOptions::MakeStructOptions(std::vector<std::string> n)
    : FunctionOptions(internal::kMakeStructOptionsType),
      field_names(std::move(n)),
      field_nullability(field_names.size(), true),
      field_metadata(field_names.size(), NULLPTR) {}

MakeStructOptions::MakeStructOptions() : MakeStructOptions(std::vector<std::string>()) {}
constexpr char MakeStructOptions::kTypeName[];

MapLookupOptions::MapLookupOptions(std::shared_ptr<Scalar> query_key,
                                   Occurrence occurrence)
    : FunctionOptions(internal::kMapLookupOptionsType),
      query_key(std::move(query_key)),
      occurrence(occurrence) {}
MapLookupOptions::MapLookupOptions()
    : MapLookupOptions(std::make_shared<NullScalar>(), Occurrence::FIRST) {}
constexpr char MapLookupOptions::kTypeName[];

MatchSubstringOptions::MatchSubstringOptions(std::string pattern, bool ignore_case)
    : FunctionOptions(internal::kMatchSubstringOptionsType),
      pattern(std::move(pattern)),
      ignore_case(ignore_case) {}
MatchSubstringOptions::MatchSubstringOptions() : MatchSubstringOptions("", false) {}
constexpr char MatchSubstringOptions::kTypeName[];

NullOptions::NullOptions(bool nan_is_null)
    : FunctionOptions(internal::kNullOptionsType), nan_is_null(nan_is_null) {}
constexpr char NullOptions::kTypeName[];

PadOptions::PadOptions(int64_t width, std::string padding, bool lean_left_on_odd_padding)
    : FunctionOptions(internal::kPadOptionsType),
      width(width),
      padding(std::move(padding)),
      lean_left_on_odd_padding(lean_left_on_odd_padding) {}
PadOptions::PadOptions() : PadOptions(0, " ") {}
constexpr char PadOptions::kTypeName[];

ReplaceSliceOptions::ReplaceSliceOptions(int64_t start, int64_t stop,
                                         std::string replacement)
    : FunctionOptions(internal::kReplaceSliceOptionsType),
      start(start),
      stop(stop),
      replacement(std::move(replacement)) {}
ReplaceSliceOptions::ReplaceSliceOptions() : ReplaceSliceOptions(0, 0, "") {}
constexpr char ReplaceSliceOptions::kTypeName[];

ReplaceSubstringOptions::ReplaceSubstringOptions(std::string pattern,
                                                 std::string replacement,
                                                 int64_t max_replacements)
    : FunctionOptions(internal::kReplaceSubstringOptionsType),
      pattern(std::move(pattern)),
      replacement(std::move(replacement)),
      max_replacements(max_replacements) {}
ReplaceSubstringOptions::ReplaceSubstringOptions()
    : ReplaceSubstringOptions("", "", -1) {}
constexpr char ReplaceSubstringOptions::kTypeName[];

RoundOptions::RoundOptions(int64_t ndigits, RoundMode round_mode)
    : FunctionOptions(internal::kRoundOptionsType),
      ndigits(ndigits),
      round_mode(round_mode) {
  static_assert(RoundMode::HALF_DOWN > RoundMode::DOWN &&
                    RoundMode::HALF_DOWN > RoundMode::UP &&
                    RoundMode::HALF_DOWN > RoundMode::TOWARDS_ZERO &&
                    RoundMode::HALF_DOWN > RoundMode::TOWARDS_INFINITY &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_UP &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TOWARDS_ZERO &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TOWARDS_INFINITY &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TO_EVEN &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TO_ODD,
                "Invalid order of round modes. Modes prefixed with HALF need to be "
                "enumerated last with HALF_DOWN being the first among them.");
}
constexpr char RoundOptions::kTypeName[];

RoundBinaryOptions::RoundBinaryOptions(RoundMode round_mode)
    : FunctionOptions(internal::kRoundBinaryOptionsType), round_mode(round_mode) {
  static_assert(RoundMode::HALF_DOWN > RoundMode::DOWN &&
                    RoundMode::HALF_DOWN > RoundMode::UP &&
                    RoundMode::HALF_DOWN > RoundMode::TOWARDS_ZERO &&
                    RoundMode::HALF_DOWN > RoundMode::TOWARDS_INFINITY &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_UP &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TOWARDS_ZERO &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TOWARDS_INFINITY &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TO_EVEN &&
                    RoundMode::HALF_DOWN < RoundMode::HALF_TO_ODD,
                "Invalid order of round modes. Modes prefixed with HALF need to be "
                "enumerated last with HALF_DOWN being the first among them.");
}
constexpr char RoundBinaryOptions::kTypeName[];

RoundTemporalOptions::RoundTemporalOptions(int multiple, CalendarUnit unit,
                                           bool week_starts_monday,
                                           bool ceil_is_strictly_greater,
                                           bool calendar_based_origin)
    : FunctionOptions(internal::kRoundTemporalOptionsType),
      multiple(std::move(multiple)),
      unit(unit),
      week_starts_monday(week_starts_monday),
      ceil_is_strictly_greater(ceil_is_strictly_greater),
      calendar_based_origin(calendar_based_origin) {}
constexpr char RoundTemporalOptions::kTypeName[];

RoundToMultipleOptions::RoundToMultipleOptions(double multiple, RoundMode round_mode)
    : RoundToMultipleOptions(std::make_shared<DoubleScalar>(multiple), round_mode) {}
RoundToMultipleOptions::RoundToMultipleOptions(std::shared_ptr<Scalar> multiple,
                                               RoundMode round_mode)
    : FunctionOptions(internal::kRoundToMultipleOptionsType),
      multiple(std::move(multiple)),
      round_mode(round_mode) {}
constexpr char RoundToMultipleOptions::kTypeName[];

SetLookupOptions::SetLookupOptions(Datum value_set, bool skip_nulls)
    : FunctionOptions(internal::kSetLookupOptionsType),
      value_set(std::move(value_set)),
      skip_nulls(skip_nulls) {
  if (skip_nulls) {
    this->null_matching_behavior = SetLookupOptions::SKIP;
  } else {
    this->null_matching_behavior = SetLookupOptions::MATCH;
  }
}
SetLookupOptions::SetLookupOptions(
    Datum value_set, SetLookupOptions::NullMatchingBehavior null_matching_behavior)
    : FunctionOptions(internal::kSetLookupOptionsType),
      value_set(std::move(value_set)),
      null_matching_behavior(std::move(null_matching_behavior)) {}
SetLookupOptions::SetLookupOptions()
    : SetLookupOptions({}, SetLookupOptions::NullMatchingBehavior::MATCH) {}
SetLookupOptions::NullMatchingBehavior SetLookupOptions::GetNullMatchingBehavior() const {
  if (!this->skip_nulls.has_value()) {
    return this->null_matching_behavior;
  } else if (this->skip_nulls.value()) {
    return SetLookupOptions::SKIP;
  } else {
    return SetLookupOptions::MATCH;
  }
}
constexpr char SetLookupOptions::kTypeName[];

SliceOptions::SliceOptions(int64_t start, int64_t stop, int64_t step)
    : FunctionOptions(internal::kSliceOptionsType),
      start(start),
      stop(stop),
      step(step) {}
SliceOptions::SliceOptions() : SliceOptions(0, 0, 1) {}
constexpr char SliceOptions::kTypeName[];

ListSliceOptions::ListSliceOptions(int64_t start, std::optional<int64_t> stop,
                                   int64_t step,
                                   std::optional<bool> return_fixed_size_list)
    : FunctionOptions(internal::kListSliceOptionsType),
      start(start),
      stop(stop),
      step(step),
      return_fixed_size_list(return_fixed_size_list) {}
ListSliceOptions::ListSliceOptions() : ListSliceOptions(0) {}
constexpr char ListSliceOptions::kTypeName[];

SplitOptions::SplitOptions(int64_t max_splits, bool reverse)
    : FunctionOptions(internal::kSplitOptionsType),
      max_splits(max_splits),
      reverse(reverse) {}
constexpr char SplitOptions::kTypeName[];

SplitPatternOptions::SplitPatternOptions(std::string pattern, int64_t max_splits,
                                         bool reverse)
    : FunctionOptions(internal::kSplitPatternOptionsType),
      pattern(std::move(pattern)),
      max_splits(max_splits),
      reverse(reverse) {}
SplitPatternOptions::SplitPatternOptions() : SplitPatternOptions("", -1, false) {}
constexpr char SplitPatternOptions::kTypeName[];

StrftimeOptions::StrftimeOptions(std::string format, std::string locale)
    : FunctionOptions(internal::kStrftimeOptionsType),
      format(std::move(format)),
      locale(std::move(locale)) {}
StrftimeOptions::StrftimeOptions() : StrftimeOptions(kDefaultFormat) {}
constexpr char StrftimeOptions::kTypeName[];
constexpr const char* StrftimeOptions::kDefaultFormat;

StrptimeOptions::StrptimeOptions(std::string format, TimeUnit::type unit,
                                 bool error_is_null)
    : FunctionOptions(internal::kStrptimeOptionsType),
      format(std::move(format)),
      unit(unit),
      error_is_null(error_is_null) {}
StrptimeOptions::StrptimeOptions() : StrptimeOptions("", TimeUnit::MICRO, false) {}
constexpr char StrptimeOptions::kTypeName[];

StructFieldOptions::StructFieldOptions(std::vector<int> indices)
    : FunctionOptions(internal::kStructFieldOptionsType), field_ref(std::move(indices)) {}
StructFieldOptions::StructFieldOptions(std::initializer_list<int> indices)
    : FunctionOptions(internal::kStructFieldOptionsType), field_ref(std::move(indices)) {}
StructFieldOptions::StructFieldOptions(FieldRef ref)
    : FunctionOptions(internal::kStructFieldOptionsType), field_ref(std::move(ref)) {}
StructFieldOptions::StructFieldOptions()
    : FunctionOptions(internal::kStructFieldOptionsType) {}
constexpr char StructFieldOptions::kTypeName[];

TrimOptions::TrimOptions(std::string characters)
    : FunctionOptions(internal::kTrimOptionsType), characters(std::move(characters)) {}
TrimOptions::TrimOptions() : TrimOptions("") {}
constexpr char TrimOptions::kTypeName[];

Utf8NormalizeOptions::Utf8NormalizeOptions(Form form)
    : FunctionOptions(internal::kUtf8NormalizeOptionsType), form(form) {}
constexpr char Utf8NormalizeOptions::kTypeName[];

WeekOptions::WeekOptions(bool week_starts_monday, bool count_from_zero,
                         bool first_week_is_fully_in_year)
    : FunctionOptions(internal::kWeekOptionsType),
      week_starts_monday(week_starts_monday),
      count_from_zero(count_from_zero),
      first_week_is_fully_in_year(first_week_is_fully_in_year) {}
constexpr char WeekOptions::kTypeName[];

RandomOptions::RandomOptions(Initializer initializer, uint64_t seed)
    : FunctionOptions(internal::kRandomOptionsType),
      initializer(initializer),
      seed(seed) {}
RandomOptions::RandomOptions() : RandomOptions(SystemRandom, 0) {}
constexpr char RandomOptions::kTypeName[];

namespace internal {
void RegisterScalarOptions(FunctionRegistry* registry) {
  DCHECK_OK(registry->AddFunctionOptionsType(kArithmeticOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kAssumeTimezoneOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kDayOfWeekOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kElementWiseAggregateOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kExtractRegexOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kExtractRegexSpanOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kJoinOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kListSliceOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kMakeStructOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kMapLookupOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kMatchSubstringOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kNullOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kPadOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kReplaceSliceOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kReplaceSubstringOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kRoundBinaryOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kRoundOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kRoundTemporalOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kRoundToMultipleOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kSetLookupOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kSliceOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kSplitOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kSplitPatternOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kStrftimeOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kStrptimeOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kStructFieldOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kTrimOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kUtf8NormalizeOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kWeekOptionsType));
  DCHECK_OK(registry->AddFunctionOptionsType(kRandomOptionsType));
}
}  // namespace internal

#define SCALAR_EAGER_UNARY(NAME, REGISTRY_NAME)              \
  Result<Datum> NAME(const Datum& value, ExecContext* ctx) { \
    return CallFunction(REGISTRY_NAME, {value}, ctx);        \
  }

#define SCALAR_EAGER_BINARY(NAME, REGISTRY_NAME)                                \
  Result<Datum> NAME(const Datum& left, const Datum& right, ExecContext* ctx) { \
    return CallFunction(REGISTRY_NAME, {left, right}, ctx);                     \
  }

// ----------------------------------------------------------------------
// Arithmetic

#define SCALAR_ARITHMETIC_UNARY(NAME, REGISTRY_NAME, REGISTRY_CHECKED_NAME)            \
  Result<Datum> NAME(const Datum& arg, ArithmeticOptions options, ExecContext* ctx) {  \
    auto func_name = (options.check_overflow) ? REGISTRY_CHECKED_NAME : REGISTRY_NAME; \
    return CallFunction(func_name, {arg}, ctx);                                        \
  }

SCALAR_ARITHMETIC_UNARY(AbsoluteValue, "abs", "abs_checked")
SCALAR_ARITHMETIC_UNARY(Acos, "acos", "acos_checked")
SCALAR_ARITHMETIC_UNARY(Acosh, "acosh", "acosh_checked")
SCALAR_ARITHMETIC_UNARY(Asin, "asin", "asin_checked")
SCALAR_ARITHMETIC_UNARY(Atanh, "atanh", "atanh_checked")
SCALAR_ARITHMETIC_UNARY(Cos, "cos", "cos_checked")
SCALAR_ARITHMETIC_UNARY(Ln, "ln", "ln_checked")
SCALAR_ARITHMETIC_UNARY(Log10, "log10", "log10_checked")
SCALAR_ARITHMETIC_UNARY(Log1p, "log1p", "log1p_checked")
SCALAR_ARITHMETIC_UNARY(Log2, "log2", "log2_checked")
SCALAR_ARITHMETIC_UNARY(Negate, "negate", "negate_checked")
SCALAR_ARITHMETIC_UNARY(Sin, "sin", "sin_checked")
SCALAR_ARITHMETIC_UNARY(Sqrt, "sqrt", "sqrt_checked")
SCALAR_ARITHMETIC_UNARY(Tan, "tan", "tan_checked")
SCALAR_EAGER_UNARY(Asinh, "asinh")
SCALAR_EAGER_UNARY(Atan, "atan")
SCALAR_EAGER_UNARY(Cosh, "cosh")
SCALAR_EAGER_UNARY(Exp, "exp")
SCALAR_EAGER_UNARY(Expm1, "expm1")
SCALAR_EAGER_UNARY(Sign, "sign")
SCALAR_EAGER_UNARY(Sinh, "sinh")
SCALAR_EAGER_UNARY(Tanh, "tanh")

Result<Datum> Round(const Datum& arg, RoundOptions options, ExecContext* ctx) {
  return CallFunction("round", {arg}, &options, ctx);
}

Result<Datum> RoundBinary(const Datum& arg1, const Datum& arg2,
                          RoundBinaryOptions options, ExecContext* ctx) {
  return CallFunction("round_binary", {arg1, arg2}, &options, ctx);
}

Result<Datum> RoundToMultiple(const Datum& arg, RoundToMultipleOptions options,
                              ExecContext* ctx) {
  return CallFunction("round_to_multiple", {arg}, &options, ctx);
}

#define SCALAR_ARITHMETIC_BINARY(NAME, REGISTRY_NAME, REGISTRY_CHECKED_NAME)           \
  Result<Datum> NAME(const Datum& left, const Datum& right, ArithmeticOptions options, \
                     ExecContext* ctx) {                                               \
    auto func_name = (options.check_overflow) ? REGISTRY_CHECKED_NAME : REGISTRY_NAME; \
    return CallFunction(func_name, {left, right}, ctx);                                \
  }

SCALAR_ARITHMETIC_BINARY(Add, "add", "add_checked")
SCALAR_ARITHMETIC_BINARY(Divide, "divide", "divide_checked")
SCALAR_ARITHMETIC_BINARY(Logb, "logb", "logb_checked")
SCALAR_ARITHMETIC_BINARY(Multiply, "multiply", "multiply_checked")
SCALAR_ARITHMETIC_BINARY(Power, "power", "power_checked")
SCALAR_ARITHMETIC_BINARY(ShiftLeft, "shift_left", "shift_left_checked")
SCALAR_ARITHMETIC_BINARY(ShiftRight, "shift_right", "shift_right_checked")
SCALAR_ARITHMETIC_BINARY(Subtract, "subtract", "subtract_checked")
SCALAR_EAGER_BINARY(Atan2, "atan2")
SCALAR_EAGER_UNARY(Floor, "floor")
SCALAR_EAGER_UNARY(Ceil, "ceil")
SCALAR_EAGER_UNARY(Trunc, "trunc")

Result<Datum> MaxElementWise(const std::vector<Datum>& args,
                             ElementWiseAggregateOptions options, ExecContext* ctx) {
  return CallFunction("max_element_wise", args, &options, ctx);
}

Result<Datum> MinElementWise(const std::vector<Datum>& args,
                             ElementWiseAggregateOptions options, ExecContext* ctx) {
  return CallFunction("min_element_wise", args, &options, ctx);
}

// ----------------------------------------------------------------------
// Set-related operations

Result<Datum> IsIn(const Datum& values, const SetLookupOptions& options,
                   ExecContext* ctx) {
  return CallFunction("is_in", {values}, &options, ctx);
}

Result<Datum> IsIn(const Datum& values, const Datum& value_set, ExecContext* ctx) {
  return IsIn(values, SetLookupOptions{value_set}, ctx);
}

Result<Datum> IndexIn(const Datum& values, const SetLookupOptions& options,
                      ExecContext* ctx) {
  return CallFunction("index_in", {values}, &options, ctx);
}

Result<Datum> IndexIn(const Datum& values, const Datum& value_set, ExecContext* ctx) {
  return IndexIn(values, SetLookupOptions{value_set}, ctx);
}

// ----------------------------------------------------------------------
// Boolean functions

SCALAR_EAGER_BINARY(And, "and")
SCALAR_EAGER_BINARY(AndNot, "and_not")
SCALAR_EAGER_BINARY(KleeneAnd, "and_kleene")
SCALAR_EAGER_BINARY(KleeneAndNot, "and_not_kleene")
SCALAR_EAGER_BINARY(KleeneOr, "or_kleene")
SCALAR_EAGER_BINARY(Or, "or")
SCALAR_EAGER_BINARY(Xor, "xor")
SCALAR_EAGER_UNARY(Invert, "invert")

// ----------------------------------------------------------------------
// Validity functions

SCALAR_EAGER_UNARY(IsNan, "is_nan")
SCALAR_EAGER_UNARY(IsValid, "is_valid")

Result<Datum> CaseWhen(const Datum& cond, const std::vector<Datum>& cases,
                       ExecContext* ctx) {
  std::vector<Datum> args = {cond};
  args.reserve(cases.size() + 1);
  args.insert(args.end(), cases.begin(), cases.end());
  return CallFunction("case_when", args, ctx);
}

Result<Datum> IfElse(const Datum& cond, const Datum& if_true, const Datum& if_false,
                     ExecContext* ctx) {
  return CallFunction("if_else", {cond, if_true, if_false}, ctx);
}

Result<Datum> IsNull(const Datum& arg, NullOptions options, ExecContext* ctx) {
  return CallFunction("is_null", {arg}, &options, ctx);
}

// ----------------------------------------------------------------------
// Temporal functions

SCALAR_EAGER_UNARY(Day, "day")
SCALAR_EAGER_UNARY(DayOfYear, "day_of_year")
SCALAR_EAGER_UNARY(Hour, "hour")
SCALAR_EAGER_UNARY(YearMonthDay, "year_month_day")
SCALAR_EAGER_UNARY(IsDaylightSavings, "is_dst")
SCALAR_EAGER_UNARY(LocalTimestamp, "local_timestamp")
SCALAR_EAGER_UNARY(IsLeapYear, "is_leap_year")
SCALAR_EAGER_UNARY(ISOCalendar, "iso_calendar")
SCALAR_EAGER_UNARY(ISOWeek, "iso_week")
SCALAR_EAGER_UNARY(ISOYear, "iso_year")
SCALAR_EAGER_UNARY(Microsecond, "microsecond")
SCALAR_EAGER_UNARY(Millisecond, "millisecond")
SCALAR_EAGER_UNARY(Minute, "minute")
SCALAR_EAGER_UNARY(Month, "month")
SCALAR_EAGER_UNARY(Nanosecond, "nanosecond")
SCALAR_EAGER_UNARY(Quarter, "quarter")
SCALAR_EAGER_UNARY(Second, "second")
SCALAR_EAGER_UNARY(Subsecond, "subsecond")
SCALAR_EAGER_UNARY(USWeek, "us_week")
SCALAR_EAGER_UNARY(USYear, "us_year")
SCALAR_EAGER_UNARY(Year, "year")

Result<Datum> AssumeTimezone(const Datum& arg, AssumeTimezoneOptions options,
                             ExecContext* ctx) {
  return CallFunction("assume_timezone", {arg}, &options, ctx);
}

Result<Datum> DayOfWeek(const Datum& arg, DayOfWeekOptions options, ExecContext* ctx) {
  return CallFunction("day_of_week", {arg}, &options, ctx);
}

Result<Datum> CeilTemporal(const Datum& arg, RoundTemporalOptions options,
                           ExecContext* ctx) {
  return CallFunction("ceil_temporal", {arg}, &options, ctx);
}

Result<Datum> FloorTemporal(const Datum& arg, RoundTemporalOptions options,
                            ExecContext* ctx) {
  return CallFunction("floor_temporal", {arg}, &options, ctx);
}

Result<Datum> RoundTemporal(const Datum& arg, RoundTemporalOptions options,
                            ExecContext* ctx) {
  return CallFunction("round_temporal", {arg}, &options, ctx);
}

Result<Datum> Strftime(const Datum& arg, StrftimeOptions options, ExecContext* ctx) {
  return CallFunction("strftime", {arg}, &options, ctx);
}

Result<Datum> Strptime(const Datum& arg, StrptimeOptions options, ExecContext* ctx) {
  return CallFunction("strptime", {arg}, &options, ctx);
}

Result<Datum> Week(const Datum& arg, WeekOptions options, ExecContext* ctx) {
  return CallFunction("week", {arg}, &options, ctx);
}

SCALAR_EAGER_BINARY(YearsBetween, "years_between")
SCALAR_EAGER_BINARY(QuartersBetween, "quarters_between")
SCALAR_EAGER_BINARY(MonthsBetween, "month_interval_between")
SCALAR_EAGER_BINARY(WeeksBetween, "weeks_between")
SCALAR_EAGER_BINARY(MonthDayNanoBetween, "month_day_nano_interval_between")
SCALAR_EAGER_BINARY(DayTimeBetween, "day_time_interval_between")
SCALAR_EAGER_BINARY(DaysBetween, "days_between")
SCALAR_EAGER_BINARY(HoursBetween, "hours_between")
SCALAR_EAGER_BINARY(MinutesBetween, "minutes_between")
SCALAR_EAGER_BINARY(SecondsBetween, "seconds_between")
SCALAR_EAGER_BINARY(MillisecondsBetween, "milliseconds_between")
SCALAR_EAGER_BINARY(MicrosecondsBetween, "microseconds_between")
SCALAR_EAGER_BINARY(NanosecondsBetween, "nanoseconds_between")

// ----------------------------------------------------------------------
// Structural transforms
Result<Datum> MapLookup(const Datum& arg, MapLookupOptions options, ExecContext* ctx) {
  return CallFunction("map_lookup", {arg}, &options, ctx);
}

// ----------------------------------------------------------------------

}  // namespace compute
}  // namespace arrow20