@@ -2664,7 +2664,7 @@ pub enum BinaryFunc {
26642664 TrimLeading ( TrimLeading ) ,
26652665 TrimTrailing ( TrimTrailing ) ,
26662666 EncodedBytesCharLength ( EncodedBytesCharLength ) ,
2667- ListLengthMax { max_layer : usize } ,
2667+ ListLengthMax ( ListLengthMax ) ,
26682668 ArrayContains ( ArrayContains ) ,
26692669 ArrayContainsArray { rev : bool } ,
26702670 ArrayLength ( ArrayLength ) ,
@@ -2937,7 +2937,7 @@ impl BinaryFunc {
29372937 BinaryFunc :: EncodedBytesCharLength ( s) => {
29382938 return s. eval ( datums, temp_storage, a_expr, b_expr) ;
29392939 }
2940- // BinaryFunc::ListLengthMax { max_layer } (s) => return s.eval(datums, temp_storage, a_expr, b_expr),
2940+ BinaryFunc :: ListLengthMax ( s) => return s. eval ( datums, temp_storage, a_expr, b_expr) ,
29412941 BinaryFunc :: ArrayLength ( s) => return s. eval ( datums, temp_storage, a_expr, b_expr) ,
29422942 BinaryFunc :: ArrayContains ( s) => return s. eval ( datums, temp_storage, a_expr, b_expr) ,
29432943 // BinaryFunc::ArrayContainsArray { rev: false } => Ok(array_contains_array(a, b)),
@@ -3037,7 +3037,6 @@ impl BinaryFunc {
30373037 BinaryFunc :: JsonbGetStringStringify => Ok ( jsonb_get_string ( a, b, temp_storage, true ) ) ,
30383038 BinaryFunc :: JsonbGetPath => Ok ( jsonb_get_path ( a, b, temp_storage, false ) ) ,
30393039 BinaryFunc :: JsonbGetPathStringify => Ok ( jsonb_get_path ( a, b, temp_storage, true ) ) ,
3040- BinaryFunc :: ListLengthMax { max_layer } => list_length_max ( a, b, * max_layer) ,
30413040 BinaryFunc :: ArrayContainsArray { rev : false } => Ok ( array_contains_array ( a, b) ) ,
30423041 BinaryFunc :: ArrayContainsArray { rev : true } => Ok ( array_contains_array ( b, a) ) ,
30433042 BinaryFunc :: ListContainsList { rev : false } => Ok ( list_contains_list ( a, b) ) ,
@@ -3258,7 +3257,7 @@ impl BinaryFunc {
32583257 ArrayLower ( s) => s. output_type ( input1_type, input2_type) ,
32593258 ArrayUpper ( s) => s. output_type ( input1_type, input2_type) ,
32603259
3261- ListLengthMax { .. } => SqlScalarType :: Int32 . nullable ( true ) ,
3260+ ListLengthMax ( s ) => s . output_type ( input1_type , input2_type ) ,
32623261
32633262 ArrayArrayConcat ( s) => s. output_type ( input1_type, input2_type) ,
32643263 ArrayRemove ( s) => s. output_type ( input1_type, input2_type) ,
@@ -3432,7 +3431,7 @@ impl BinaryFunc {
34323431 BinaryFunc :: LikeEscape ( s) => s. propagates_nulls ( ) ,
34333432 BinaryFunc :: ListContainsList { .. } => true ,
34343433 BinaryFunc :: ListElementConcat ( s) => s. propagates_nulls ( ) ,
3435- BinaryFunc :: ListLengthMax { .. } => true ,
3434+ BinaryFunc :: ListLengthMax ( s ) => s . propagates_nulls ( ) ,
34363435 BinaryFunc :: ListListConcat ( s) => s. propagates_nulls ( ) ,
34373436 BinaryFunc :: ListRemove ( s) => s. propagates_nulls ( ) ,
34383437 BinaryFunc :: LogNumeric ( s) => s. propagates_nulls ( ) ,
@@ -3724,7 +3723,7 @@ impl BinaryFunc {
37243723 JsonbGetPathStringify => true ,
37253724 JsonbGetString => true ,
37263725 JsonbGetStringStringify => true ,
3727- ListLengthMax { .. } => true ,
3726+ ListLengthMax ( s ) => s . introduces_nulls ( ) ,
37283727 MapGetValue ( s) => s. introduces_nulls ( ) ,
37293728 }
37303729 }
@@ -3901,7 +3900,7 @@ impl BinaryFunc {
39013900 GetByte ( s) => s. is_infix_op ( ) ,
39023901 Left ( s) => s. is_infix_op ( ) ,
39033902 LikeEscape ( s) => s. is_infix_op ( ) ,
3904- ListLengthMax { .. } => false ,
3903+ ListLengthMax ( s ) => s . is_infix_op ( ) ,
39053904 ListRemove ( s) => s. is_infix_op ( ) ,
39063905 LogNumeric ( s) => s. is_infix_op ( ) ,
39073906 MzAclItemContainsPrivilege ( s) => s. is_infix_op ( ) ,
@@ -4045,7 +4044,7 @@ impl BinaryFunc {
40454044 BinaryFunc :: LikeEscape ( s) => s. negate ( ) ,
40464045 BinaryFunc :: ListContainsList { .. } => None ,
40474046 BinaryFunc :: ListElementConcat ( s) => s. negate ( ) ,
4048- BinaryFunc :: ListLengthMax { .. } => None ,
4047+ BinaryFunc :: ListLengthMax ( s ) => s . negate ( ) ,
40494048 BinaryFunc :: ListListConcat ( s) => s. negate ( ) ,
40504049 BinaryFunc :: ListRemove ( s) => s. negate ( ) ,
40514050 BinaryFunc :: LogNumeric ( s) => s. negate ( ) ,
@@ -4310,7 +4309,7 @@ impl BinaryFunc {
43104309 BinaryFunc :: RepeatString => true ,
43114310 BinaryFunc :: Normalize => true ,
43124311 BinaryFunc :: EncodedBytesCharLength ( s) => s. could_error ( ) ,
4313- BinaryFunc :: ListLengthMax { .. } => true ,
4312+ BinaryFunc :: ListLengthMax ( s ) => s . could_error ( ) ,
43144313 BinaryFunc :: ArrayLength ( s) => s. could_error ( ) ,
43154314 BinaryFunc :: ArrayRemove ( s) => s. could_error ( ) ,
43164315 BinaryFunc :: ArrayUpper ( s) => s. could_error ( ) ,
@@ -4510,7 +4509,7 @@ impl BinaryFunc {
45104509 BinaryFunc :: TrimLeading ( s) => s. is_monotone ( ) ,
45114510 BinaryFunc :: TrimTrailing ( s) => s. is_monotone ( ) ,
45124511 BinaryFunc :: EncodedBytesCharLength ( s) => s. is_monotone ( ) ,
4513- BinaryFunc :: ListLengthMax { .. } => ( false , false ) ,
4512+ BinaryFunc :: ListLengthMax ( s ) => s . is_monotone ( ) ,
45144513 BinaryFunc :: ArrayContains ( s) => s. is_monotone ( ) ,
45154514 BinaryFunc :: ArrayContainsArray { .. } => ( false , false ) ,
45164515 BinaryFunc :: ArrayLength ( s) => s. is_monotone ( ) ,
@@ -4718,7 +4717,7 @@ impl fmt::Display for BinaryFunc {
47184717 BinaryFunc :: TrimLeading ( s) => s. fmt ( f) ,
47194718 BinaryFunc :: TrimTrailing ( s) => s. fmt ( f) ,
47204719 BinaryFunc :: EncodedBytesCharLength ( s) => s. fmt ( f) ,
4721- BinaryFunc :: ListLengthMax { .. } => f . write_str ( "list_length_max" ) ,
4720+ BinaryFunc :: ListLengthMax ( s ) => s . fmt ( f ) ,
47224721 BinaryFunc :: ArrayContains ( s) => s. fmt ( f) ,
47234722 BinaryFunc :: ArrayContainsArray { rev } => f. write_str ( if * rev { "<@" } else { "@>" } ) ,
47244723 BinaryFunc :: ArrayLength ( s) => s. fmt ( f) ,
@@ -5226,48 +5225,6 @@ fn array_upper<'a>(a: Array<'a>, i: i64) -> Result<Option<i32>, EvalError> {
52265225 . transpose ( )
52275226}
52285227
5229- // TODO(benesch): remove potentially dangerous usage of `as`.
5230- #[ allow( clippy:: as_conversions) ]
5231- fn list_length_max < ' a > (
5232- a : Datum < ' a > ,
5233- b : Datum < ' a > ,
5234- max_layer : usize ,
5235- ) -> Result < Datum < ' a > , EvalError > {
5236- fn max_len_on_layer < ' a > ( d : Datum < ' a > , on_layer : i64 ) -> Option < usize > {
5237- match d {
5238- Datum :: List ( i) => {
5239- let mut i = i. iter ( ) ;
5240- if on_layer > 1 {
5241- let mut max_len = None ;
5242- while let Some ( Datum :: List ( i) ) = i. next ( ) {
5243- max_len =
5244- std:: cmp:: max ( max_len_on_layer ( Datum :: List ( i) , on_layer - 1 ) , max_len) ;
5245- }
5246- max_len
5247- } else {
5248- Some ( i. count ( ) )
5249- }
5250- }
5251- Datum :: Null => None ,
5252- _ => unreachable ! ( ) ,
5253- }
5254- }
5255-
5256- let b = b. unwrap_int64 ( ) ;
5257-
5258- if b as usize > max_layer || b < 1 {
5259- Err ( EvalError :: InvalidLayer { max_layer, val : b } )
5260- } else {
5261- match max_len_on_layer ( a, b) {
5262- Some ( l) => match l. try_into ( ) {
5263- Ok ( c) => Ok ( Datum :: Int32 ( c) ) ,
5264- Err ( _) => Err ( EvalError :: Int32OutOfRange ( l. to_string ( ) . into ( ) ) ) ,
5265- } ,
5266- None => Ok ( Datum :: Null ) ,
5267- }
5268- }
5269- }
5270-
52715228#[ sqlfunc(
52725229 is_infix_op = true ,
52735230 sqlname = "array_contains" ,
0 commit comments