@@ -914,6 +914,50 @@ macro_rules! instantiate_primitive {
914914 } ;
915915}
916916
917+ /// Returns true if the specified data type has a specialized
918+ /// [`GroupColumn`] builder in [`make_group_column`].
919+ ///
920+ /// This is the allow-list that gates the `GroupValuesRows` fallback in
921+ /// [`crate::aggregates::group_values::new_group_values`]: it must accept
922+ /// exactly the set of types that [`make_group_column`] constructs a
923+ /// builder for. The `group_column_supported_type_matches_make_group_column`
924+ /// test below pins this biconditional.
925+ fn group_column_supported_type ( data_type : & DataType ) -> bool {
926+ matches ! (
927+ * data_type,
928+ DataType :: Int8
929+ | DataType :: Int16
930+ | DataType :: Int32
931+ | DataType :: Int64
932+ | DataType :: UInt8
933+ | DataType :: UInt16
934+ | DataType :: UInt32
935+ | DataType :: UInt64
936+ | DataType :: Float32
937+ | DataType :: Float64
938+ | DataType :: Decimal128 ( _, _)
939+ | DataType :: Utf8
940+ | DataType :: LargeUtf8
941+ | DataType :: Binary
942+ | DataType :: LargeBinary
943+ | DataType :: Date32
944+ | DataType :: Date64
945+ // Only the semantically valid Time variants per the Arrow spec.
946+ // The dispatcher in `make_group_column` returns NotImpl for the
947+ // other unit combinations, so accepting them here would cause a
948+ // schema to be routed into GroupValuesColumn and then fail at
949+ // intern. Keep these two arms in lockstep with the dispatcher.
950+ | DataType :: Time32 ( TimeUnit :: Second )
951+ | DataType :: Time32 ( TimeUnit :: Millisecond )
952+ | DataType :: Time64 ( TimeUnit :: Microsecond )
953+ | DataType :: Time64 ( TimeUnit :: Nanosecond )
954+ | DataType :: Timestamp ( _, _)
955+ | DataType :: Utf8View
956+ | DataType :: BinaryView
957+ | DataType :: Boolean
958+ )
959+ }
960+
917961/// Build a [`GroupColumn`] for a single schema field.
918962///
919963/// Extracted from the inline match that used to live in
@@ -926,6 +970,9 @@ macro_rules! instantiate_primitive {
926970/// Returns `Err(not_impl_err!(...))` for any type not in the supported set;
927971/// callers (`GroupValues::intern`) propagate that error so the
928972/// `GroupValuesRows` fallback can take over upstream of this builder.
973+ ///
974+ /// The allow-list that gates this dispatcher lives in
975+ /// [`group_column_supported_type`] directly above.
929976fn make_group_column ( field : & Field ) -> Result < Box < dyn GroupColumn > > {
930977 let nullable = field. is_nullable ( ) ;
931978 let data_type = field. data_type ( ) ;
@@ -955,8 +1002,8 @@ fn make_group_column(field: &Field) -> Result<Box<dyn GroupColumn>> {
9551002 instantiate_primitive ! ( v, nullable, Time32MillisecondType , data_type)
9561003 }
9571004 // Time32 with Microsecond / Nanosecond is not a valid Arrow type
958- // combination; reject explicitly so supported_type and this
959- // dispatcher stay in lockstep (see consistency fuzz below).
1005+ // combination; reject explicitly so group_column_supported_type
1006+ // and this dispatcher stay in lockstep (see consistency fuzz below).
9601007 _ => return not_impl_err ! ( "{data_type} not supported in GroupValuesColumn" ) ,
9611008 } ,
9621009 DataType :: Time64 ( t) => match t {
@@ -1195,53 +1242,7 @@ pub fn supported_schema(schema: &Schema) -> bool {
11951242 . fields ( )
11961243 . iter ( )
11971244 . map ( |f| f. data_type ( ) )
1198- . all ( supported_type)
1199- }
1200-
1201- /// Returns true if the specified data type is supported by [`GroupValuesColumn`]
1202- ///
1203- /// In order to be supported, there must be a specialized implementation of
1204- /// [`GroupColumn`] for the data type, instantiated in
1205- /// [`make_group_column`]. This function is the allow-list that gates the
1206- /// `GroupValuesRows` fallback in [`crate::aggregates::group_values::new_group_values`];
1207- /// it must accept exactly the set of types that [`make_group_column`]
1208- /// constructs a builder for. The
1209- /// `supported_type_and_make_group_column_stay_in_sync` test below pins
1210- /// this biconditional.
1211- fn supported_type ( data_type : & DataType ) -> bool {
1212- matches ! (
1213- * data_type,
1214- DataType :: Int8
1215- | DataType :: Int16
1216- | DataType :: Int32
1217- | DataType :: Int64
1218- | DataType :: UInt8
1219- | DataType :: UInt16
1220- | DataType :: UInt32
1221- | DataType :: UInt64
1222- | DataType :: Float32
1223- | DataType :: Float64
1224- | DataType :: Decimal128 ( _, _)
1225- | DataType :: Utf8
1226- | DataType :: LargeUtf8
1227- | DataType :: Binary
1228- | DataType :: LargeBinary
1229- | DataType :: Date32
1230- | DataType :: Date64
1231- // Only the semantically valid Time variants per the Arrow spec.
1232- // The dispatcher in `make_group_column` returns NotImpl for the
1233- // other unit combinations, so accepting them here would cause a
1234- // schema to be routed into GroupValuesColumn and then fail at
1235- // intern. Keep these two arms in lockstep with the dispatcher.
1236- | DataType :: Time32 ( TimeUnit :: Second )
1237- | DataType :: Time32 ( TimeUnit :: Millisecond )
1238- | DataType :: Time64 ( TimeUnit :: Microsecond )
1239- | DataType :: Time64 ( TimeUnit :: Nanosecond )
1240- | DataType :: Timestamp ( _, _)
1241- | DataType :: Utf8View
1242- | DataType :: BinaryView
1243- | DataType :: Boolean
1244- )
1245+ . all ( group_column_supported_type)
12451246}
12461247
12471248///Shows how many `null`s there are in an array
@@ -1268,23 +1269,25 @@ mod tests {
12681269 GroupValues , multi_group_by:: GroupValuesColumn ,
12691270 } ;
12701271
1271- use super :: { GroupIndexView , make_group_column, supported_schema, supported_type} ;
1272+ use super :: {
1273+ GroupIndexView , group_column_supported_type, make_group_column, supported_schema,
1274+ } ;
12721275
1273- /// CRITICAL invariant: if `supported_type (t)` returns true the dispatcher
1274- /// must accept that type at intern time, and conversely if
1275- /// `supported_type (t)` returns false the planner must NOT route it through
1276- /// `GroupValuesColumn`. A divergence here would let the planner select
1277- /// `GroupValuesColumn` for a type whose dispatcher arm is missing,
1278- /// producing a runtime `not_impl_err` after the field reaches the
1279- /// builder factory.
1276+ /// CRITICAL invariant: if `group_column_supported_type (t)` returns true
1277+ /// the dispatcher must accept that type at intern time, and conversely
1278+ /// if `group_column_supported_type (t)` returns false the planner must
1279+ /// NOT route it through `GroupValuesColumn`. A divergence here would
1280+ /// let the planner select `GroupValuesColumn` for a type whose
1281+ /// dispatcher arm is missing, producing a runtime `not_impl_err` after
1282+ /// the field reaches the builder factory.
12801283 ///
12811284 /// This test fuzzes a representative cross-section of types and asserts
12821285 /// both directions of the biconditional. When a new specialization is
12831286 /// added (`Float16`, `FixedSizeList`, `Struct`, ...) it should be added
12841287 /// to the supported_cases vector; when a type is intentionally rejected
12851288 /// it should be added to unsupported_cases.
12861289 #[ test]
1287- fn supported_type_and_make_group_column_stay_in_sync ( ) {
1290+ fn group_column_supported_type_matches_make_group_column ( ) {
12881291 let supported_cases: Vec < DataType > = vec ! [
12891292 DataType :: Int8 ,
12901293 DataType :: Int64 ,
@@ -1310,13 +1313,13 @@ mod tests {
13101313
13111314 for dt in & supported_cases {
13121315 assert ! (
1313- supported_type ( dt) ,
1314- "expected supported_type =true for {dt:?}"
1316+ group_column_supported_type ( dt) ,
1317+ "expected group_column_supported_type =true for {dt:?}"
13151318 ) ;
13161319 let field = Field :: new ( "col" , dt. clone ( ) , true ) ;
13171320 make_group_column ( & field) . unwrap_or_else ( |e| {
13181321 panic ! (
1319- "supported_type accepted {dt:?} but make_group_column rejected: {e}"
1322+ "group_column_supported_type accepted {dt:?} but make_group_column rejected: {e}"
13201323 )
13211324 } ) ;
13221325 }
@@ -1328,8 +1331,8 @@ mod tests {
13281331 // Second / Millisecond and Time64 only for Microsecond /
13291332 // Nanosecond. The TimeUnit enum allows constructing the other
13301333 // combinations programmatically, but they are not valid Arrow
1331- // types and must be rejected by both supported_type and the
1332- // dispatcher.
1334+ // types and must be rejected by both group_column_supported_type
1335+ // and the dispatcher.
13331336 DataType :: Time64 ( arrow:: datatypes:: TimeUnit :: Second ) ,
13341337 DataType :: Time64 ( arrow:: datatypes:: TimeUnit :: Millisecond ) ,
13351338 DataType :: Time32 ( arrow:: datatypes:: TimeUnit :: Microsecond ) ,
@@ -1338,13 +1341,13 @@ mod tests {
13381341
13391342 for dt in & unsupported_cases {
13401343 assert ! (
1341- !supported_type ( dt) ,
1342- "expected supported_type =false for {dt:?}"
1344+ !group_column_supported_type ( dt) ,
1345+ "expected group_column_supported_type =false for {dt:?}"
13431346 ) ;
13441347 let field = Field :: new ( "col" , dt. clone ( ) , true ) ;
13451348 assert ! (
13461349 make_group_column( & field) . is_err( ) ,
1347- "supported_type rejected {dt:?} but make_group_column accepted it"
1350+ "group_column_supported_type rejected {dt:?} but make_group_column accepted it"
13481351 ) ;
13491352 }
13501353 }
0 commit comments