alamb commented on code in PR #7401:
URL: https://github.com/apache/arrow-datafusion/pull/7401#discussion_r1324499901


##########
datafusion/core/src/physical_plan/row_converter.rs:
##########
@@ -0,0 +1,292 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! [`CardinalityAwareRowConverter`] for converting data to
+//! [`arrow::row`] format.
+
+use arrow::datatypes::DataType;
+use arrow::row::{Row, RowConverter};
+use arrow::row::{Rows, SortField};
+use arrow_array::cast::AsArray;
+use arrow_array::*;
+use datafusion_common::{internal_err, DataFusionError, Result};
+
+/// The threshold of the number of values at which to consider a
+/// [`DictionaryArray`] "high" cardinality.
+///
+/// Since [`RowConverter`] blindly generates a mapping for all values,
+/// regardless of if they appear in the keys, this value is compared
+/// to the length of values.
+///
+/// The assumption is that the number of potential distinct key values
+/// (aka the length of the values array) is a more robust predictor of
+/// being "high" cardinality than the actual number of keys used. The
+/// intuition for this is that other values in the dictionary could be
+/// used in subsequent batches.
+///
+/// While an argument can made for doing something more sophisticated,
+/// this would likely only really make sense if the dictionary
+/// interner itself followed a similar approach, which it did not at
+/// the time of this writing.
+const LOW_CARDINALITY_THRESHOLD: usize = 10;

Review Comment:
   > a dictionary will almost never have this few values, even if the column 
itself only contains 2 or 3 distinct values. 
   
   I don't understand that statement. 
   
   @JayjeetAtGithub do you have any specific numbers about how this threshold 
was chosen? @tustvold do you have any suggestions for a different value (or 
suggestions on how to empirically determine a threshold?)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to