11// SPDX-License-Identifier: Apache-2.0
22// SPDX-FileCopyrightText: Copyright the Vortex contributors
33
4+ use std:: fmt:: Debug ;
45use std:: marker:: PhantomData ;
56use std:: sync:: Arc ;
67
@@ -11,17 +12,17 @@ use crate::EncodingId;
1112use crate :: array:: ArrayRef ;
1213use crate :: array:: transform:: context:: ArrayRuleContext ;
1314use crate :: array:: transform:: rules:: {
14- AnyParent , ArrayParentMatcher , ArrayParentReduceRule , ArrayReduceRule ,
15+ AnyArrayParent , ArrayParentMatcher , ArrayParentReduceRule , ArrayReduceRule ,
1516} ;
1617use crate :: vtable:: VTable ;
1718
1819/// Dynamic trait for array reduce rules
19- pub trait DynArrayReduceRule : Send + Sync {
20+ pub trait DynArrayReduceRule : Debug + Send + Sync {
2021 fn reduce ( & self , array : & ArrayRef , ctx : & ArrayRuleContext ) -> VortexResult < Option < ArrayRef > > ;
2122}
2223
2324/// Dynamic trait for array parent reduce rules
24- pub trait DynArrayParentReduceRule : Send + Sync {
25+ pub trait DynArrayParentReduceRule : Debug + Send + Sync {
2526 fn reduce_parent (
2627 & self ,
2728 array : & ArrayRef ,
@@ -37,12 +38,30 @@ struct ArrayReduceRuleAdapter<V: VTable, R> {
3738 _phantom : PhantomData < V > ,
3839}
3940
41+ impl < V : VTable , R : Debug > Debug for ArrayReduceRuleAdapter < V , R > {
42+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
43+ f. debug_struct ( "ArrayReduceRuleAdapter" )
44+ . field ( "rule" , & self . rule )
45+ . finish ( )
46+ }
47+ }
48+
4049/// Adapter for ArrayParentReduceRule
4150struct ArrayParentReduceRuleAdapter < Child : VTable , Parent : ArrayParentMatcher , R > {
4251 rule : R ,
4352 _phantom : PhantomData < ( Child , Parent ) > ,
4453}
4554
55+ impl < Child : VTable , Parent : ArrayParentMatcher , R : Debug > Debug
56+ for ArrayParentReduceRuleAdapter < Child , Parent , R >
57+ {
58+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
59+ f. debug_struct ( "ArrayParentReduceRuleAdapter" )
60+ . field ( "rule" , & self . rule )
61+ . finish ( )
62+ }
63+ }
64+
4665impl < V , R > DynArrayReduceRule for ArrayReduceRuleAdapter < V , R >
4766where
4867 V : VTable ,
81100
82101/// Inner struct that holds all the rule registries.
83102/// Wrapped in a single Arc by ArrayRewriteRuleRegistry for efficient cloning.
84- #[ derive( Default ) ]
103+ #[ derive( Default , Debug ) ]
85104struct ArrayRewriteRuleRegistryInner {
86105 /// Reduce rules indexed by encoding ID
87106 reduce_rules : DashMap < EncodingId , Vec < Arc < dyn DynArrayReduceRule > > > ,
@@ -91,25 +110,6 @@ struct ArrayRewriteRuleRegistryInner {
91110 any_parent_rules : DashMap < EncodingId , Vec < Arc < dyn DynArrayParentReduceRule > > > ,
92111}
93112
94- impl std:: fmt:: Debug for ArrayRewriteRuleRegistryInner {
95- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
96- f. debug_struct ( "ArrayRewriteRuleRegistryInner" )
97- . field (
98- "reduce_rules" ,
99- & format ! ( "{} encodings" , self . reduce_rules. len( ) ) ,
100- )
101- . field (
102- "parent_rules" ,
103- & format ! ( "{} pairs" , self . parent_rules. len( ) ) ,
104- )
105- . field (
106- "any_parent_rules" ,
107- & format ! ( "{} encodings" , self . any_parent_rules. len( ) ) ,
108- )
109- . finish ( )
110- }
111- }
112-
113113/// Registry of array rewrite rules.
114114///
115115/// Stores rewrite rules indexed by the encoding ID they apply to.
@@ -135,8 +135,7 @@ impl ArrayRewriteRuleRegistry {
135135 pub fn register_reduce_rule < V , R > ( & self , encoding : & V :: Encoding , rule : R )
136136 where
137137 V : VTable ,
138- R : ' static ,
139- R : ArrayReduceRule < V > ,
138+ R : ArrayReduceRule < V > + ' static ,
140139 {
141140 let adapter = ArrayReduceRuleAdapter {
142141 rule,
@@ -159,8 +158,7 @@ impl ArrayRewriteRuleRegistry {
159158 ) where
160159 Child : VTable ,
161160 Parent : VTable ,
162- R : ' static ,
163- R : ArrayParentReduceRule < Child , Parent > ,
161+ R : ArrayParentReduceRule < Child , Parent > + ' static ,
164162 {
165163 let adapter = ArrayParentReduceRuleAdapter {
166164 rule,
@@ -179,8 +177,7 @@ impl ArrayRewriteRuleRegistry {
179177 pub fn register_any_parent_rule < Child , R > ( & self , child_encoding : & Child :: Encoding , rule : R )
180178 where
181179 Child : VTable ,
182- R : ' static ,
183- R : ArrayParentReduceRule < Child , AnyParent > ,
180+ R : ArrayParentReduceRule < Child , AnyArrayParent > + ' static ,
184181 {
185182 let adapter = ArrayParentReduceRuleAdapter {
186183 rule,
0 commit comments