Sorts record batches by all columns for deterministic comparison. When comparing query results, we need a canonical ordering so that semantically equivalent results compare as equal. This function sorts by all columns in the schema to achieve that.
(
ctx: &SessionContext,
batches: Vec<RecordBatch>,
)
| 199 | /// semantically equivalent results compare as equal. This function sorts |
| 200 | /// by all columns in the schema to achieve that. |
| 201 | async fn sort_batches( |
| 202 | ctx: &SessionContext, |
| 203 | batches: Vec<RecordBatch>, |
| 204 | ) -> Result<Vec<RecordBatch>> { |
| 205 | let mut df = ctx.read_batches(batches)?; |
| 206 | let schema = df.schema().as_arrow().clone(); |
| 207 | let sort_exprs = schema |
| 208 | .fields() |
| 209 | .iter() |
| 210 | // Use Column directly, col() causes the column names to be normalized to lowercase |
| 211 | .map(|f| { |
| 212 | Expr::Column(Column::new_unqualified(f.name().to_string())).sort(true, false) |
| 213 | }) |
| 214 | .collect_vec(); |
| 215 | if !sort_exprs.is_empty() { |
| 216 | df = df.sort(sort_exprs)?; |
| 217 | } |
| 218 | df.collect().await |
| 219 | } |
| 220 | |
| 221 | /// The outcome of running a single roundtrip test. |
| 222 | /// |
no test coverage detected
searching dependent graphs…