@@ -909,6 +909,13 @@ fn register_to_number_functions(registry: &mut FunctionRegistry) {
909
909
ToNumberImpl :: eval_date :: < ToYear , _ > ( val, ctx. func_ctx . tz )
910
910
} ) ,
911
911
) ;
912
+ registry. register_passthrough_nullable_1_arg :: < DateType , UInt8Type , _ , _ > (
913
+ "to_quarter" ,
914
+ |_, _| FunctionDomain :: Full ,
915
+ vectorize_1_arg :: < DateType , UInt8Type > ( |val, ctx| {
916
+ ToNumberImpl :: eval_date :: < ToQuarter , _ > ( val, ctx. func_ctx . tz )
917
+ } ) ,
918
+ ) ;
912
919
registry. register_passthrough_nullable_1_arg :: < DateType , UInt8Type , _ , _ > (
913
920
"to_month" ,
914
921
|_, _| FunctionDomain :: Full ,
@@ -973,6 +980,13 @@ fn register_to_number_functions(registry: &mut FunctionRegistry) {
973
980
ToNumberImpl :: eval_timestamp :: < ToYear , _ > ( val, ctx. func_ctx . tz )
974
981
} ) ,
975
982
) ;
983
+ registry. register_passthrough_nullable_1_arg :: < TimestampType , UInt8Type , _ , _ > (
984
+ "to_quarter" ,
985
+ |_, _| FunctionDomain :: Full ,
986
+ vectorize_1_arg :: < TimestampType , UInt8Type > ( |val, ctx| {
987
+ ToNumberImpl :: eval_timestamp :: < ToQuarter , _ > ( val, ctx. func_ctx . tz )
988
+ } ) ,
989
+ ) ;
976
990
registry. register_passthrough_nullable_1_arg :: < TimestampType , UInt8Type , _ , _ > (
977
991
"to_month" ,
978
992
|_, _| FunctionDomain :: Full ,
@@ -1027,23 +1041,31 @@ fn register_to_number_functions(registry: &mut FunctionRegistry) {
1027
1041
}
1028
1042
1029
1043
fn register_timestamp_add_sub ( registry : & mut FunctionRegistry ) {
1030
- registry. register_2_arg :: < DateType , Int64Type , DateType , _ , _ > (
1044
+ registry. register_passthrough_nullable_2_arg :: < DateType , Int64Type , DateType , _ , _ > (
1031
1045
"plus" ,
1032
1046
|_, lhs, rhs| {
1033
1047
( || {
1034
- let lm = lhs. max ;
1035
- let ln = lhs. min ;
1036
- let rm: i32 = num_traits :: cast :: cast ( rhs. max ) ? ;
1037
- let rn: i32 = num_traits :: cast :: cast ( rhs. min ) ? ;
1048
+ let lm: i64 = num_traits :: cast :: cast ( lhs. max ) ? ;
1049
+ let ln: i64 = num_traits :: cast :: cast ( lhs. min ) ? ;
1050
+ let rm = rhs. max ;
1051
+ let rn = rhs. min ;
1038
1052
1039
1053
Some ( FunctionDomain :: Domain ( SimpleDomain :: < i32 > {
1040
- min : ln . checked_add ( rn ) ?,
1041
- max : lm . checked_add ( rm ) ?,
1054
+ min : check_date ( ln + rn ) . ok ( ) ?,
1055
+ max : check_date ( lm + rm ) . ok ( ) ?,
1042
1056
} ) )
1043
1057
} ) ( )
1044
- . unwrap_or ( FunctionDomain :: Full )
1058
+ . unwrap_or ( FunctionDomain :: MayThrow )
1045
1059
} ,
1046
- |a, b, _| a + ( b as i32 ) ,
1060
+ vectorize_with_builder_2_arg :: < DateType , Int64Type , DateType > ( |a, b, output, ctx| {
1061
+ match check_date ( ( a as i64 ) + b) {
1062
+ Ok ( v) => output. push ( v) ,
1063
+ Err ( err) => {
1064
+ ctx. set_error ( output. len ( ) , err) ;
1065
+ output. push ( 0 ) ;
1066
+ }
1067
+ }
1068
+ } ) ,
1047
1069
) ;
1048
1070
1049
1071
registry. register_2_arg :: < DateType , DateType , Int32Type , _ , _ > (
@@ -1065,7 +1087,7 @@ fn register_timestamp_add_sub(registry: &mut FunctionRegistry) {
1065
1087
|a, b, _| a + b,
1066
1088
) ;
1067
1089
1068
- registry. register_2_arg :: < TimestampType , Int64Type , TimestampType , _ , _ > (
1090
+ registry. register_passthrough_nullable_2_arg :: < TimestampType , Int64Type , TimestampType , _ , _ > (
1069
1091
"plus" ,
1070
1092
|_, lhs, rhs| {
1071
1093
( || {
@@ -1074,13 +1096,21 @@ fn register_timestamp_add_sub(registry: &mut FunctionRegistry) {
1074
1096
let rm = rhs. max ;
1075
1097
let rn = rhs. min ;
1076
1098
Some ( FunctionDomain :: Domain ( SimpleDomain :: < i64 > {
1077
- min : ln . checked_add ( rn ) ?,
1078
- max : lm . checked_add ( rm ) ?,
1099
+ min : check_timestamp ( ln + rn ) . ok ( ) ?,
1100
+ max : check_timestamp ( lm + rm ) . ok ( ) ?,
1079
1101
} ) )
1080
1102
} ) ( )
1081
- . unwrap_or ( FunctionDomain :: Full )
1103
+ . unwrap_or ( FunctionDomain :: MayThrow )
1082
1104
} ,
1083
- |a, b, _| a + b,
1105
+ vectorize_with_builder_2_arg :: < TimestampType , Int64Type , TimestampType > (
1106
+ |a, b, output, ctx| match check_timestamp ( a + b) {
1107
+ Ok ( v) => output. push ( v) ,
1108
+ Err ( err) => {
1109
+ ctx. set_error ( output. len ( ) , err) ;
1110
+ output. push ( 0 ) ;
1111
+ }
1112
+ } ,
1113
+ ) ,
1084
1114
) ;
1085
1115
1086
1116
registry. register_2_arg :: < TimestampType , TimestampType , Int64Type , _ , _ > (
@@ -1101,23 +1131,31 @@ fn register_timestamp_add_sub(registry: &mut FunctionRegistry) {
1101
1131
|a, b, _| a + b,
1102
1132
) ;
1103
1133
1104
- registry. register_2_arg :: < DateType , Int64Type , DateType , _ , _ > (
1134
+ registry. register_passthrough_nullable_2_arg :: < DateType , Int64Type , DateType , _ , _ > (
1105
1135
"minus" ,
1106
1136
|_, lhs, rhs| {
1107
1137
( || {
1108
- let lm = lhs. max ;
1109
- let ln = lhs. min ;
1110
- let rm: i32 = num_traits :: cast :: cast ( rhs. max ) ? ;
1111
- let rn: i32 = num_traits :: cast :: cast ( rhs. min ) ? ;
1138
+ let lm: i64 = num_traits :: cast :: cast ( lhs. max ) ? ;
1139
+ let ln: i64 = num_traits :: cast :: cast ( lhs. min ) ? ;
1140
+ let rm = rhs. max ;
1141
+ let rn = rhs. min ;
1112
1142
1113
1143
Some ( FunctionDomain :: Domain ( SimpleDomain :: < i32 > {
1114
- min : ln . checked_sub ( rm ) ?,
1115
- max : lm . checked_sub ( rn ) ?,
1144
+ min : check_date ( ln - rn ) . ok ( ) ?,
1145
+ max : check_date ( lm - rm ) . ok ( ) ?,
1116
1146
} ) )
1117
1147
} ) ( )
1118
- . unwrap_or ( FunctionDomain :: Full )
1148
+ . unwrap_or ( FunctionDomain :: MayThrow )
1119
1149
} ,
1120
- |a, b, _| a - b as i32 ,
1150
+ vectorize_with_builder_2_arg :: < DateType , Int64Type , DateType > ( |a, b, output, ctx| {
1151
+ match check_date ( ( a as i64 ) - b) {
1152
+ Ok ( v) => output. push ( v) ,
1153
+ Err ( err) => {
1154
+ ctx. set_error ( output. len ( ) , err) ;
1155
+ output. push ( 0 ) ;
1156
+ }
1157
+ }
1158
+ } ) ,
1121
1159
) ;
1122
1160
1123
1161
registry. register_2_arg :: < DateType , DateType , Int32Type , _ , _ > (
@@ -1139,7 +1177,7 @@ fn register_timestamp_add_sub(registry: &mut FunctionRegistry) {
1139
1177
|a, b, _| a - b,
1140
1178
) ;
1141
1179
1142
- registry. register_2_arg :: < TimestampType , Int64Type , TimestampType , _ , _ > (
1180
+ registry. register_passthrough_nullable_2_arg :: < TimestampType , Int64Type , TimestampType , _ , _ > (
1143
1181
"minus" ,
1144
1182
|_, lhs, rhs| {
1145
1183
( || {
@@ -1149,13 +1187,21 @@ fn register_timestamp_add_sub(registry: &mut FunctionRegistry) {
1149
1187
let rn = rhs. min ;
1150
1188
1151
1189
Some ( FunctionDomain :: Domain ( SimpleDomain :: < i64 > {
1152
- min : ln . checked_sub ( rm ) ?,
1153
- max : lm . checked_sub ( rn ) ?,
1190
+ min : check_timestamp ( ln - rn ) . ok ( ) ?,
1191
+ max : check_timestamp ( lm - rm ) . ok ( ) ?,
1154
1192
} ) )
1155
1193
} ) ( )
1156
- . unwrap_or ( FunctionDomain :: Full )
1194
+ . unwrap_or ( FunctionDomain :: MayThrow )
1157
1195
} ,
1158
- |a, b, _| a - b,
1196
+ vectorize_with_builder_2_arg :: < TimestampType , Int64Type , TimestampType > (
1197
+ |a, b, output, ctx| match check_timestamp ( a - b) {
1198
+ Ok ( v) => output. push ( v) ,
1199
+ Err ( err) => {
1200
+ ctx. set_error ( output. len ( ) , err) ;
1201
+ output. push ( 0 ) ;
1202
+ }
1203
+ } ,
1204
+ ) ,
1159
1205
) ;
1160
1206
1161
1207
registry. register_2_arg :: < TimestampType , TimestampType , Int64Type , _ , _ > (
0 commit comments