kosiew commented on code in PR #24951:
URL: https://github.com/apache/datafusion/pull/24951#discussion_r3977245241
##########
datafusion/datasource/src/write/demux.rs:
##########
@@ -595,3 +602,69 @@ fn compute_hive_style_file_path(
file_path.join(format!("{write_id}.{file_extension}"))
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use arrow::array::{Array, ArrayRef, DictionaryArray, Int32Array};
+ use arrow::datatypes::Int32Type;
+
+ fn partition_batch(column: ArrayRef) -> RecordBatch {
+ RecordBatch::try_from_iter_with_nullable([("p", column,
true)]).unwrap()
+ }
+
+ #[test]
+ fn partition_keys_reject_null_values() {
+ let columns: Vec<ArrayRef> = vec![
+ Arc::new(Int32Array::from(vec![Some(0), None])),
+ Arc::new(StringArray::from(vec![Some(""), None])),
+ ];
+ for column in columns {
+ let partition_by = vec![("p".to_string(),
column.data_type().clone())];
+ let batch = partition_batch(column);
+ let err = compute_partition_keys_by_row(&batch,
&partition_by).unwrap_err();
+ assert_eq!(
+ err.strip_backtrace(),
+ "Execution error: NULL values are not supported for partition
column 'p'"
+ );
+ }
+ }
+
+ #[test]
+ fn partition_keys_accept_slice_without_nulls() {
+ let column = Int32Array::from(vec![None, Some(0), Some(1)]).slice(1,
2);
+ let batch = partition_batch(Arc::new(column));
+ let partition_by = vec![("p".to_string(), DataType::Int32)];
+ let keys = compute_partition_keys_by_row(&batch,
&partition_by).unwrap();
+ assert_eq!(keys, vec![vec![Cow::Borrowed("0"), Cow::Borrowed("1")]]);
+ }
+
+ fn dictionary_with_null_value() -> DictionaryArray<Int32Type> {
Review Comment:
Could we also add a dictionary test where the dictionary key itself is NULL,
rather than only testing a key that points to a NULL dictionary value?
`logical_null_count()` intentionally accounts for both kinds of logical NULLs,
so covering both cases would help keep this validation robust if Arrow's
dictionary handling or these fixtures change in the future.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]