@@ -24,7 +24,8 @@ use arrow::array::GenericStringArray;
2424use arrow:: array:: {
2525 ArrayRef , BooleanArray , Float32Array , Float64Array , Int16Array , Int32Array ,
2626 Int64Array , Int8Array , StringOffsetSizeTrait , UInt16Array , UInt32Array , UInt64Array ,
27- UInt8Array ,
27+ UInt8Array , Int64Decimal0Array , Int64Decimal1Array , Int64Decimal2Array , Int64Decimal3Array , Int64Decimal4Array ,
28+ Int64Decimal5Array , Int64Decimal10Array
2829} ;
2930use arrow:: { datatypes:: DataType , record_batch:: RecordBatch } ;
3031
@@ -43,6 +44,59 @@ pub struct InListExpr {
4344}
4445
4546macro_rules! make_contains {
47+ ( $ARRAY: expr, $LIST_VALUES: expr, $NEGATED: expr, Int64Decimal , $ARRAY_TYPE: ident, $SCALE: expr) => { {
48+ let array = $ARRAY. as_any( ) . downcast_ref:: <$ARRAY_TYPE>( ) . unwrap( ) ;
49+
50+ let mut contains_null = false ;
51+ let values = $LIST_VALUES
52+ . iter( )
53+ . flat_map( |expr| match expr {
54+ ColumnarValue :: Scalar ( s) => match s {
55+ ScalarValue :: Int64Decimal ( Some ( v) , $SCALE) => Some ( * v) ,
56+ ScalarValue :: Int64Decimal ( None , $SCALE) => {
57+ contains_null = true ;
58+ None
59+ }
60+ ScalarValue :: Utf8 ( None ) => {
61+ contains_null = true ;
62+ None
63+ }
64+ datatype => unimplemented!( "Unexpected type {} for InList" , datatype) ,
65+ } ,
66+ ColumnarValue :: Array ( _) => {
67+ unimplemented!( "InList does not yet support nested columns." )
68+ }
69+ } )
70+ . collect:: <Vec <_>>( ) ;
71+
72+ Ok ( ColumnarValue :: Array ( Arc :: new(
73+ array
74+ . iter( )
75+ . map( |x| {
76+ let contains = x. map( |x| values. contains( & x) ) ;
77+ match contains {
78+ Some ( true ) => {
79+ if $NEGATED {
80+ Some ( false )
81+ } else {
82+ Some ( true )
83+ }
84+ }
85+ Some ( false ) => {
86+ if contains_null {
87+ None
88+ } else if $NEGATED {
89+ Some ( true )
90+ } else {
91+ Some ( false )
92+ }
93+ }
94+ None => None ,
95+ }
96+ } )
97+ . collect:: <BooleanArray >( ) ,
98+ ) ) )
99+ } } ;
46100 ( $ARRAY: expr, $LIST_VALUES: expr, $NEGATED: expr, $SCALAR_VALUE: ident, $ARRAY_TYPE: ident) => { {
47101 let array = $ARRAY. as_any( ) . downcast_ref:: <$ARRAY_TYPE>( ) . unwrap( ) ;
48102
@@ -262,6 +316,27 @@ impl PhysicalExpr for InListExpr {
262316 DataType :: UInt8 => {
263317 make_contains ! ( array, list_values, self . negated, UInt8 , UInt8Array )
264318 }
319+ DataType :: Int64Decimal ( 0 ) => {
320+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal0Array , 0 )
321+ }
322+ DataType :: Int64Decimal ( 1 ) => {
323+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal1Array , 1 )
324+ }
325+ DataType :: Int64Decimal ( 2 ) => {
326+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal2Array , 2 )
327+ }
328+ DataType :: Int64Decimal ( 3 ) => {
329+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal3Array , 3 )
330+ }
331+ DataType :: Int64Decimal ( 4 ) => {
332+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal4Array , 4 )
333+ }
334+ DataType :: Int64Decimal ( 5 ) => {
335+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal5Array , 5 )
336+ }
337+ DataType :: Int64Decimal ( 10 ) => {
338+ make_contains ! ( array, list_values, self . negated, Int64Decimal , Int64Decimal10Array , 10 )
339+ }
265340 DataType :: Boolean => {
266341 make_contains ! ( array, list_values, self . negated, Boolean , BooleanArray )
267342 }
0 commit comments