Skip to content

Commit 5e49094

Browse files
authored
refactor(properties): Split properties.rs into smaller modules (#14925)
chore: fix the license header check Signed-off-by: Alan Tang <[email protected]>
1 parent 988a535 commit 5e49094

File tree

6 files changed

+4673
-4544
lines changed

6 files changed

+4673
-4544
lines changed

datafusion/physical-expr/src/equivalence/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,38 @@ mod tests {
7979
LexOrdering, PhysicalSortRequirement,
8080
};
8181

82+
/// Converts a string to a physical sort expression
83+
///
84+
/// # Example
85+
/// * `"a"` -> (`"a"`, `SortOptions::default()`)
86+
/// * `"a ASC"` -> (`"a"`, `SortOptions { descending: false, nulls_first: false }`)
87+
pub fn parse_sort_expr(name: &str, schema: &SchemaRef) -> PhysicalSortExpr {
88+
let mut parts = name.split_whitespace();
89+
let name = parts.next().expect("empty sort expression");
90+
let mut sort_expr = PhysicalSortExpr::new(
91+
col(name, schema).expect("invalid column name"),
92+
SortOptions::default(),
93+
);
94+
95+
if let Some(options) = parts.next() {
96+
sort_expr = match options {
97+
"ASC" => sort_expr.asc(),
98+
"DESC" => sort_expr.desc(),
99+
_ => panic!(
100+
"unknown sort options. Expected 'ASC' or 'DESC', got {}",
101+
options
102+
),
103+
}
104+
}
105+
106+
assert!(
107+
parts.next().is_none(),
108+
"unexpected tokens in column name. Expected 'name' / 'name ASC' / 'name DESC' but got '{name}'"
109+
);
110+
111+
sort_expr
112+
}
113+
82114
pub fn output_schema(
83115
mapping: &ProjectionMapping,
84116
input_schema: &Arc<Schema>,

0 commit comments

Comments
 (0)