andygrove commented on a change in pull request #8102: URL: https://github.com/apache/arrow/pull/8102#discussion_r490294558
########## File path: rust/datafusion/tests/sql.rs ########## @@ -609,6 +609,74 @@ fn execute(ctx: &mut ExecutionContext, sql: &str) -> Vec<String> { result_str(&results) } +fn array_str(array: &Arc<dyn Array>, row_index: usize) -> String { + if array.is_null(row_index) { + return "NULL".to_string(); + } + + match array.data_type() { + DataType::Int8 => { + let array = array.as_any().downcast_ref::<Int8Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Int16 => { + let array = array.as_any().downcast_ref::<Int16Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Int32 => { + let array = array.as_any().downcast_ref::<Int32Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Int64 => { + let array = array.as_any().downcast_ref::<Int64Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::UInt8 => { + let array = array.as_any().downcast_ref::<UInt8Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::UInt16 => { + let array = array.as_any().downcast_ref::<UInt16Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::UInt32 => { + let array = array.as_any().downcast_ref::<UInt32Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::UInt64 => { + let array = array.as_any().downcast_ref::<UInt64Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Float32 => { + let array = array.as_any().downcast_ref::<Float32Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Float64 => { + let array = array.as_any().downcast_ref::<Float64Array>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Utf8 => { + let array = array.as_any().downcast_ref::<StringArray>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::Boolean => { + let array = array.as_any().downcast_ref::<BooleanArray>().unwrap(); + format!("{:?}", array.value(row_index)) + } + DataType::FixedSizeList(_, n) => { + let array = array.as_any().downcast_ref::<FixedSizeListArray>().unwrap(); + let array = array.value(row_index); Review comment: I think that we need a null check here in case the whole array is null. I know we check at the start of this method for a null value _within_ an array, but I don't see a check for a null array. Maybe there are guarantees that no arrays can be null? If so, it would be good to add a comment here to explain. ```rust let array = array.as_any().downcast_ref::<FixedSizeListArray>().unwrap(); if array.is_null(row_index) { // this case isn't handled } else { let array = array.value(row_index); let mut r = Vec::with_capacity(*n as usize); for i in 0..*n { r.push(array_str(&array, i as usize)); } format!("[{}]", r.join(",")) } ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org