Skip to content

Commit

Permalink
refactor(properties): Split properties.rs into smaller modules (#14925)
Browse files Browse the repository at this point in the history
chore: fix the license header check

Signed-off-by: Alan Tang <[email protected]>
  • Loading branch information
Standing-Man authored Feb 28, 2025
1 parent 988a535 commit 5e49094
Show file tree
Hide file tree
Showing 6 changed files with 4,673 additions and 4,544 deletions.
32 changes: 32 additions & 0 deletions datafusion/physical-expr/src/equivalence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ mod tests {
LexOrdering, PhysicalSortRequirement,
};

/// Converts a string to a physical sort expression
///
/// # Example
/// * `"a"` -> (`"a"`, `SortOptions::default()`)
/// * `"a ASC"` -> (`"a"`, `SortOptions { descending: false, nulls_first: false }`)
pub fn parse_sort_expr(name: &str, schema: &SchemaRef) -> PhysicalSortExpr {
let mut parts = name.split_whitespace();
let name = parts.next().expect("empty sort expression");
let mut sort_expr = PhysicalSortExpr::new(
col(name, schema).expect("invalid column name"),
SortOptions::default(),
);

if let Some(options) = parts.next() {
sort_expr = match options {
"ASC" => sort_expr.asc(),
"DESC" => sort_expr.desc(),
_ => panic!(
"unknown sort options. Expected 'ASC' or 'DESC', got {}",
options
),
}
}

assert!(
parts.next().is_none(),
"unexpected tokens in column name. Expected 'name' / 'name ASC' / 'name DESC' but got '{name}'"
);

sort_expr
}

pub fn output_schema(
mapping: &ProjectionMapping,
input_schema: &Arc<Schema>,
Expand Down
Loading

0 comments on commit 5e49094

Please sign in to comment.